Skip to contentSkip to conversation

f2fs: compress: support zstd compress algorithm

PATCH In review Chao Yu 3 participants 7 messages Mar 3, 2020 – Mar 24, 2020

Subsystems (3)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v2 1/1 f2fs: compress: support zstd compress algorithm

Add zstd compress algorithm support, use "compress_algorithm=zstd" mountoption to enable it.

---
v2:
- avoid accessing invalid address
- introduce .{init,destroy}_{,de}compress_ctx callback functions.

 Documentation/filesystems/f2fs.txt |   4 +-
 fs/f2fs/Kconfig                    |   9 ++
 fs/f2fs/compress.c                 | 167 +++++++++++++++++++++++++++++
 fs/f2fs/f2fs.h                     |   5 +
 fs/f2fs/super.c                    |   7 ++
 include/trace/events/f2fs.h        |   3 +-
 6 files changed, 192 insertions(+), 3 deletions(-)
Documentation/filesystems/f2fs.txt +2 -2
index 4eb3e2ddd00e..b1a66cf0e967 100644
@@ -235,8 +235,8 @@ checkpoint=%s[:%u[%]]     Set to "disable" to turn off checkpointing. Set to "en
                        hide up to all remaining free space. The actual space that
                        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"
-                       and "lz4" algorithm.
+compress_algorithm=%s  Control compress algorithm, currently f2fs supports "lzo",
+                       "lz4" and "zstd" 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.
fs/f2fs/Kconfig +9 -0
index f0faada30f30..bb68d21e1f8c 100644
@@ -118,3 +118,12 @@ config F2FS_FS_LZ4
 	default y
 	help
 	  Support LZ4 compress algorithm, if unsure, say Y.
+
+config F2FS_FS_ZSTD
+	bool "ZSTD compression support"
+	depends on F2FS_FS_COMPRESSION
+	select ZSTD_COMPRESS
+	select ZSTD_DECOMPRESS
+	default y
+	help
+	  Support ZSTD compress algorithm, if unsure, say Y.
fs/f2fs/compress.c +167 -0

185 lines not on this page · raw message

fs/f2fs/f2fs.h +5 -0
index 73fd5c97d504..09270854cce8 100644
@@ -1231,6 +1231,7 @@ enum fsync_mode {
 enum compress_algorithm_type {
 	COMPRESS_LZO,
 	COMPRESS_LZ4,
+	COMPRESS_ZSTD,
 	COMPRESS_MAX,
 };
 
@@ -1260,6 +1261,7 @@ struct compress_ctx {
 	size_t rlen;			/* valid data length in rbuf */
 	size_t clen;			/* valid data length in cbuf */
 	void *private;			/* payload buffer for specified compression algorithm */
+	void *private2;			/* extra payload buffer */
 };
 
 /* compress context for write IO path */
@@ -1289,11 +1291,14 @@ struct decompress_io_ctx {
 	size_t clen;			/* valid data length in cbuf */
 	refcount_t ref;			/* referrence count of compressed page */
 	bool failed;			/* indicate IO error during decompression */
+	void *private;			/* payload buffer for specified decompression algorithm */
+	void *private2;			/* extra payload buffer */
 };
 
 #define NULL_CLUSTER			((unsigned int)(~0))
 #define MIN_COMPRESS_LOG_SIZE		2
 #define MAX_COMPRESS_LOG_SIZE		8
+#define MAX_COMPRESS_WINDOW_SIZE	((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE)
 
 struct f2fs_sb_info {
 	struct super_block *sb;			/* pointer to VFS super block */
fs/f2fs/super.c +7 -0
index 9f435191f1e5..db3a63f7c769 100644
@@ -829,6 +829,10 @@ static int parse_options(struct super_block *sb, char *options)
 					!strcmp(name, "lz4")) {
 				F2FS_OPTION(sbi).compress_algorithm =
 								COMPRESS_LZ4;
+			} else if (strlen(name) == 4 &&
+					!strcmp(name, "zstd")) {
+				F2FS_OPTION(sbi).compress_algorithm =
+								COMPRESS_ZSTD;
 			} else {
 				kfree(name);
 				return -EINVAL;
@@ -1419,6 +1423,9 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
 	case COMPRESS_LZ4:
 		algtype = "lz4";
 		break;
+	case COMPRESS_ZSTD:
+		algtype = "zstd";
+		break;
 	}
 	seq_printf(seq, ",compress_algorithm=%s", algtype);
 
include/trace/events/f2fs.h +2 -1
index 67a97838c2a0..d97adfc327f0 100644
@@ -153,7 +153,8 @@ TRACE_DEFINE_ENUM(CP_PAUSE);
 #define show_compress_algorithm(type)					\
 	__print_symbolic(type,						\
 		{ COMPRESS_LZO,		"LZO" },			\
-		{ COMPRESS_LZ4,		"LZ4" })
+		{ COMPRESS_LZ4,		"LZ4" },			\
+		{ COMPRESS_ZSTD,	"ZSTD" })
 
 struct f2fs_sb_info;
 struct f2fs_io_info;
