ext4: open coding repeated check in next_linear_group
authorKemeng Shi <shikemeng@huaweicloud.com>
Wed, 24 Apr 2024 06:19:04 +0000 (14:19 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 3 May 2024 04:12:33 +0000 (00:12 -0400)
Open coding repeated check in next_linear_group.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240424061904.987525-6-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/mballoc.c

index 65ce2dd0cefb73debb98e59d7135c1329c20f4a1..e89c1bfb7ce31fde9dd193a23608a3519b519814 100644 (file)
@@ -1080,23 +1080,11 @@ static inline int should_optimize_scan(struct ext4_allocation_context *ac)
 }
 
 /*
- * Return next linear group for allocation. If linear traversal should not be
- * performed, this function just returns the same group
+ * Return next linear group for allocation.
  */
 static ext4_group_t
-next_linear_group(struct ext4_allocation_context *ac, ext4_group_t group,
-                 ext4_group_t ngroups)
+next_linear_group(ext4_group_t group, ext4_group_t ngroups)
 {
-       if (!should_optimize_scan(ac))
-               goto inc_and_return;
-
-       if (ac->ac_groups_linear_remaining) {
-               ac->ac_groups_linear_remaining--;
-               goto inc_and_return;
-       }
-
-       return group;
-inc_and_return:
        /*
         * Artificially restricted ngroups for non-extent
         * files makes group > ngroups possible on first loop.
@@ -1122,8 +1110,19 @@ static void ext4_mb_choose_next_group(struct ext4_allocation_context *ac,
 {
        *new_cr = ac->ac_criteria;
 
-       if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) {
-               *group = next_linear_group(ac, *group, ngroups);
+       if (!should_optimize_scan(ac)) {
+               *group = next_linear_group(*group, ngroups);
+               return;
+       }
+
+       /*
+        * Optimized scanning can return non adjacent groups which can cause
+        * seek overhead for rotational disks. So try few linear groups before
+        * trying optimized scan.
+        */
+       if (ac->ac_groups_linear_remaining) {
+               *group = next_linear_group(*group, ngroups);
+               ac->ac_groups_linear_remaining--;
                return;
        }