Skip to content

Commit dddcd2f

Browse files
brookxu-cntytso
authored andcommitted
ext4: optimize the implementation of ext4_mb_good_group()
It might be better to adjust the code in two places: 1. Determine whether grp is currupt or not should be placed first. 2. (cr<=2 && free <ac->ac_g_ex.fe_len)should may belong to the crx strategy, and it may be more appropriate to put it in the subsequent switch statement block. For cr1, cr2, the conditions in switch potentially realize the above judgment. For cr0, we should add (free <ac->ac_g_ex.fe_len) judgment, and then delete (free / fragments) >= ac->ac_g_ex.fe_len), because cr0 returns true by default. Signed-off-by: Chunguang Xu <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 051e2ce commit dddcd2f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/ext4/mballoc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,13 +2112,11 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,
21122112

21132113
BUG_ON(cr < 0 || cr >= 4);
21142114

2115-
free = grp->bb_free;
2116-
if (free == 0)
2117-
return false;
2118-
if (cr <= 2 && free < ac->ac_g_ex.fe_len)
2115+
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp)))
21192116
return false;
21202117

2121-
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp)))
2118+
free = grp->bb_free;
2119+
if (free == 0)
21222120
return false;
21232121

21242122
fragments = grp->bb_fragments;
@@ -2135,8 +2133,10 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,
21352133
((group % flex_size) == 0))
21362134
return false;
21372135

2138-
if ((ac->ac_2order > ac->ac_sb->s_blocksize_bits+1) ||
2139-
(free / fragments) >= ac->ac_g_ex.fe_len)
2136+
if (free < ac->ac_g_ex.fe_len)
2137+
return false;
2138+
2139+
if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1)
21402140
return true;
21412141

21422142
if (grp->bb_largest_free_order < ac->ac_2order)

0 commit comments

Comments
 (0)