Skip to contentSkip to conversation

ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock()

PATCH Superseded Gou Hao 3 participants 5 messages Oct 23, 2023 – Jan 9, 2024 ext4 file system

lore
Share & tools
lore

Gou Hao

author
#0 lore raw

PATCH 1/1 ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock()

'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)', 'pnum' and 'block' is equal in this case.

---
 fs/ext4/mballoc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/ext4/mballoc.c +1 -3
index 454d5612641e..8442f5474b25 100644
@@ -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);
Signature · 1 line
2.34.1
reviewer
#1 lore raw
Quoted 5 lines · Gou Hao

'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)', 'pnum' and 'block' is equal in this case.

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

fs/ext4/mballoc.c static int ext4_mb_get_buddy_page_lock(struct super_block *sb, · line 1459

Quoted 12 lines
fs/ext4/mballoc.c +1 -3
index 454d5612641e..8442f5474b25 100644
@@ -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

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#2 lore raw
Quoted 7 lines · Jan Kara
Quoted 5 lines · Gou Hao

'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)', 'pnum' and 'block' is equal in this case.

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

ok

Quoted 8 lines
Quoted 8 lines
fs/ext4/mballoc.c +0 -0
index 454d5612641e..8442f5474b25 100644
@@ -1456,9 +1456,7 @@ static int ext4_mb_get_buddy_page_lock(struct super_block *sb,
  		return 0;
  	}
 
Quoted 6 lines

fs/ext4/mballoc.c static int ext4_mb_get_buddy_page_lock(struct super_block *sb, · line 1459

Quoted 4 lines
fs/ext4/mballoc.c +1 -3
-	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.

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

Otherwise the patch looks good!

Honza

Signature · 2 lines
thanks,
Gou Hao <[email protected]>
author
#3 lore raw

PATCH v2 1/1 ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock()

In reply to Gou Hao

'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)', 'pnum' and 'block' are equal in this case.

---
 fs/ext4/mballoc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/ext4/mballoc.c +2 -3
index 454d5612641e..c340d4d7287a 100644
@@ -1456,9 +1456,8 @@ 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);
+	/* blocks_per_page == 1, hence we need another page for the buddy */
+	page = find_or_create_page(inode->i_mapping, block + 1, gfp);
 	if (!page)
 		return -ENOMEM;
 	BUG_ON(page->mapping != inode->i_mapping);
Signature · 1 line
2.20.1
maintainer Applied
#4 lore raw
Quoted 4 lines · Gou Hao

'blocks_per_page' is always 1 after 'if (blocks_per_page >= 2)', 'pnum' and 'block' are equal in this case.

Applied, thanks!

[1/1] ext4: delete redundant calculations in ext4_mb_get_buddy_page_lock()

      commit: f2fec3e99a32d7c14dbf63c824f8286ebc94b18d

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>