erofs-utils: add LZMA fixed-sized output compression support
A message that is not in the archive (sent off-list or not yet received): [email protected]
cover erofs-utils: add LZMA fixed-sized output compression support
From: Gao Xiang <[email protected]>
Hi folks,
Thanks to Lasse, liblzma finally has a preliminary usable fixed-sized output compression support. I've made a quick integration and it seems work. The preliminary C/R result of this is:
459382784 enwik9_4k.squashfs.xz.img 401649664 enwik9_8k.squashfs.xz.img 371617792 enwik9_4k.lzma.erofs.img 360972288 enwik9_16k.squashfs.xz.img
* Also -zlzma,1,
389115904 enwik9_4k.lzma.erofs.img
So it's worthwhile to take the further step and get an entire solution.
TODOs:
- make a formal configure.ac / Makefile.am rather than such hack;
- save DICT_SIZE to super block rather than using a fixed value;
- support threaded compression to boost up build time (including segment compression);
- look on sorting out kernel side support.
Thanks,
Gao Xiang
Gao Xiang (4):
erofs-utils: clevel set up as an individual function
erofs-utils: add liblzma dependency
erofs-utils: mkfs: add LZMA algorithm support
erofs-utils: fuse: add LZMA algorithm support
fuse/Makefile.am | 2 +- include/erofs_fs.h | 3 +- lib/Makefile.am | 2 + lib/compress.c | 16 ++++--- lib/compressor.c | 23 +++++++--- lib/compressor.h | 7 ++- lib/compressor_liblzma.c | 93 ++++++++++++++++++++++++++++++++++++++++ lib/compressor_lz4.c | 1 - lib/compressor_lz4hc.c | 21 ++++++--- lib/data.c | 7 +-- lib/decompress.c | 62 +++++++++++++++++++++++++++ mkfs/Makefile.am | 2 +- 12 files changed, 211 insertions(+), 28 deletions(-) create mode 100644 lib/compressor_liblzma.c
Signature · 1 line
2.24.0
RFC PATCH 1/4 erofs-utils: clevel set up as an individual function
From: Gao Xiang <[email protected]>
Compression level passed in can be verified then. Also, in order for preparation of upcoming LZMA fixed-sized output compression.
--- lib/compress.c | 11 ++++++----- lib/compressor.c | 22 +++++++++++++++------- lib/compressor.h | 6 ++++-- lib/compressor_lz4.c | 1 - lib/compressor_lz4hc.c | 21 +++++++++++++++------ 5 files changed, 40 insertions(+), 21 deletions(-)
lib/compress.c +6 -5
@@ -20,8 +20,6 @@#include "compressor.h" static struct erofs_compress compresshandle; -static int compressionlevel; -static struct z_erofs_map_header mapheader;struct z_erofs_vle_compress_ctx {
@@ -165,8 +163,7 @@ static int vle_compress_one(struct erofs_inode *inode, } count = len; - ret =erofs_compress_destsize (h, compressionlevel, - ctx->queue + ctx->head, + ret =erofs_compress_destsize (h, ctx->queue + ctx->head, &count, dst,EROFS_BLKSIZ );if (ret <=0 ) {if (ret != -EAGAIN ) {
@@ -520,7 +517,11 @@ int z_erofs_compress_init(void)if (!cfg.c_compr_alg_master)return 0 ; - compressionlevel = cfg.c_compr_level_master <0 ? + ret =erofs_compressor_setlevel (&compresshandle, cfg.c_compr_level_master); +if (ret) +return ret; + + compresshandle.compression_level = cfg.c_compr_level_master <0 ? compresshandle.alg->default_level : cfg.c_compr_level_master;
lib/compressor.c +15 -7
@@ -22,11 +22,8 @@ static struct erofs_compressor *compressors[] = { };int erofs_compress_destsize (struct erofs_compress *c, -int compression_level, -void *src, -unsigned int *srcsize, -void *dst, -unsigned int dstsize) +void *src,unsigned int *srcsize, +void *dst,unsigned int dstsize) {int ret;
@@ -34,8 +31,7 @@ int erofs_compress_destsize(struct erofs_compress *c,if (!c->alg->compress_destsize)return -ENOTSUP ; - ret = c->alg->compress_destsize (c, compression_level, - src, srcsize, dst, dstsize); + ret = c->alg->compress_destsize (c, src, srcsize, dst, dstsize);if (ret <0 )return ret;
@@ -50,6 +46,18 @@ const char *z_erofs_list_available_compressors(unsigned int i)return i >=ARRAY_SIZE (compressors) ?NULL : compressors[i]->name; } +int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level) +{ +DBG_BUGON (!c->alg); +if (c->alg->setlevel) +return c->alg->setlevel (c, compression_level); + +if (compression_level >=0 ) +return -EINVAL ; + c->compression_level =0 ; +return 0 ; +} +int erofs_compressor_init (struct erofs_compress *c,char *alg_name) {int ret, i;
lib/compressor.h +4 -2
@@ -21,9 +21,9 @@ struct erofs_compressor {int (*init)(struct erofs_compress *c);int (*exit)(struct erofs_compress *c); +int (*setlevel)(struct erofs_compress *c,int compression_level);int (*compress_destsize)(struct erofs_compress *c, -int compress_level,void *src,unsigned int *srcsize,void *dst,unsigned int dstsize); };
@@ -32,6 +32,7 @@ struct erofs_compress {struct erofs_compressor *alg;unsigned int compress_threshold; +unsigned int compression_level;/* *_destsize specific */ unsigned int destsize_alignsize;
@@ -45,10 +46,11 @@ struct erofs_compress {extern struct erofs_compressor erofs_compressor_lz4;extern struct erofs_compressor erofs_compressor_lz4hc; -int erofs_compress_destsize (struct erofs_compress *c,int compression_level, +int erofs_compress_destsize (struct erofs_compress *c,void *src,unsigned int *srcsize,void *dst,unsigned int dstsize); +int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level);int erofs_compressor_init (struct erofs_compress *c,char *alg_name);int erofs_compressor_exit (struct erofs_compress *c);
lib/compressor_lz4.c +0 -1
@@ -11,7 +11,6 @@#include "compressor.h" static int lz4_compress_destsize (struct erofs_compress *c, -int compression_level,void *src,unsigned int *srcsize,void *dst,unsigned int dstsize) {
lib/compressor_lz4hc.c +15 -6
@@ -12,16 +12,13 @@#include "compressor.h" static int lz4hc_compress_destsize (struct erofs_compress *c, -int compression_level, -void *src, -unsigned int *srcsize, -void *dst, -unsigned int dstsize) +void *src,unsigned int *srcsize, +void *dst,unsigned int dstsize) {int srcSize = (int )*srcsize;int rc =LZ4_compress_HC_destSize (c->private_data, src, dst, &srcSize, (int )dstsize, - compression_level); + c->compression_level);if (!rc)return -EFAULT ; *srcsize = srcSize;
@@ -47,12 +44,24 @@ static int compressor_lz4hc_init(struct erofs_compress *c)return 0 ; } +static int compressor_lz4hc_setlevel (struct erofs_compress *c, +int compression_level) +{ +if (compression_level >LZ4HC_CLEVEL_MAX ) +return -EINVAL ; + + c->compression_level = compression_level <0 ? +LZ4HC_CLEVEL_DEFAULT : compression_level; +return 0 ; +} +struct erofs_compressor erofs_compressor_lz4hc = { .name ="lz4hc" , .default_level =LZ4HC_CLEVEL_DEFAULT , .best_level =LZ4HC_CLEVEL_MAX , .init = compressor_lz4hc_init, .exit = compressor_lz4hc_exit, + .setlevel = compressor_lz4hc_setlevel, .compress_destsize = lz4hc_compress_destsize, };
Signature · 1 line
2.24.0
RFC PATCH 2/4 erofs-utils: add liblzma dependency
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
liblzma [1] has an experimental fixed-sized output LZMA compression support now. Let's use it to have a try!
TODO:
complete configure.ac / Makefile.am
--- fuse/Makefile.am | 2 +- lib/Makefile.am | 1 + mkfs/Makefile.am | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)
fuse/Makefile.am +1 -1
@@ -7,4 +7,4 @@ erofsfuse_SOURCES = dir.c main.c erofsfuse_CFLAGS = -Wall -Werror -I$(top_srcdir)/include erofsfuse_CFLAGS += -DFUSE_USE_VERSION=26 ${libfuse_CFLAGS} ${libselinux_CFLAGS} erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse_LIBS} ${liblz4_LIBS} ${libselinux_LIBS} - +erofsfuse_LDADD += -L/tmp/xz-test/lib -llzma
lib/Makefile.am +1 -0
@@ -13,3 +13,4 @@ liberofs_la_SOURCES += compressor_lz4hc.c endif endif +liberofs_la_CFLAGS += -I/tmp/xz-test/include
mkfs/Makefile.am +1 -1
@@ -7,4 +7,4 @@ AM_CPPFLAGS = ${libuuid_CFLAGS} ${libselinux_CFLAGS} mkfs_erofs_SOURCES = main.c mkfs_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include mkfs_erofs_LDADD = ${libuuid_LIBS} $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} ${liblz4_LIBS} - +mkfs_erofs_LDADD += -L/tmp/xz-test/lib -llzma
Signature · 1 line
2.24.0
RFC PATCH 3/4 erofs-utils: mkfs: add LZMA algorithm support
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
This patch adds LZMA compression algorithms to erofs-utils compression framework by using upstream liblzma.
--- include/erofs_fs.h | 3 +- lib/Makefile.am | 1 + lib/compress.c | 5 ++- lib/compressor.c | 1 + lib/compressor.h | 1 + lib/compressor_liblzma.c | 93 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 lib/compressor_liblzma.c
include/erofs_fs.h +2 -1
@@ -193,7 +193,8 @@ static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)/* available compression algorithm types (for h_algorithmtype) */ enum { -Z_EROFS_COMPRESSION_LZ4 =0 , +Z_EROFS_COMPRESSION_LZ4 =0 , +Z_EROFS_COMPRESSION_LZMA =1 ,Z_EROFS_COMPRESSION_MAX };
lib/Makefile.am +1 -0
@@ -14,3 +14,4 @@ endif endif liberofs_la_CFLAGS += -I/tmp/xz-test/include +liberofs_la_SOURCES += compressor_liblzma.c
lib/compress.c +4 -1
@@ -493,6 +493,8 @@ static int erofs_get_compress_algorithm_id(const char *name) {if (!strcmp (name,"lz4" ) || !strcmp (name,"lz4hc" ))return Z_EROFS_COMPRESSION_LZ4 ; +if (!strcmp (name,"lzma" )) +return Z_EROFS_COMPRESSION_LZMA ;return -ENOTSUP ; }
@@ -511,7 +513,8 @@ int z_erofs_compress_init(void)* clear LZ4_0PADDING feature for old kernel compatibility. */ if (!cfg.c_compr_alg_master || -strncmp (cfg.c_compr_alg_master,"lz4" ,3 )) + (strncmp (cfg.c_compr_alg_master,"lz4" ,3 ) && +strcmp (cfg.c_compr_alg_master,"lzma" )))erofs_sb_clear_lz4_0padding ();if (!cfg.c_compr_alg_master)
lib/compressor.c +1 -0
@@ -19,6 +19,7 @@ static struct erofs_compressor *compressors[] = {#endif &erofs_compressor_lz4, #endif + &erofs_compressor_lzma, }; int erofs_compress_destsize(struct erofs_compress *c,
lib/compressor.h +1 -0
@@ -45,6 +45,7 @@ struct erofs_compress {/* list of compression algorithms */ extern struct erofs_compressor erofs_compressor_lz4;extern struct erofs_compressor erofs_compressor_lz4hc; +extern struct erofs_compressor erofs_compressor_lzma; int erofs_compress_destsize(struct erofs_compress *c, void *src, unsigned int *srcsize,
lib/compressor_liblzma.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.24.0
RFC PATCH 4/4 erofs-utils: fuse: add LZMA algorithm support
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
This patch adds LZMA compression algorithms to erofsfuse to test if LZMA fixed-sized output algorithm works as expected.
--- lib/data.c | 7 +++--- lib/decompress.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-)
lib/data.c +4 -3
@@ -146,9 +146,10 @@ static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,if (ret <0 )return -EIO ; - algorithmformat = map.m_flags &EROFS_MAP_ZIPPED ? -Z_EROFS_COMPRESSION_LZ4 : -Z_EROFS_COMPRESSION_SHIFTED ; +if (map.m_flags &EROFS_MAP_ZIPPED ) + algorithmformat = inode->z_algorithmtype[0 ]; +else + algorithmformat =Z_EROFS_COMPRESSION_SHIFTED ;/* * trim to the needed size if the returned extent is quite
lib/decompress.c +62 -0
73 lines not on this page · raw message
Signature · 1 line
2.24.0