Signature · 1 line
2.18.0.rc1
#1 lore raw
I love your patch! Yet something to improve:

Hi Chao,

I love your patch! Yet something to improve:

[auto build test ERROR on f2fs/dev-test]
[also build test ERROR on v5.6-rc4 next-20200303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Chao-Yu/f2fs-compress-support-zstd-compress-algorithm/20200304-020312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
config: x86_64-randconfig-s1-20200303 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-5) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

fs/f2fs/compress.c:450:3: error: 'const struct f2fs_compress_ops' has no member named 'init_decompress_ctx'; did you mean 'init_compress_ctx'?
.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~
init_compress_ctx

>> fs/f2fs/compress.c:450:25: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init]

.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~
fs/f2fs/compress.c:450:25: note: (near initialization for 'f2fs_zstd_ops')
fs/f2fs/compress.c:450:25: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types] fs/f2fs/compress.c:450:25: note: (near initialization for 'f2fs_zstd_ops.destroy_compress_ctx')
fs/f2fs/compress.c:451:3: error: 'const struct f2fs_compress_ops' has no member named 'destroy_decompress_ctx'; did you mean 'destroy_compress_ctx'?
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~
destroy_compress_ctx
fs/f2fs/compress.c:451:28: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init]
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/f2fs/compress.c:451:28: note: (near initialization for 'f2fs_zstd_ops')
fs/f2fs/compress.c:451:28: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types] fs/f2fs/compress.c:451:28: note: (near initialization for 'f2fs_zstd_ops.decompress_pages')
cc1: some warnings being treated as errors

vim +450 fs/f2fs/compress.c

445
446 static const struct f2fs_compress_ops f2fs_zstd_ops = {
447 .init_compress_ctx = zstd_init_compress_ctx,
448 .destroy_compress_ctx = zstd_destroy_compress_ctx,
449 .compress_pages = zstd_compress_pages,

 > 450		.init_decompress_ctx	= zstd_init_decompress_ctx,

451 .destroy_decompress_ctx = zstd_destroy_decompress_ctx,
452 .decompress_pages = zstd_decompress_pages,
453 };
454 #endif
455

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Chao Yu
I love your patch! Yet something to improve:

Hi Chao,

I love your patch! Yet something to improve:

[auto build test ERROR on f2fs/dev-test]
[also build test ERROR on v5.6-rc4 next-20200303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Chao-Yu/f2fs-compress-support-zstd-compress-algorithm/20200304-020312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
config: x86_64-randconfig-g003-20200303 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-5) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

fs//f2fs/compress.c:450:3: error: 'const struct f2fs_compress_ops' has no member named 'init_decompress_ctx'; did you mean 'init_compress_ctx'?
.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~
init_compress_ctx
fs//f2fs/compress.c:450:25: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init]
.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~
fs//f2fs/compress.c:450:25: note: (near initialization for 'f2fs_zstd_ops')

>> fs//f2fs/compress.c:450:25: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]

