erofs-utils: lib: adjust MicroLZMA default dictionary size
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 30 Apr 2024 06:37:30 +0000 (14:37 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 1 May 2024 06:43:30 +0000 (14:43 +0800)
If dict_size is not given, it will be set as max(32k, pclustersize * 8)
but no more than Z_EROFS_LZMA_MAX_DICT_SIZE.

Also kill an obsolete warning since multi-threaded support is landed.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240430063730.599937-2-hsiangkao@linux.alibaba.com
lib/compressor_liblzma.c
mkfs/main.c

index 2f19a93e2373539a01feb7f84c8488ff68416b9e..d609a28383e6321ed15497aaee15f5fbd8606214 100644 (file)
@@ -70,11 +70,18 @@ static int erofs_compressor_liblzma_setlevel(struct erofs_compress *c,
 static int erofs_compressor_liblzma_setdictsize(struct erofs_compress *c,
                                                u32 dict_size)
 {
-       if (!dict_size)
-               dict_size = erofs_compressor_lzma.default_dictsize;
+       if (!dict_size) {
+               if (erofs_compressor_lzma.default_dictsize) {
+                       dict_size = erofs_compressor_lzma.default_dictsize;
+               } else {
+                       dict_size = min_t(u32, Z_EROFS_LZMA_MAX_DICT_SIZE,
+                                         cfg.c_mkfs_pclustersize_max << 3);
+                       if (dict_size < 32768)
+                               dict_size = 32768;
+               }
+       }
 
-       if (dict_size > erofs_compressor_lzma.max_dictsize ||
-           dict_size < 4096) {
+       if (dict_size > Z_EROFS_LZMA_MAX_DICT_SIZE || dict_size < 4096) {
                erofs_err("invalid dictionary size %u", dict_size);
                return -EINVAL;
        }
@@ -86,7 +93,6 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
 {
        struct erofs_liblzma_context *ctx;
        u32 preset;
-       static erofs_atomic_bool_t __warnonce;
 
        ctx = malloc(sizeof(*ctx));
        if (!ctx)
@@ -105,15 +111,12 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
        ctx->opt.dict_size = c->dict_size;
 
        c->private_data = ctx;
-       if (!erofs_atomic_test_and_set(&__warnonce))
-               erofs_warn("It may take a longer time since MicroLZMA is still single-threaded for now.");
        return 0;
 }
 
 const struct erofs_compressor erofs_compressor_lzma = {
        .default_level = LZMA_PRESET_DEFAULT,
        .best_level = 109,
-       .default_dictsize = Z_EROFS_LZMA_MAX_DICT_SIZE,
        .max_dictsize = Z_EROFS_LZMA_MAX_DICT_SIZE,
        .init = erofs_compressor_liblzma_init,
        .exit = erofs_compressor_liblzma_exit,
index a047dfa4100ce5267518d6d204e5d78f288cbdc7..4c3620de777dd4b80bf74cafe19490bbdbc189b6 100644 (file)
@@ -137,8 +137,12 @@ static void usage(int argc, char **argv)
                                       spaces, s->c->best_level, s->c->default_level);
                }
                if (s->c->setdictsize) {
-                       printf("%s  [,dictsize=<dictsize>]\t(default=%u, max=%u)\n",
-                              spaces, s->c->default_dictsize, s->c->max_dictsize);
+                       if (s->c->default_dictsize)
+                               printf("%s  [,dictsize=<dictsize>]\t(default=%u, max=%u)\n",
+                                      spaces, s->c->default_dictsize, s->c->max_dictsize);
+                       else
+                               printf("%s  [,dictsize=<dictsize>]\t(default=<auto>, max=%u)\n",
+                                      spaces, s->c->max_dictsize);
                }
        }
        printf(