erofs-utils: mkfs: use all available processors by default
authorGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 27 Apr 2024 06:25:52 +0000 (14:25 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 27 Apr 2024 22:52:09 +0000 (06:52 +0800)
Fulfill the needs of most users.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240427062552.744810-1-hsiangkao@linux.alibaba.com
include/erofs/config.h
lib/compress.c
lib/config.c
mkfs/main.c

index d2f91ff8e5725416d1d10f8a4e32cef7cd692545..16910ea7bdd413009bff46ab4ef1dc1a52c09ff1 100644 (file)
@@ -76,10 +76,9 @@ struct erofs_configure {
        /* < 0, xattr disabled and INT_MAX, always use inline xattrs */
        int c_inline_xattr_tolerance;
 #ifdef EROFS_MT_ENABLED
-       u64 c_segment_size;
+       u64 c_mkfs_segment_size;
        u32 c_mt_workers;
 #endif
-
        u32 c_pclusterblks_max, c_pclusterblks_def, c_pclusterblks_packed;
        u32 c_max_decompressed_extent_bytes;
        u64 c_unix_timestamp;
index 7fef69811ddfbf269e4ada69760e784ffd534191..f9183223dc0f442e9fabd205c1579a6b05f9419c 100644 (file)
@@ -1255,7 +1255,7 @@ void z_erofs_mt_workfn(struct erofs_work *work, void *tlsp)
        }
        sctx->memoff = 0;
 
-       ret = z_erofs_compress_segment(sctx, sctx->seg_idx * cfg.c_segment_size,
+       ret = z_erofs_compress_segment(sctx, sctx->seg_idx * cfg.c_mkfs_segment_size,
                                       EROFS_NULL_ADDR);
 
 out:
@@ -1304,7 +1304,7 @@ int z_erofs_mt_compress(struct z_erofs_compress_ictx *ictx)
        struct erofs_compress_work *cur, *head = NULL, **last = &head;
        struct erofs_compress_cfg *ccfg = ictx->ccfg;
        struct erofs_inode *inode = ictx->inode;
-       int nsegs = DIV_ROUND_UP(inode->i_size, cfg.c_segment_size);
+       int nsegs = DIV_ROUND_UP(inode->i_size, cfg.c_mkfs_segment_size);
        int i;
 
        ictx->seg_num = nsegs;
@@ -1338,9 +1338,9 @@ int z_erofs_mt_compress(struct z_erofs_compress_ictx *ictx)
                if (i == nsegs - 1)
                        cur->ctx.remaining = inode->i_size -
                                              inode->fragment_size -
-                                             i * cfg.c_segment_size;
+                                             i * cfg.c_mkfs_segment_size;
                else
-                       cur->ctx.remaining = cfg.c_segment_size;
+                       cur->ctx.remaining = cfg.c_mkfs_segment_size;
 
                cur->alg_id = ccfg->handle.alg->id;
                cur->alg_name = ccfg->handle.alg->name;
@@ -1718,6 +1718,14 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *s
 
        z_erofs_mt_enabled = false;
 #ifdef EROFS_MT_ENABLED
+       if (cfg.c_mt_workers > 1 && (cfg.c_dedupe || cfg.c_fragments)) {
+               if (cfg.c_dedupe)
+                       erofs_warn("multi-threaded dedupe is NOT implemented for now");
+               if (cfg.c_fragments)
+                       erofs_warn("multi-threaded fragments is NOT implemented for now");
+               cfg.c_mt_workers = 0;
+       }
+
        if (cfg.c_mt_workers > 1) {
                ret = erofs_alloc_workqueue(&z_erofs_mt_ctrl.wq,
                                            cfg.c_mt_workers,
index 25302748ff627aa5156468ab6c1015f2903cf725..98adaef723735428dd8c4e098b2e20ad7e6da56d 100644 (file)
@@ -38,11 +38,6 @@ 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);
 }
 
index d632f740ad3fa10c1bf0398bd353a1a6a5ce70a6..9ad213b8540079854d4b64fe8369775c1e03f775 100644 (file)
@@ -838,12 +838,6 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
                }
                cfg.c_pclusterblks_packed = pclustersize_packed >> sbi.blkszbits;
        }
-#ifdef EROFS_MT_ENABLED
-       if (cfg.c_mt_workers > 1 && (cfg.c_dedupe || cfg.c_fragments)) {
-               erofs_warn("Note that dedupe/fragments are NOT supported in multi-threaded mode for now, resetting --workers=1.");
-               cfg.c_mt_workers = 1;
-       }
-#endif
        return 0;
 }
 
@@ -954,6 +948,10 @@ static void erofs_mkfs_default_options(void)
        cfg.c_legacy_compress = false;
        cfg.c_inline_data = true;
        cfg.c_xattr_name_filter = true;
+#ifdef EROFS_MT_ENABLED
+       cfg.c_mt_workers = erofs_get_available_processors();
+       cfg.c_mkfs_segment_size = 16ULL * 1024 * 1024;
+#endif
        sbi.blkszbits = ilog2(min_t(u32, getpagesize(), EROFS_MAX_BLOCK_SIZE));
        sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_ZERO_PADDING;
        sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |