Whamcloud - gitweb
LU-16169 e2fsck: fix parallel thread balance 92/53292/3
authorAndreas Dilger <adilger@whamcloud.com>
Thu, 30 Nov 2023 09:28:58 +0000 (02:28 -0700)
committerLi Dongyang <dongyangli@ddn.com>
Wed, 6 Dec 2023 23:45:27 +0000 (23:45 +0000)
Calculate the average number of *used* inodes for each thread to
process instead of the overall average number of inodes in the
filesystem per thread.  Otherwise, if the filesystem is not very
full it will allocate too many groups to the first threads and
none to the last threads.

For example, a filesystem with a total of 5242880 inodes, with
3789293 used inodes should process on average 473661 used inodes
per thread with 8 threads, but this wasn't the case:

    # e2fsck -fn -m8 /dev/vgmyth/lvmythmdt0.ssd
    Pass 1: Checking inodes, blocks, and sizes
    [Thread 0] Scan group range [0, 20), inode_count = 655358/655360
    [Thread 1] Scan group range [20, 40), inode_count = 655360/655360
    [Thread 2] Scan group range [40, 66), inode_count = 647340/655360
    [Thread 3] Scan group range [66, 92), inode_count = 651555/655360
    [Thread 4] Scan group range [92, 112), inode_count = 655360/655360
    [Thread 5] Scan group range [112, 160), inode_count = 524320/655360
    [Thread 6] Scan group range [159, 160), inode_count = 0/655360
    [Thread 7] Scan group range [159, 160), inode_count = 0/655360

With the fix the thread balance is much better, with each thread
processing approximately the same number of used inodes, even the
last thread which has more groups but with fewer used inodes:

    Pass 1: Checking inodes, blocks, and sizes
    [Thread 0] Scan group range [0, 13], used inodes 458750/458752
    [Thread 1] Scan group range [14, 28], used inodes 491520/491520
    [Thread 2] Scan group range [29, 42], used inodes 458752/458752
    [Thread 3] Scan group range [43, 63], used inodes 486191/688128
    [Thread 4] Scan group range [64, 84], used inodes 485024/688128
    [Thread 5] Scan group range [85, 98], used inodes 458752/458752
    [Thread 6] Scan group range [99, 113], used inodes 491520/491520
    [Thread 7] Scan group range [114, 159], used inodes 458784/1507328

Also print the group ranges as closed sets so the brackets align.

Change-Id: If0536d50bf82d0ca76399dad825a894218af0e3f
Fixes: 4e82819edc ("LU-16169 e2fsck: improve parallel thread balance")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/tools/e2fsprogs/+/53292
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
e2fsck/pass1.c
tests/f_multithread/expect.1
tests/f_multithread_logfile/expect.1
tests/f_multithread_no/expect.1

index 449a435..ea5a48c 100644 (file)
@@ -3008,6 +3008,7 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx,
        ext2_filsys             thread_fs;
        ext2_filsys             global_fs = global_ctx->fs;
        struct e2fsck_thread    *tinfo;
+       int                     total_inodes;
        dgrp_t                  grp;
 
        assert(global_ctx->inode_used_map == NULL);
