Skip to content

Commit

Permalink
ext4: optimize the implementation of ext4_mb_good_group()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
brookxu-cn authored and tytso committed Aug 18, 2020
1 parent 051e2ce commit dddcd2f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,13 +2112,11 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,

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

free = grp->bb_free;
if (free == 0)
return false;
if (cr <= 2 && free < ac->ac_g_ex.fe_len)
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp)))
return false;

if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp)))
free = grp->bb_free;
if (free == 0)
return false;

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

if ((ac->ac_2order > ac->ac_sb->s_blocksize_bits+1) ||
(free / fragments) >= ac->ac_g_ex.fe_len)
if (free < ac->ac_g_ex.fe_len)
return false;

if (ac->ac_2order > ac->ac_sb->s_blocksize_bits+1)
return true;

if (grp->bb_largest_free_order < ac->ac_2order)
Expand Down

0 comments on commit dddcd2f

Please sign in to comment.