[PATCH v6 3/5] erofs-utils: mkfs: add --worker=# parameter

Yifan Zhao zhaoyifan at sjtu.edu.cn
Thu Mar 14 23:37:52 AEDT 2024


This patch introduces a --worker=# parameter for the incoming
multi-threaded compression support. It also introduces a segment size
used in multi-threaded compression, which has the default value 16MB
and cannot be modified.

It also introduces a concept called `segment size` to split large files
for multi-threading, which has the default value 16MB for now.

Signed-off-by: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
---
 include/erofs/config.h |  4 ++++
 lib/config.c           |  4 ++++
 mkfs/main.c            | 28 ++++++++++++++++++++++++++++
 3 files changed, 36 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..89252c2 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},
 };
@@ -187,6 +190,9 @@ static void usage(int argc, char **argv)
 		" --product-out=X       X=product_out directory\n"
 		" --fs-config-file=X    X=fs_config file\n"
 		" --block-list-file=X   X=block_list file\n"
+#endif
+#ifdef EROFS_MT_ENABLED
+		" --workers=#            set the number of worker threads to # (default=1)\n"
 #endif
 		);
 }
@@ -416,6 +422,13 @@ static void erofs_rebuild_cleanup(void)
 	rebuild_src_count = 0;
 }
 
+#ifdef EROFS_MT_ENABLED
+static u32 mkfs_max_worker_num()
+{
+	return erofs_get_available_processors() ?: 16;
+}
+#endif
+
 static int mkfs_parse_options_cfg(int argc, char *argv[])
 {
 	char *endptr;
@@ -660,6 +673,20 @@ 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:
+			cfg.c_mt_workers = strtoul(optarg, &endptr, 0);
+			if (errno || *endptr != '\0') {
+				erofs_err("invalid worker number %s", optarg);
+				return -EINVAL;
+			}
+			if (cfg.c_mt_workers > mkfs_max_worker_num()) {
+				cfg.c_mt_workers = mkfs_max_worker_num();
+				erofs_warn("worker number %s is too large, setting to %u",
+				   optarg, cfg.c_mt_workers);
+			}
+			break;
+#endif
 		case 'V':
 			version();
 			exit(0);
@@ -815,6 +842,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		}
 		cfg.c_pclusterblks_packed = pclustersize_packed >> sbi.blkszbits;
 	}
+
 	return 0;
 }
 
-- 
2.44.0



More information about the Linux-erofs mailing list