Whamcloud - gitweb
e2fsck: split groups to different threads
authorLi Xi <lixi@ddn.com>
Thu, 22 Aug 2019 07:35:12 +0000 (15:35 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Mon, 19 Sep 2022 22:23:42 +0000 (16:23 -0600)
The start/end groups of a thread is calculated according to the
thread number. But still, only one thread is used to check.

E2fsprogs-commit: 562df7468d97042689896cff4b48c6cebc3b8508

Change-Id: I3175b4e6f0423ecd69ed55afea45f1c5919f5c79
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass1.c

index a610f18..822b1d6 100644 (file)
@@ -2269,13 +2269,14 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src)
 }
 
 static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thread_ctx,
-                                            int thread_index)
+                                            int thread_index, int num_threads)
 {
        errcode_t               retval;
        e2fsck_t                thread_context;
        ext2_filsys             thread_fs;
        ext2_filsys             global_fs = global_ctx->fs;
        struct e2fsck_thread    *tinfo;
+       dgrp_t                  average_group;
 
        assert(global_ctx->inode_used_map == NULL);
        assert(global_ctx->inode_dir_map == NULL);
@@ -2315,11 +2316,20 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre
        thread_context->thread_info.et_thread_index = thread_index;
        set_up_logging(thread_context);
 
-       assert(thread_index == 0);
+       /*
+        * Distribute work to multiple threads:
+        * Each thread work on fs->group_desc_count / nthread groups.
+        */
        tinfo = &thread_context->thread_info;
-       tinfo->et_group_start = 0;
-       tinfo->et_group_next = 0;
-       tinfo->et_group_end = thread_fs->group_desc_count;
+       average_group = thread_fs->group_desc_count / num_threads;
+       if (average_group == 0)
+               average_group = 1;
+       tinfo->et_group_start = average_group * thread_index;
+       if (thread_index == num_threads - 1)
+               tinfo->et_group_end = thread_fs->group_desc_count;
+       else
+               tinfo->et_group_end = average_group * (thread_index + 1);
+       tinfo->et_group_next = tinfo->et_group_start;
 
        thread_context->fs = thread_fs;
        *thread_ctx = thread_context;
@@ -2543,7 +2553,8 @@ static int e2fsck_pass1_threads_start(struct e2fsck_thread_info **pinfo,
        for (i = 0; i < num_threads; i++) {
                tmp_pinfo = &infos[i];
                tmp_pinfo->eti_thread_index = i;
-               retval = e2fsck_pass1_thread_prepare(global_ctx, &thread_ctx, i);
+               retval = e2fsck_pass1_thread_prepare(global_ctx, &thread_ctx,
+                                                    i, num_threads);
                if (retval) {
                        com_err(global_ctx->program_name, retval,
                                _("while preparing pass1 thread\n"));