[PATCH 1/2] erofs-utils: fix liblzma extreme compression levels

Gao Xiang hsiangkao at linux.alibaba.com
Fri Mar 10 20:16:00 AEDT 2023


100 ~ 109 are now valid for LZMA extreme compression.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/compressor_liblzma.c | 11 ++++++++---
 man/mkfs.erofs.1         |  3 ++-
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c
index 4886d6a..f274dce 100644
--- a/lib/compressor_liblzma.c
+++ b/lib/compressor_liblzma.c
@@ -56,11 +56,16 @@ static int erofs_compressor_liblzma_setlevel(struct erofs_compress *c,
 					     int compression_level)
 {
 	struct erofs_liblzma_context *ctx = c->private_data;
+	u32 preset;
 
 	if (compression_level < 0)
-		compression_level = LZMA_PRESET_DEFAULT;
+		preset = LZMA_PRESET_DEFAULT;
+	else if (compression_level >= 100)
+		preset = (compression_level - 100) | LZMA_PRESET_EXTREME;
+	else
+		preset = compression_level;
 
-	if (lzma_lzma_preset(&ctx->opt, compression_level))
+	if (lzma_lzma_preset(&ctx->opt, preset))
 		return -EINVAL;
 
 	/* XXX: temporary hack */
@@ -97,7 +102,7 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c)
 const struct erofs_compressor erofs_compressor_lzma = {
 	.name = "lzma",
 	.default_level = LZMA_PRESET_DEFAULT,
-	.best_level = LZMA_PRESET_EXTREME,
+	.best_level = 109,
 	.init = erofs_compressor_liblzma_init,
 	.exit = erofs_compressor_liblzma_exit,
 	.setlevel = erofs_compressor_liblzma_setlevel,
diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
index c1ad47d..e237877 100644
--- a/man/mkfs.erofs.1
+++ b/man/mkfs.erofs.1
@@ -22,7 +22,8 @@ from \fISOURCE\fR directory.
 .TP
 .BI "\-z " compression-algorithm " [" ",#" "]"
 Set an algorithm for file compression, which can be set with an optional
-compression level separated by a comma.
+compression level (1 to 12 for LZ4HC, 0 to 9 for LZMA and 100 to 109 for LZMA
+extreme compression) separated by a comma.
 .TP
 .BI "\-C " max-pcluster-size
 Specify the maximum size of compress physical cluster in bytes. It may enable
-- 
2.24.4



More information about the Linux-erofs mailing list