f2fs: compress: support lzo-rle compress algorithm
authorChao Yu <yuchao0@huawei.com>
Wed, 8 Apr 2020 11:56:32 +0000 (19:56 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 12 May 2020 03:36:46 +0000 (20:36 -0700)
LZO-RLE extension (run length encoding) was introduced to improve
performance of LZO algorithm in scenario of data contains many zeros,
zram has changed to use this extended algorithm by default, this
patch adds to support this algorithm extension, to enable this
extension, it needs to enable F2FS_FS_LZO and F2FS_FS_LZORLE config,
and specifies "compress_algorithm=lzo-rle" mountoption.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Documentation/filesystems/f2fs.rst
fs/f2fs/Kconfig
fs/f2fs/compress.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
include/trace/events/f2fs.h

index 87d794b..96e3f89 100644 (file)
@@ -244,7 +244,7 @@ checkpoint=%s[:%u[%]]  Set to "disable" to turn off checkpointing. Set to "enabl
                        would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
                        This space is reclaimed once checkpoint=enable.
 compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo",
-                       "lz4" and "zstd" algorithm.
+                       "lz4", "zstd" and "lzo-rle" algorithm.
 compress_log_size=%u   Support configuring compress cluster size, the size will
                        be 4KB * (1 << %u), 16KB is minimum size, also it's
                        default size.
index bb68d21..d13c5c6 100644 (file)
@@ -127,3 +127,13 @@ config F2FS_FS_ZSTD
        default y
        help
          Support ZSTD compress algorithm, if unsure, say Y.
+
+config F2FS_FS_LZORLE
+       bool "LZO-RLE compression support"
+       depends on F2FS_FS_COMPRESSION
+       depends on F2FS_FS_LZO
+       select LZO_COMPRESS
+       select LZO_DECOMPRESS
+       default y
+       help
+         Support LZO-RLE compress algorithm, if unsure, say Y.
index 230ea7c..c7c5a8f 100644 (file)
@@ -442,6 +442,31 @@ static const struct f2fs_compress_ops f2fs_zstd_ops = {
 };
 #endif
 
+#ifdef CONFIG_F2FS_FS_LZO
+#ifdef CONFIG_F2FS_FS_LZORLE
+static int lzorle_compress_pages(struct compress_ctx *cc)
+{
+       int ret;
+
+       ret = lzorle1x_1_compress(cc->rbuf, cc->rlen, cc->cbuf->cdata,
+                                       &cc->clen, cc->private);
+       if (ret != LZO_E_OK) {
+               printk_ratelimited("%sF2FS-fs (%s): lzo-rle compress failed, ret:%d\n",
+                               KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id, ret);
+               return -EIO;
+       }
+       return 0;
+}
+
+static const struct f2fs_compress_ops f2fs_lzorle_ops = {
+       .init_compress_ctx      = lzo_init_compress_ctx,
+       .destroy_compress_ctx   = lzo_destroy_compress_ctx,
+       .compress_pages         = lzorle_compress_pages,
+       .decompress_pages       = lzo_decompress_pages,
+};
+#endif
+#endif
+
 static const struct f2fs_compress_ops *f2fs_cops[COMPRESS_MAX] = {
 #ifdef CONFIG_F2FS_FS_LZO
        &f2fs_lzo_ops,
@@ -458,6 +483,11 @@ static const struct f2fs_compress_ops *f2fs_cops[COMPRESS_MAX] = {
 #else
        NULL,
 #endif
+#if defined(CONFIG_F2FS_FS_LZO) && defined(CONFIG_F2FS_FS_LZORLE)
+       &f2fs_lzorle_ops,
+#else
+       NULL,
+#endif
 };
 
 bool f2fs_is_compress_backend_ready(struct inode *inode)
index d098b94..0dab21e 100644 (file)
@@ -1281,6 +1281,7 @@ enum compress_algorithm_type {
        COMPRESS_LZO,
        COMPRESS_LZ4,
        COMPRESS_ZSTD,
+       COMPRESS_LZORLE,
        COMPRESS_MAX,
 };
 
index 1b170fc..582bbf4 100644 (file)
@@ -822,6 +822,9 @@ static int parse_options(struct super_block *sb, char *options)
                        } else if (!strcmp(name, "zstd")) {
                                F2FS_OPTION(sbi).compress_algorithm =
                                                                COMPRESS_ZSTD;
+                       } else if (!strcmp(name, "lzo-rle")) {
+                               F2FS_OPTION(sbi).compress_algorithm =
+                                                               COMPRESS_LZORLE;
                        } else {
                                kfree(name);
                                return -EINVAL;
@@ -1415,6 +1418,9 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
        case COMPRESS_ZSTD:
                algtype = "zstd";
                break;
+       case COMPRESS_LZORLE:
+               algtype = "lzo-rle";
+               break;
        }
        seq_printf(seq, ",compress_algorithm=%s", algtype);
 
index 417a486..757d3d6 100644 (file)
@@ -154,7 +154,8 @@ TRACE_DEFINE_ENUM(CP_PAUSE);
        __print_symbolic(type,                                          \
                { COMPRESS_LZO,         "LZO" },                        \
                { COMPRESS_LZ4,         "LZ4" },                        \
-               { COMPRESS_ZSTD,        "ZSTD" })
+               { COMPRESS_ZSTD,        "ZSTD" },                       \
+               { COMPRESS_LZORLE,      "LZO-RLE" })
 
 struct f2fs_sb_info;
 struct f2fs_io_info;