fs//f2fs/compress.c:450:25: note: (near initialization for 'f2fs_zstd_ops.init_compress_ctx')
fs//f2fs/compress.c:451:3: error: 'const struct f2fs_compress_ops' has no member named 'destroy_decompress_ctx'; did you mean 'destroy_compress_ctx'?
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~
destroy_compress_ctx
fs//f2fs/compress.c:451:28: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init]
.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
fs//f2fs/compress.c:451:28: note: (near initialization for 'f2fs_zstd_ops')
fs//f2fs/compress.c:451:28: warning: excess elements in struct initializer
fs//f2fs/compress.c:451:28: note: (near initialization for 'f2fs_zstd_ops')
cc1: some warnings being treated as errors

vim +450 fs//f2fs/compress.c

445
446 static const struct f2fs_compress_ops f2fs_zstd_ops = {
447 .init_compress_ctx = zstd_init_compress_ctx,
448 .destroy_compress_ctx = zstd_destroy_compress_ctx,
449 .compress_pages = zstd_compress_pages,

 > 450		.init_decompress_ctx	= zstd_init_decompress_ctx,

451 .destroy_decompress_ctx = zstd_destroy_decompress_ctx,
452 .decompress_pages = zstd_decompress_pages,
453 };
454 #endif
455

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Chao Yu
I love your patch! Yet something to improve:

Hi Chao,

I love your patch! Yet something to improve:

