[PATCH v7 3/5] erofs-utils: mkfs: add --workers=# parameter
Gao Xiang
hsiangkao at linux.alibaba.com
Fri Mar 15 12:10:17 AEDT 2024
From: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
This patch introduces `--workers=#` parameter for the incoming
multi-threaded compression support.
It also introduces a concept called `segment size` to split large
inodes for multi-threaded compression, which has the fixed value
16MiB and cannot be modified for now.
Signed-off-by: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs/config.h | 4 ++++
lib/config.c | 4 ++++
mkfs/main.c | 23 +++++++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 73e3ac2..d2f91ff 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -75,6 +75,10 @@ struct erofs_configure {
char c_force_chunkformat;
/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
int c_inline_xattr_tolerance;
+#ifdef EROFS_MT_ENABLED
+ u64 c_segment_size;
+ u32 c_mt_workers;
+#endif
u32 c_pclusterblks_max, c_pclusterblks_def, c_pclusterblks_packed;
u32 c_max_decompressed_extent_bytes;
diff --git a/lib/config.c b/lib/config.c
index 947a183..2530274 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -38,6 +38,10 @@ void erofs_init_configure(void)
cfg.c_pclusterblks_max = 1;
cfg.c_pclusterblks_def = 1;
cfg.c_max_decompressed_extent_bytes = -1;
+#ifdef EROFS_MT_ENABLED
+ cfg.c_segment_size = 16ULL * 1024 * 1024;
+ cfg.c_mt_workers = 1;
+#endif
erofs_stdout_tty = isatty(STDOUT_FILENO);
}
diff --git a/mkfs/main.c b/mkfs/main.c
index 8a68a72..126a049 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -77,6 +77,9 @@ static struct option long_options[] = {
#ifdef HAVE_LIBLZMA
{"unlzma", optional_argument, NULL, 519},
{"unxz", optional_argument, NULL, 519},
+#endif
+#ifdef EROFS_MT_ENABLED
+ {"workers", required_argument, NULL, 520},
#endif
{0, 0, 0, 0},
};
@@ -178,6 +181,9 @@ static void usage(int argc, char **argv)
#ifdef HAVE_LIBLZMA
" --unxz[=X] try to filter the tarball stream through xz/lzma/lzip\n"
" (and optionally dump the raw stream to X together)\n"
+#endif
+#ifdef EROFS_MT_ENABLED
+ " --workers=# set the number of worker threads to # (default=1)\n"
#endif
" --xattr-prefix=X X=extra xattr name prefix\n"
" --mount-point=X X=prefix of target fs path (default: /)\n"
@@ -660,6 +666,23 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
erofstar.dumpfile = strdup(optarg);
tarerofs_decoder = EROFS_IOS_DECODER_GZIP + (opt - 518);
break;
+#ifdef EROFS_MT_ENABLED
+ case 520: {
+ unsigned int processors;
+
+ cfg.c_mt_workers = strtoul(optarg, &endptr, 0);
+ if (errno || *endptr != '\0') {
+ erofs_err("invalid worker number %s", optarg);
+ return -EINVAL;
+ }
+
+ processors = erofs_get_available_processors();
+ if (cfg.c_mt_workers > processors)
+ erofs_warn("the number of workers %d is more than the number of processors %d, performance may be impacted.",
+ cfg.c_mt_workers, processors);
+ break;
+ }
+#endif
case 'V':
version();
exit(0);
--
2.39.3
More information about the Linux-erofs
mailing list