Skip to content

Commit 2bf5eb2

Browse files
Gou Haotytso
authored andcommitted
ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
After first execution of mb_find_order_for_block(): 'fe_start' is the value of 'block' passed in mb_find_extent(). 'fe_len' is the difference between the length of order-chunk and remainder of the block divided by order-chunk. And 'next' does not require initialization after above modifications. Signed-off-by: Gou Hao <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent c6bfd72 commit 2bf5eb2

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

fs/ext4/mballoc.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
19571957
static int mb_find_extent(struct ext4_buddy *e4b, int block,
19581958
int needed, struct ext4_free_extent *ex)
19591959
{
1960-
int next = block;
1961-
int max, order;
1960+
int max, order, next;
19621961
void *buddy;
19631962

19641963
assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
@@ -1976,16 +1975,12 @@ static int mb_find_extent(struct ext4_buddy *e4b, int block,
19761975

19771976
/* find actual order */
19781977
order = mb_find_order_for_block(e4b, block);
1979-
block = block >> order;
19801978

1981-
ex->fe_len = 1 << order;
1982-
ex->fe_start = block << order;
1979+
ex->fe_len = (1 << order) - (block & ((1 << order) - 1));
1980+
ex->fe_start = block;
19831981
ex->fe_group = e4b->bd_group;
19841982

1985-
/* calc difference from given start */
1986-
next = next - ex->fe_start;
1987-
ex->fe_len -= next;
1988-
ex->fe_start += next;
1983+
block = block >> order;
19891984

19901985
while (needed > ex->fe_len &&
19911986
mb_find_buddy(e4b, order, &max)) {

0 commit comments

Comments
 (0)