diff mbox series

ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock()

Message ID 20231023013416.17246-1-gouhao@uniontech.com
State Superseded
Headers show
Series ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock() | expand

Commit Message

Gou Hao Oct. 23, 2023, 1:34 a.m. UTC
'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)',
'pnum' and 'block' is equal in this case.

Signed-off-by: Gou Hao <gouhao@uniontech.com>
Signed-off-by: Gou Hao <gouhaojake@163.com>
---
 fs/ext4/mballoc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Jan Kara Oct. 23, 2023, 11:44 a.m. UTC | #1
On Mon 23-10-23 09:34:16, Gou Hao wrote:
> 'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)',
> 'pnum' and 'block' is equal in this case.
> 
> Signed-off-by: Gou Hao <gouhao@uniontech.com>
> Signed-off-by: Gou Hao <gouhaojake@163.com>

No need for two signed-off-by here. Any one from you is enough :)

> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 454d5612641e..8442f5474b25 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -1456,9 +1456,7 @@ static int ext4_mb_get_buddy_page_lock(struct super_block *sb,
>  		return 0;
>  	}
>  
> -	block++;
> -	pnum = block / blocks_per_page;
> -	page = find_or_create_page(inode->i_mapping, pnum, gfp);
> +	page = find_or_create_page(inode->i_mapping, ++block, gfp);
						     ^^^ perhaps just
"block + 1" here? Maybe also add a comment before this call like:

	/* blocks_per_page == 1, hence we need another page for the buddy */

Otherwise the patch looks good!

								Honza
Gou Hao Oct. 24, 2023, 2:35 a.m. UTC | #2
On 10/23/23 19:44, Jan Kara wrote:

> On Mon 23-10-23 09:34:16, Gou Hao wrote:
>> 'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)',
>> 'pnum' and 'block' is equal in this case.
>>
>> Signed-off-by: Gou Hao <gouhao@uniontech.com>
>> Signed-off-by: Gou Hao <gouhaojake@163.com>
> No need for two signed-off-by here. Any one from you is enough :)
ok
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index 454d5612641e..8442f5474b25 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -1456,9 +1456,7 @@ static int ext4_mb_get_buddy_page_lock(struct super_block *sb,
>>   		return 0;
>>   	}
>>   
>> -	block++;
>> -	pnum = block / blocks_per_page;
>> -	page = find_or_create_page(inode->i_mapping, pnum, gfp);
>> +	page = find_or_create_page(inode->i_mapping, ++block, gfp);
> 						     ^^^ perhaps just
> "block + 1" here? Maybe also add a comment before this call like:

Yes, 'block +1' is better here, i will add a comment.

Thanks for your review.

> 	/* blocks_per_page == 1, hence we need another page for the buddy */
>
> Otherwise the patch looks good!
>
> 								Honza
>
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 454d5612641e..8442f5474b25 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1456,9 +1456,7 @@  static int ext4_mb_get_buddy_page_lock(struct super_block *sb,
 		return 0;
 	}
 
-	block++;
-	pnum = block / blocks_per_page;
-	page = find_or_create_page(inode->i_mapping, pnum, gfp);
+	page = find_or_create_page(inode->i_mapping, ++block, gfp);
 	if (!page)
 		return -ENOMEM;
 	BUG_ON(page->mapping != inode->i_mapping);