ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
PATCH 1/1 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.
--- fs/ext4/mballoc.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
fs/ext4/mballoc.c +4 -9
@@ -1958,8 +1958,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,static int mb_find_extent (struct ext4_buddy *e4b,int block,int needed,struct ext4_free_extent *ex) { -int next = block; -int max, order; +int max, order, next;void *buddy;assert_spin_locked (ext4_group_lock_ptr (e4b->bd_sb, e4b->bd_group));
@@ -1977,16 +1976,12 @@ static int mb_find_extent(struct ext4_buddy *e4b, int block,/* find actual order */ order =mb_find_order_for_block (e4b, block); - block = block >> order; - ex->fe_len =1 << order; - ex->fe_start = block << order; + ex->fe_len = (1 << order) - (block & ((1 << order) -1 )); + ex->fe_start = block; ex->fe_group = e4b->bd_group; -/* calc difference from given start */ - next = next - ex->fe_start; - ex->fe_len -= next; - ex->fe_start += next; + block = block >> order;while (needed > ex->fe_len &&mb_find_buddy (e4b, order, &max)) {
Signature · 1 line
2.20.1
Quoted 10 lines · Gou Hao
After first execution of
mb_find_order_for_block():'
fe_start' is the value of 'block' passed inmb_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]>
Ah, nice simplification! Feel free to add:
Honza
Quoted 41 lines
--- fs/ext4/mballoc.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)fs/ext4/mballoc.c +4
-9@@ -1958,8 +1958,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,static int mb_find_extent (struct ext4_buddy *e4b,int block,int needed,struct ext4_free_extent *ex) { -int next = block; -int max, order; +int max, order, next;void *buddy;assert_spin_locked (ext4_group_lock_ptr (e4b->bd_sb, e4b->bd_group));@@ -1977,16 +1976,12 @@ static int mb_find_extent(struct ext4_buddy *e4b, int block,/* find actual order */ order =mb_find_order_for_block (e4b, block); - block = block >> order; - ex->fe_len =1 << order; - ex->fe_start = block << order; + ex->fe_len = (1 << order) - (block & ((1 << order) -1 )); + ex->fe_start = block; ex->fe_group = e4b->bd_group; -/* calc difference from given start */ - next = next - ex->fe_start; - ex->fe_len -= next; - ex->fe_start += next; + block = block >> order;while (needed > ex->fe_len &&mb_find_buddy (e4b, order, &max)) {Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Gou Hao
After first execution of
mb_find_order_for_block():'
fe_start' is the value of 'block' passed inmb_find_extent().'
fe_len' is the difference between the length of order-chunk and remainder of the block divided by order-chunk.[...]
Applied, thanks!
[1/1] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
commit: 2bf5eb2a7c22fc3dd011fda2722fd369b1c4608b
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>