[PATCH v2 3/3] erofs-utils: support limit max decompressed extent size
Gao Xiang
xiang at kernel.org
Tue Jun 1 00:31:17 AEST 2021
Currently, some data pattern (e.g. zeroed data) could cause very
high CR with EROFS. However, for such extreme high C/R compressed
pclusters, the kernel side hasn't optimize such cases yet (such as
decompressing such pclusters fully in advance.)
Alternatively, let's add support to limit each decompressed extent
size for now.
Signed-off-by: Gao Xiang <xiang at kernel.org>
---
include/erofs/config.h | 1 +
lib/compress.c | 2 +-
lib/config.c | 1 +
man/mkfs.erofs.1 | 3 +++
mkfs/main.c | 11 +++++++++++
5 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 21bd25e886e6..d140a735bd49 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -58,6 +58,7 @@ struct erofs_configure {
int c_inline_xattr_tolerance;
u32 c_physical_clusterblks;
+ u32 c_max_decompressed_extent_bytes;
u64 c_unix_timestamp;
u32 c_uid, c_gid;
#ifdef WITH_ANDROID
diff --git a/lib/compress.c b/lib/compress.c
index 1b847ce27c2f..2093bfd68b71 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -184,7 +184,7 @@ static int vle_compress_one(struct erofs_inode *inode,
}
}
- count = len;
+ count = min(len, cfg.c_max_decompressed_extent_bytes);
ret = erofs_compress_destsize(h, compressionlevel,
ctx->queue + ctx->head,
&count, dst, pclustersize);
diff --git a/lib/config.c b/lib/config.c
index bc0afa284807..99fcf498f178 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -27,6 +27,7 @@ void erofs_init_configure(void)
cfg.c_uid = -1;
cfg.c_gid = -1;
cfg.c_physical_clusterblks = 1;
+ cfg.c_max_decompressed_extent_bytes = -1;
}
void erofs_show_config(void)
diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
index 4f2e43565799..d164fa51fe17 100644
--- a/man/mkfs.erofs.1
+++ b/man/mkfs.erofs.1
@@ -85,6 +85,9 @@ Make all files owned by root.
.TP
.B \-\-help
Display this help and exit.
+.TP
+.B \-\-max-extent-bytes #
+Specify maximum decompressed extent size # in bytes.
.SH AUTHOR
This version of \fBmkfs.erofs\fR is written by Li Guifu <blucerlee at gmail.com>,
Miao Xie <miaoxie at huawei.com> and Gao Xiang <xiang at kernel.org> with
diff --git a/mkfs/main.c b/mkfs/main.c
index b2a4cba1d2f5..e476189f0731 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -42,6 +42,7 @@ static struct option long_options[] = {
#ifndef NDEBUG
{"random-pclusterblks", no_argument, NULL, 8},
#endif
+ {"max-extent-bytes", required_argument, NULL, 9},
#ifdef WITH_ANDROID
{"mount-point", required_argument, NULL, 10},
{"product-out", required_argument, NULL, 11},
@@ -85,6 +86,7 @@ static void usage(void)
" --force-gid=# set all file gids to # (# = GID)\n"
" --all-root make all files owned by root\n"
" --help display this help and exit\n"
+ " --max-extent-bytes=# set maximum decompressed extent size # in bytes\n"
#ifndef NDEBUG
" --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n"
#endif
@@ -268,6 +270,15 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
cfg.c_random_pclusterblks = true;
break;
#endif
+ case 9:
+ cfg.c_max_decompressed_extent_bytes =
+ strtoul(optarg, &endptr, 0);
+ if (*endptr != '\0') {
+ erofs_err("invalid maximum uncompressed extent size %s",
+ optarg);
+ return -EINVAL;
+ }
+ break;
#ifdef WITH_ANDROID
case 10:
cfg.mount_point = optarg;
--
2.20.1
More information about the Linux-erofs
mailing list