[auto build test ERROR on f2fs/dev-test]
[also build test ERROR on v5.6-rc4 next-20200303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Chao-Yu/f2fs-compress-support-zstd-compress-algorithm/20200304-020312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (git://gitmirror/llvm_project 211fb91f1067ecdf7c0b8a019bcf76554d813129)

reproduce:
# FIXME the reproduce steps for clang is not ready yet

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

>> fs/f2fs/compress.c:450:3: error: field designator 'init_decompress_ctx' does not refer to any field in type 'const struct f2fs_compress_ops'; did you mean 'init_compress_ctx'?
           .init_decompress_ctx    = zstd_init_decompress_ctx,
            ^~~~~~~~~~~~~~~~~~~
            init_compress_ctx
   fs/f2fs/compress.c:21:8: note: 'init_compress_ctx' declared here
           int (*init_compress_ctx)(struct compress_ctx *cc);
                 ^
>> fs/f2fs/compress.c:450:25: error: incompatible function pointer types initializing 'int (*)(struct compress_ctx *)' with an expression of type 'int (struct decompress_io_ctx *)' [-Werror,-Wincompatible-function-pointer-types]
           .init_decompress_ctx    = zstd_init_decompress_ctx,
                                     ^~~~~~~~~~~~~~~~~~~~~~~~
>> fs/f2fs/compress.c:451:3: error: field designator 'destroy_decompress_ctx' does not refer to any field in type 'const struct f2fs_compress_ops'; did you mean 'destroy_compress_ctx'?
           .destroy_decompress_ctx = zstd_destroy_decompress_ctx,
            ^~~~~~~~~~~~~~~~~~~~~~
            destroy_compress_ctx
   fs/f2fs/compress.c:22:9: note: 'destroy_compress_ctx' declared here
           void (*destroy_compress_ctx)(struct compress_ctx *cc);
                  ^
>> fs/f2fs/compress.c:451:28: error: incompatible function pointer types initializing 'void (*)(struct compress_ctx *)' with an expression of type 'void (struct decompress_io_ctx *)' [-Werror,-Wincompatible-function-pointer-types]

.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.

vim +450 fs/f2fs/compress.c

445
446 static const struct f2fs_compress_ops f2fs_zstd_ops = {
447 .init_compress_ctx = zstd_init_compress_ctx,
448 .destroy_compress_ctx = zstd_destroy_compress_ctx,
449 .compress_pages = zstd_compress_pages,

 > 450		.init_decompress_ctx	= zstd_init_decompress_ctx,
 > 451		.destroy_decompress_ctx	= zstd_destroy_decompress_ctx,

452 .decompress_pages = zstd_decompress_pages,
453 };
454 #endif
455

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author
#4 lore raw

Hi,

Thanks for the report.

I guess we need to apply below patches first:

[PATCH 1/2] f2fs: compress: fix to call missing destroy_compress_ctx() [PATCH 2/2] f2fs: compress: add .{init,destroy}_decompress_ctx callback

Quoted 62 lines · kbuild test robot

Hi Chao,

I love your patch! Yet something to improve:

[auto build test ERROR on f2fs/dev-test]
[also build test ERROR on v5.6-rc4 next-20200303]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Chao-Yu/f2fs-compress-support-zstd-compress-algorithm/20200304-020312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev-test
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (git://gitmirror/llvm_project 211fb91f1067ecdf7c0b8a019bcf76554d813129)

reproduce:
# FIXME the reproduce steps for clang is not ready yet

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

fs/f2fs/compress.c:450:3: error: field designator 'init_decompress_ctx' does not refer to any field in type 'const struct f2fs_compress_ops'; did you mean 'init_compress_ctx'?

.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~
init_compress_ctx
fs/f2fs/compress.c:21:8: note: 'init_compress_ctx' declared here

           int (*init_compress_ctx)(struct compress_ctx *cc);
                 ^
Quoted 1 line
Quoted 1 line

fs/f2fs/compress.c:450:25: error: incompatible function pointer types initializing 'int (*)(struct compress_ctx *)' with an expression of type 'int (struct decompress_io_ctx *)' [-Werror,-Wincompatible-function-pointer-types]

.init_decompress_ctx = zstd_init_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~

Quoted 1 line
Quoted 1 line

fs/f2fs/compress.c:451:3: error: field designator 'destroy_decompress_ctx' does not refer to any field in type 'const struct f2fs_compress_ops'; did you mean 'destroy_compress_ctx'?

.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~
destroy_compress_ctx
fs/f2fs/compress.c:22:9: note: 'destroy_compress_ctx' declared here

           void (*destroy_compress_ctx)(struct compress_ctx *cc);
                  ^
Quoted 1 line
Quoted 1 line

fs/f2fs/compress.c:451:28: error: incompatible function pointer types initializing 'void (*)(struct compress_ctx *)' with an expression of type 'void (struct decompress_io_ctx *)' [-Werror,-Wincompatible-function-pointer-types]

.destroy_decompress_ctx = zstd_destroy_decompress_ctx,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.

vim +450 fs/f2fs/compress.c

   445	
   446	static const struct f2fs_compress_ops f2fs_zstd_ops = {
   447		.init_compress_ctx	= zstd_init_compress_ctx,
   448		.destroy_compress_ctx	= zstd_destroy_compress_ctx,
   449		.compress_pages		= zstd_compress_pages,
Quoted 2 lines

450 .init_decompress_ctx = zstd_init_decompress_ctx,
451 .destroy_decompress_ctx = zstd_destroy_decompress_ctx,

452 .decompress_pages = zstd_decompress_pages,

   453	};
   454	#endif
   455	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author
#5 lore raw
In reply to Chao Yu

Hi Jaegeuk,

Quoted 8 lines · Chao Yu

Add zstd compress algorithm support, use "compress_algorithm=zstd" mountoption to enable it.

---
v2:
- avoid accessing invalid address
- introduce .{init,destroy}_{,de}compress_ctx callback functions.

I guess we merged related patches with wrong sequence as this patch depends on ("f2fs: compress: add .{init,destroy}_decompress_ctx callback").

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#6 lore raw
Quoted 6 lines · Chao Yu

Hi Jaegeuk,

Quoted 3 lines · Chao Yu

Add zstd compress algorithm support, use "compress_algorithm=zstd" mountoption to enable it.

Quoted 8 lines
Quoted 5 lines

---
v2:
- avoid accessing invalid address
- introduce .{init,destroy}_{,de}compress_ctx callback functions.

I guess we merged related patches with wrong sequence as this patch depends on ("f2fs: compress: add .{init,destroy}_decompress_ctx callback").

Done.

Quoted 2 lines

Thanks,