@@ -3100,9 +3101,12 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx,
        tinfo->et_log_length = 0;
        if (thread_context->options & E2F_OPT_MULTITHREAD)
                log_out(thread_context,
-                       _("Scan group range [%d, %d), inode_count = %u/%u\n"),
-                       tinfo->et_group_start, tinfo->et_group_end,
-                       tinfo->et_inode_count, average_inodes);
+                       _("Scan group range [%d, %d], used inodes %u/%u\n"),
+                       tinfo->et_group_start,
+                       tinfo->et_group_end ? tinfo->et_group_end - 1 : 0,
+                       tinfo->et_inode_count,
+                       (tinfo->et_group_end - tinfo->et_group_start) *
+                               global_fs->super->s_inodes_per_group );
        thread_context->fs = thread_fs;
        retval = quota_init_context(&thread_context->qctx, thread_fs, 0);
        if (retval) {
@@ -3637,13 +3641,15 @@ static void *e2fsck_pass1_thread(void *arg)
        e2fsck_pass1_run(thread_ctx);
 
 out:
-       if (thread_ctx->options & E2F_OPT_MULTITHREAD)
+       if (thread_ctx->options & E2F_OPT_MULTITHREAD) {
+               dgrp_t end = thread_ctx->thread_info.et_group_end;
+
                log_out(thread_ctx,
-                       _("Scanned group range [%u, %u), inodes %u/%u\n"),
-                       thread_ctx->thread_info.et_group_start,
-                       thread_ctx->thread_info.et_group_end,
+                       _("Scanned group range [%u, %u], used inodes %u/%u\n"),
+                       thread_ctx->thread_info.et_group_start, end ? end - 1 : 0,
                        thread_ctx->thread_info.et_inode_count,
                        thread_ctx->thread_info.et_inode_number);
+       }
 
 #ifdef DEBUG_THREADS
        pthread_mutex_lock(&thread_debug->etd_mutex);
@@ -3655,6 +3661,7 @@ out:
        return NULL;
 }
 
+/* return the average number of groups per thread */
 static dgrp_t ext2fs_get_avg_group(ext2_filsys fs)
 {
        dgrp_t average_group = fs->group_desc_count;
@@ -3682,17 +3689,18 @@ out:
        return average_group;
 }
 
+/* return the average number of used inodes to scan per thread */
 static dgrp_t ext2fs_get_avg_inodes(ext2_filsys fs)
 {
-       ext2_ino_t average_inodes = fs->super->s_inodes_count;
+       ext2_ino_t average_inodes = fs->super->s_inodes_count -
+                                   fs->super->s_free_inodes_count;
+
 #ifdef HAVE_PTHREAD
 
        if (fs->fs_num_threads <= 1)
                goto out;
 
-       average_inodes = fs->super->s_inodes_count / fs->fs_num_threads;
-       if (average_inodes <= fs->super->s_inodes_per_group)
-               average_inodes = fs->super->s_inodes_per_group;
+       average_inodes /= fs->fs_num_threads;
 
 out:
 #endif
index e6b6d31..0dca572 100644 (file)
@@ -1,8 +1,8 @@
 ext2fs_open2: Bad magic number in super-block
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 Pass 1: Checking inodes, blocks, and sizes
-[Thread 0] Scan group range [0, 2), inode_count = 11/3008
-[Thread 0] Scanned group range [0, 2), inodes 11/3008
+[Thread 0] Scan group range [0, 1], used inodes 11/3008
+[Thread 0] Scanned group range [0, 1], used inodes 11/3008
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
index e6b6d31..0dca572 100644 (file)
@@ -1,8 +1,8 @@
 ext2fs_open2: Bad magic number in super-block
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 Pass 1: Checking inodes, blocks, and sizes
-[Thread 0] Scan group range [0, 2), inode_count = 11/3008
-[Thread 0] Scanned group range [0, 2), inodes 11/3008
+[Thread 0] Scan group range [0, 1], used inodes 11/3008
+[Thread 0] Scanned group range [0, 1], used inodes 11/3008
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
index 80f337d..69ddaa0 100644 (file)
@@ -1,8 +1,8 @@
 ext2fs_open2: Bad magic number in super-block
 ../e2fsck/e2fsck: Superblock invalid, trying backup blocks...
 Pass 1: Checking inodes, blocks, and sizes
-[Thread 0] Scan group range [0, 2), inode_count = 11/3008
-[Thread 0] Scanned group range [0, 2), inodes 11/3008
+[Thread 0] Scan group range [0, 1], used inodes 11/3008
+[Thread 0] Scanned group range [0, 1], used inodes 11/3008
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts