All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/buffer.c: Optimize grow_buffer function.
@ 2018-07-21 17:30 Sean Fu
  2018-07-21 18:21 ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Fu @ 2018-07-21 17:30 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, linux-kernel, Sean Fu

Use PAGE_SHIFT and i_blkbits of bd_inode directly to avoid ugly sizebits
calculation.
Remove ugly sizebits calculation.
Remove unnecessary sizebits parameter of grow_dev_page.

Reduces code size:

Before:

sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/buffer.o
   text	   data	    bss	    dec	    hex	filename
  34037	   1510	     16	  35563	   8aeb	fs/buffer.o

After:

sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/buffer.o
   text	   data	    bss	    dec	    hex	filename
  34021	   1510	     16	  35547	   8adb	fs/buffer.o

Signed-off-by: Sean Fu <fxinrong@gmail.com>
---
 fs/buffer.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 249b83f..143ad78 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -918,7 +918,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
  */
 static int
 grow_dev_page(struct block_device *bdev, sector_t block,
-	      pgoff_t index, int size, int sizebits, gfp_t gfp)
+	      pgoff_t index, int size, gfp_t gfp)
 {
 	struct inode *inode = bdev->bd_inode;
 	struct page *page;
@@ -945,7 +945,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
 		bh = page_buffers(page);
 		if (bh->b_size == size) {
 			end_block = init_page_buffers(page, bdev,
-						(sector_t)index << sizebits,
+						(sector_t)index << (PAGE_SHIFT - inode->i_blkbits),
 						size);
 			goto done;
 		}
@@ -965,7 +965,8 @@ grow_dev_page(struct block_device *bdev, sector_t block,
 	 */
 	spin_lock(&inode->i_mapping->private_lock);
 	link_dev_buffers(page, bh);
-	end_block = init_page_buffers(page, bdev, (sector_t)index << sizebits,
+	end_block = init_page_buffers(page, bdev,
+			(sector_t)index << (PAGE_SHIFT - inode->i_blkbits),
 			size);
 	spin_unlock(&inode->i_mapping->private_lock);
 done:
@@ -984,20 +985,13 @@ static int
 grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp)
 {
 	pgoff_t index;
-	int sizebits;
-
-	sizebits = -1;
-	do {
-		sizebits++;
-	} while ((size << sizebits) < PAGE_SIZE);
-
-	index = block >> sizebits;
+	index = block >> (PAGE_SHIFT - bdev->bd_inode->i_blkbits);
 
 	/*
 	 * Check for a block which wants to lie outside our maximum possible
 	 * pagecache index.  (this comparison is done using sector_t types).
 	 */
-	if (unlikely(index != block >> sizebits)) {
+	if (unlikely(index != block >> (PAGE_SHIFT - bdev->bd_inode->i_blkbits))) {
 		printk(KERN_ERR "%s: requested out-of-range block %llu for "
 			"device %pg\n",
 			__func__, (unsigned long long)block,
@@ -1006,7 +1000,7 @@ grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp)
 	}
 
 	/* Create a page with the proper size buffers.. */
-	return grow_dev_page(bdev, block, index, size, sizebits, gfp);
+	return grow_dev_page(bdev, block, index, size, gfp);
 }
 
 static struct buffer_head *
-- 
2.6.2

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

end of thread, other threads:[~2018-08-08  9:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-21 17:30 [PATCH] fs/buffer.c: Optimize grow_buffer function Sean Fu
2018-07-21 18:21 ` Al Viro
2018-07-24  9:42   ` Sean Fu
2018-08-08  6:52   ` Sean Fu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.