Skip to content

Commit 45704f9

Browse files
LiBaokun96tytso
authored andcommitted
ext4: factor out __ext4_mb_scan_group()
Extract __ext4_mb_scan_group() to make the code clearer and to prepare for the later conversion of 'choose group' to 'scan groups'. No functional changes. Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Zhang Yi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 7d345aa commit 45704f9

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

fs/ext4/mballoc.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,30 @@ void ext4_mb_scan_aligned(struct ext4_allocation_context *ac,
25682568
}
25692569
}
25702570

2571+
static void __ext4_mb_scan_group(struct ext4_allocation_context *ac)
2572+
{
2573+
bool is_stripe_aligned;
2574+
struct ext4_sb_info *sbi;
2575+
enum criteria cr = ac->ac_criteria;
2576+
2577+
ac->ac_groups_scanned++;
2578+
if (cr == CR_POWER2_ALIGNED)
2579+
return ext4_mb_simple_scan_group(ac, ac->ac_e4b);
2580+
2581+
sbi = EXT4_SB(ac->ac_sb);
2582+
is_stripe_aligned = false;
2583+
if ((sbi->s_stripe >= sbi->s_cluster_ratio) &&
2584+
!(ac->ac_g_ex.fe_len % EXT4_NUM_B2C(sbi, sbi->s_stripe)))
2585+
is_stripe_aligned = true;
2586+
2587+
if ((cr == CR_GOAL_LEN_FAST || cr == CR_BEST_AVAIL_LEN) &&
2588+
is_stripe_aligned)
2589+
ext4_mb_scan_aligned(ac, ac->ac_e4b);
2590+
2591+
if (ac->ac_status == AC_STATUS_CONTINUE)
2592+
ext4_mb_complex_scan_group(ac, ac->ac_e4b);
2593+
}
2594+
25712595
/*
25722596
* This is also called BEFORE we load the buddy bitmap.
25732597
* Returns either 1 or 0 indicating that the group is either suitable
@@ -2855,6 +2879,8 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
28552879
*/
28562880
if (ac->ac_2order)
28572881
cr = CR_POWER2_ALIGNED;
2882+
2883+
ac->ac_e4b = &e4b;
28582884
repeat:
28592885
for (; cr < EXT4_MB_NUM_CRS && ac->ac_status == AC_STATUS_CONTINUE; cr++) {
28602886
ac->ac_criteria = cr;
@@ -2932,24 +2958,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
29322958
continue;
29332959
}
29342960

2935-
ac->ac_groups_scanned++;
2936-
if (cr == CR_POWER2_ALIGNED)
2937-
ext4_mb_simple_scan_group(ac, &e4b);
2938-
else {
2939-
bool is_stripe_aligned =
2940-
(sbi->s_stripe >=
2941-
sbi->s_cluster_ratio) &&
2942-
!(ac->ac_g_ex.fe_len %
2943-
EXT4_NUM_B2C(sbi, sbi->s_stripe));
2944-
2945-
if ((cr == CR_GOAL_LEN_FAST ||
2946-
cr == CR_BEST_AVAIL_LEN) &&
2947-
is_stripe_aligned)
2948-
ext4_mb_scan_aligned(ac, &e4b);
2949-
2950-
if (ac->ac_status == AC_STATUS_CONTINUE)
2951-
ext4_mb_complex_scan_group(ac, &e4b);
2952-
}
2961+
__ext4_mb_scan_group(ac);
29532962

29542963
ext4_unlock_group(sb, group);
29552964
ext4_mb_unload_buddy(&e4b);

fs/ext4/mballoc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ struct ext4_allocation_context {
204204
__u8 ac_2order; /* if request is to allocate 2^N blocks and
205205
* N > 0, the field stores N, otherwise 0 */
206206
__u8 ac_op; /* operation, for history only */
207+
208+
struct ext4_buddy *ac_e4b;
207209
struct folio *ac_bitmap_folio;
208210
struct folio *ac_buddy_folio;
209211
struct ext4_prealloc_space *ac_pa;

0 commit comments

Comments
 (0)