jffs2: add support for zstd compression
RFC PATCH v2 1/1 jffs2: add support for zstd compression
Implement support for zstd compression in jffs2 at the default compression level (3).
Lightly tested in OpenWrt, on a single CPU embedded MIPS32 system (AirGrid M2).
---
v2: fix blunder in compression context allocation
fs/jffs2/Kconfig | 9 +++ fs/jffs2/Makefile | 1 + fs/jffs2/compr.c | 10 +++ fs/jffs2/compr.h | 6 ++ fs/jffs2/compr_zstd.c | 131 +++++++++++++++++++++++++++++++++++++ fs/jffs2/super.c | 7 ++ include/uapi/linux/jffs2.h | 1 + 7 files changed, 165 insertions(+) create mode 100644 fs/jffs2/compr_zstd.c
fs/jffs2/Kconfig +9 -0
@@ -136,6 +136,15 @@ config JFFS2_LZO This feature was added in July, 2007. Say 'N' if you need compatibility with older bootloaders or kernels. +config JFFS2_ZSTD + bool "JFFS2 zstd compression support" if JFFS2_COMPRESSION_OPTIONS + select ZSTD_COMPRESS + select ZSTD_DECOMPRESS + depends on JFFS2_FS + default n + help + Zstd compression. + config JFFS2_RTIME bool "JFFS2 RTIME compression support" if JFFS2_COMPRESSION_OPTIONS depends on JFFS2_FS
fs/jffs2/Makefile +1 -0
@@ -19,4 +19,5 @@ jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o jffs2-$(CONFIG_JFFS2_LZO) += compr_lzo.o +jffs2-$(CONFIG_JFFS2_ZSTD) += compr_zstd.o jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o
fs/jffs2/compr.c +10 -0
@@ -237,6 +237,10 @@ uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f, ret =jffs2_selected_compress (JFFS2_COMPR_ZLIB , data_in, cpage_out, datalen, cdatalen);break ; +case JFFS2_COMPR_MODE_FORCEZSTD : + ret =jffs2_selected_compress (JFFS2_COMPR_ZSTD , data_in, + cpage_out, datalen, cdatalen); +break ;default :pr_err ("unknown compression mode\n" ); }
@@ -378,6 +382,9 @@ int __init jffs2_compressors_init(void)#ifdef CONFIG_JFFS2_LZO jffs2_lzo_init ();#endif +#ifdef CONFIG_JFFS2_ZSTD +jffs2_zstd_init (); +#endif /* Setting default compression mode */ #ifdef CONFIG_JFFS2_CMODE_NONE jffs2_compression_mode =JFFS2_COMPR_MODE_NONE ;
@@ -413,6 +420,9 @@ int jffs2_compressors_exit(void)#endif #ifdef CONFIG_JFFS2_ZLIB jffs2_zlib_exit (); +#endif +#ifdef CONFIG_JFFS2_ZSTD +jffs2_zstd_exit ();#endif return 0 ; }
fs/jffs2/compr.h +6 -0
@@ -31,6 +31,7 @@#define JFFS2_RTIME_PRIORITY 50#define JFFS2_ZLIB_PRIORITY 60#define JFFS2_LZO_PRIORITY 80 +#define JFFS2_ZSTD_PRIORITY 90#define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */
@@ -42,6 +43,7 @@#define JFFS2_COMPR_MODE_FAVOURLZO 3#define JFFS2_COMPR_MODE_FORCELZO 4#define JFFS2_COMPR_MODE_FORCEZLIB 5 +#define JFFS2_COMPR_MODE_FORCEZSTD 6#define FAVOUR_LZO_PERCENT 80
@@ -101,5 +103,9 @@ void jffs2_zlib_exit(void);int jffs2_lzo_init (void );void jffs2_lzo_exit (void );#endif +#ifdef CONFIG_JFFS2_ZSTD +int jffs2_zstd_init (void ); +void jffs2_zstd_exit (void ); +#endif #endif /* __JFFS2_COMPR_H__ */
fs/jffs2/compr_zstd.c new file +131 -0
131 lines not on this page · raw message
fs/jffs2/super.c +7 -0
@@ -73,6 +73,10 @@ static const char *jffs2_compr_name(unsigned int compr)#ifdef CONFIG_JFFS2_ZLIB case JFFS2_COMPR_MODE_FORCEZLIB :return "zlib" ; +#endif +#ifdef CONFIG_JFFS2_ZSTD +case JFFS2_COMPR_MODE_FORCEZSTD : +return "zstd" ;#endif default :/* should never happen; programmer error */
@@ -174,6 +178,9 @@ static const struct constant_table jffs2_param_compr[] = {#endif #ifdef CONFIG_JFFS2_ZLIB {"zlib", JFFS2_COMPR_MODE_FORCEZLIB }, +#endif +#ifdef CONFIG_JFFS2_ZSTD + {"zstd", JFFS2_COMPR_MODE_FORCEZSTD }, #endif {} };
include/uapi/linux/jffs2.h +1 -0
@@ -46,6 +46,7 @@#define JFFS2_COMPR_DYNRUBIN 0x05#define JFFS2_COMPR_ZLIB 0x06#define JFFS2_COMPR_LZO 0x07 +#define JFFS2_COMPR_ZSTD 0x08/* Compatibility flags. */ #define JFFS2_COMPAT_MASK 0xc000/* What do to if an unknown nodetype is found */ #define JFFS2_NODE_ACCURATE 0x2000
Signature · 1 line
2.31.0
Friendly ping (and also cc'ing dwmw2).
Quoted 5 lines · Rui Salvaterra
Implement support for zstd compression in jffs2 at the default compression level (3).
Lightly tested in OpenWrt, on a single CPU embedded MIPS32 system (AirGrid M2).
Quoted 2 lines · Rui Salvaterra
Friendly ping (and also cc'ing dwmw2).
Ping^2, now the merge window is closed.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
David Woodhouse
maintainerQuoted 8 lines · Rui Salvaterra
Friendly ping (and also cc'ing dwmw2).
Quoted 5 lines · Rui Salvaterra
Implement support for zstd compression in jffs2 at the default compression level (3).
Lightly tested in OpenWrt, on a single CPU embedded MIPS32 system (AirGrid M2).
Seems reasonable. Do you have the corresponding addition for mkfs.jffs2 and can you report the boot time / image sizes with it vs. zlib on a typical platform?
And if it doesn't make a difference to boot time or image size... why are we doing it?
Hi, David,
Quoted 6 lines · David Woodhouse
Quoted 4 lines · Rui Salvaterra
Friendly ping (and also cc'ing dwmw2).
Quoted 1 line · Rui Salvaterra
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Implement support for zstd compression in jffs2 at the default compression level (3).
Lightly tested in OpenWrt, on a single CPU embedded MIPS32 system (AirGrid M2).
Seems reasonable. Do you have the corresponding addition for mkfs.jffs2 and can you report the boot time / image sizes with it vs. zlib on a typical platform?
I haven't done any changes to userspace, other than OpenWrt's fstools (to force-enable zstd compression at mount time, with compr=zstd).
Quoted 2 lines
And if it doesn't make a difference to boot time or image size... why are we doing it?
In OpenWrt, we're carrying an enormous patch [1] which enables lzma compression in (and only in) jffs2. Having a single compression algorithm with good all-around performance, usable by other subsystems (e.g. zram, ubifs) would allow us to disable other redundant algorithms and consequently reduce the total image size (I measured an increase of nearly 200 kB by the lzma patch alone).