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 87d794bc75a4790ced1e0fcf6ef9f3b4aaa11081..96e3f89d7abace4659b54ae78ba638eb6ed91f26 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 bb68d21e1f8c699dc196f93152c26b027209de07..d13c5c6a978769b69eef060d50569c578616ba14 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 230ea7cd151045ee99f4df3214969d063d4cac02..c7c5a8f8a48cbba352c98e8f22e7f8260eceee70 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 d098b94ca22d11063264a490b2f6205188093434..0dab21e764d9f053876689376076c29c4a81b07d 100644 (file)
@@ -1281,6 +1281,7 @@ enum compress_algorithm_type {
        COMPRESS_LZO,
        COMPRESS_LZ4,
        COMPRESS_ZSTD,
+       COMPRESS_LZORLE,
        COMPRESS_MAX,
 };
 
index 1b170fc48941210fb92814387d394fc0b5fdc746..582bbf40c559002e614aed897518ac58e61e18fd 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 417a486f5c8a9be4220a9934804a8dba5660023b..757d3d6031e635024a7e854caa6c7d507e047dc1 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;