Skip to content

Commit 1f6bc02

Browse files
OjaswinMtytso
authored andcommitted
ext4: fallback to complex scan if aligned scan doesn't work
Currently in case the goal length is a multiple of stripe size we use ext4_mb_scan_aligned() to find the stripe size aligned physical blocks. In case we are not able to find any, we again go back to calling ext4_mb_choose_next_group() to search for a different suitable block group. However, since the linear search always begins from the start, most of the times we end up with the same BG and the cycle continues. With large fliesystems, the CPU can be stuck in this loop for hours which can slow down the whole system. Hence, until we figure out a better way to continue the search (rather than starting from beginning) in ext4_mb_choose_next_group(), lets just fallback to ext4_mb_complex_scan_group() in case aligned scan fails, as it is much more likely to find the needed blocks. Signed-off-by: Ojaswin Mujoo <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/ee033f6dfa0a7f2934437008a909c3788233950f.1702455010.git.ojaswin@linux.ibm.com Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 4d5cdd7 commit 1f6bc02

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/ext4/mballoc.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,14 +2889,19 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
28892889
ac->ac_groups_scanned++;
28902890
if (cr == CR_POWER2_ALIGNED)
28912891
ext4_mb_simple_scan_group(ac, &e4b);
2892-
else if ((cr == CR_GOAL_LEN_FAST ||
2893-
cr == CR_BEST_AVAIL_LEN) &&
2894-
sbi->s_stripe &&
2895-
!(ac->ac_g_ex.fe_len %
2896-
EXT4_B2C(sbi, sbi->s_stripe)))
2897-
ext4_mb_scan_aligned(ac, &e4b);
2898-
else
2899-
ext4_mb_complex_scan_group(ac, &e4b);
2892+
else {
2893+
bool is_stripe_aligned = sbi->s_stripe &&
2894+
!(ac->ac_g_ex.fe_len %
2895+
EXT4_B2C(sbi, sbi->s_stripe));
2896+
2897+
if ((cr == CR_GOAL_LEN_FAST ||
2898+
cr == CR_BEST_AVAIL_LEN) &&
2899+
is_stripe_aligned)
2900+
ext4_mb_scan_aligned(ac, &e4b);
2901+
2902+
if (ac->ac_status == AC_STATUS_CONTINUE)
2903+
ext4_mb_complex_scan_group(ac, &e4b);
2904+
}
29002905

29012906
ext4_unlock_group(sb, group);
29022907
ext4_mb_unload_buddy(&e4b);

0 commit comments

Comments
 (0)