Skip to content

Commit

Permalink
ext4: simplify the code of mb_find_order_for_block
Browse files Browse the repository at this point in the history
The code of mb_find_order_for_block is a bit obscure, but we can
simplify it with mb_find_buddy(), make the code more concise.

Signed-off-by: Chunguang Xu <[email protected]>
Reviewed-by: Andreas Dilger <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
brookxu-tx authored and tytso committed Dec 3, 2020
1 parent 6bd97bf commit ce3cca3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1289,22 +1289,18 @@ static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)

static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
{
int order = 1;
int bb_incr = 1 << (e4b->bd_blkbits - 1);
int order = 1, max;
void *bb;

BUG_ON(e4b->bd_bitmap == e4b->bd_buddy);
BUG_ON(block >= (1 << (e4b->bd_blkbits + 3)));

bb = e4b->bd_buddy;
while (order <= e4b->bd_blkbits + 1) {
block = block >> 1;
if (!mb_test_bit(block, bb)) {
bb = mb_find_buddy(e4b, order, &max);
if (!mb_test_bit(block >> order, bb)) {
/* this block is part of buddy of order 'order' */
return order;
}
bb += bb_incr;
bb_incr >>= 1;
order++;
}
return 0;
Expand Down

0 comments on commit ce3cca3

Please sign in to comment.