public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
@ 2023-11-13  8:26 Gou Hao
  2023-11-30 12:36 ` Jan Kara
  2024-01-09  2:53 ` Theodore Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Gou Hao @ 2023-11-13  8:26 UTC (permalink / raw)
  To: tytso, adilger.kernel, jack, alex, linux-ext4; +Cc: linux-kernel, gouhaojake

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 <gouhao@uniontech.com>
---
 fs/ext4/mballoc.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 454d5612641e..d3f985f7cab8 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -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)) {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
  2023-11-13  8:26 [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent() Gou Hao
@ 2023-11-30 12:36 ` Jan Kara
  2024-01-09  2:53 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2023-11-30 12:36 UTC (permalink / raw)
  To: Gou Hao
  Cc: tytso, adilger.kernel, jack, alex, linux-ext4, linux-kernel,
	gouhaojake

On Mon 13-11-23 16:26:17, Gou Hao wrote:
> 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 <gouhao@uniontech.com>

Ah, nice simplification! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/mballoc.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 454d5612641e..d3f985f7cab8 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -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)) {
> -- 
> 2.20.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
  2023-11-13  8:26 [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent() Gou Hao
  2023-11-30 12:36 ` Jan Kara
@ 2024-01-09  2:53 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2024-01-09  2:53 UTC (permalink / raw)
  To: adilger.kernel, jack, alex, linux-ext4, Gou Hao
  Cc: Theodore Ts'o, linux-kernel, gouhaojake


On Mon, 13 Nov 2023 16:26:17 +0800, Gou Hao wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent()
      commit: 2bf5eb2a7c22fc3dd011fda2722fd369b1c4608b

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-09  2:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-13  8:26 [PATCH] ext4: improving calculation of 'fe_{len|start}' in mb_find_extent() Gou Hao
2023-11-30 12:36 ` Jan Kara
2024-01-09  2:53 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox