Skip to content

Commit da5704e

Browse files
Kemeng Shitytso
authored andcommitted
ext4: open coding repeated check in next_linear_group
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>
1 parent 2caffb6 commit da5704e

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

fs/ext4/mballoc.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,23 +1080,11 @@ static inline int should_optimize_scan(struct ext4_allocation_context *ac)
10801080
}
10811081

10821082
/*
1083-
* Return next linear group for allocation. If linear traversal should not be
1084-
* performed, this function just returns the same group
1083+
* Return next linear group for allocation.
10851084
*/
10861085
static ext4_group_t
1087-
next_linear_group(struct ext4_allocation_context *ac, ext4_group_t group,
1088-
ext4_group_t ngroups)
1086+
next_linear_group(ext4_group_t group, ext4_group_t ngroups)
10891087
{
1090-
if (!should_optimize_scan(ac))
1091-
goto inc_and_return;
1092-
1093-
if (ac->ac_groups_linear_remaining) {
1094-
ac->ac_groups_linear_remaining--;
1095-
goto inc_and_return;
1096-
}
1097-
1098-
return group;
1099-
inc_and_return:
11001088
/*
11011089
* Artificially restricted ngroups for non-extent
11021090
* files makes group > ngroups possible on first loop.
@@ -1122,8 +1110,19 @@ static void ext4_mb_choose_next_group(struct ext4_allocation_context *ac,
11221110
{
11231111
*new_cr = ac->ac_criteria;
11241112

1125-
if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) {
1126-
*group = next_linear_group(ac, *group, ngroups);
1113+
if (!should_optimize_scan(ac)) {
1114+
*group = next_linear_group(*group, ngroups);
1115+
return;
1116+
}
1117+
1118+
/*
1119+
* Optimized scanning can return non adjacent groups which can cause
1120+
* seek overhead for rotational disks. So try few linear groups before
1121+
* trying optimized scan.
1122+
*/
1123+
if (ac->ac_groups_linear_remaining) {
1124+
*group = next_linear_group(*group, ngroups);
1125+
ac->ac_groups_linear_remaining--;
11271126
return;
11281127
}
11291128

0 commit comments

Comments
 (0)