[PATCH 2/4] fs/buffer: avoid redundant lookup in getblk slowpath

Davidlohr Bueso posted 4 patches 7 months, 1 week ago
[PATCH 2/4] fs/buffer: avoid redundant lookup in getblk slowpath
Posted by Davidlohr Bueso 7 months, 1 week ago
__getblk_slow() already implies failing a first lookup
as the fastpath, so try to create the buffers immediately
and avoid the redundant lookup. This saves 5-10% of the
total cost/latency of the slowpath.

Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 fs/buffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 5a4342881f3b..b02cced96529 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1139,15 +1139,15 @@ __getblk_slow(struct block_device *bdev, sector_t block,
 	for (;;) {
 		struct buffer_head *bh;
 
+		if (!grow_buffers(bdev, block, size, gfp))
+			return NULL;
+
 		if (blocking)
 			bh = __find_get_block_nonatomic(bdev, block, size);
 		else
 			bh = __find_get_block(bdev, block, size);
 		if (bh)
 			return bh;
-
-		if (!grow_buffers(bdev, block, size, gfp))
-			return NULL;
 	}
 }
 
-- 
2.39.5
Re: [PATCH 2/4] fs/buffer: avoid redundant lookup in getblk slowpath
Posted by Jan Kara 7 months, 1 week ago
On Thu 15-05-25 10:39:23, Davidlohr Bueso wrote:
> __getblk_slow() already implies failing a first lookup
> as the fastpath, so try to create the buffers immediately
> and avoid the redundant lookup. This saves 5-10% of the
> total cost/latency of the slowpath.
> 
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>

Makes sense. Feel free to add:

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

								Honza

> ---
>  fs/buffer.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/buffer.c b/fs/buffer.c
> index 5a4342881f3b..b02cced96529 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -1139,15 +1139,15 @@ __getblk_slow(struct block_device *bdev, sector_t block,
>  	for (;;) {
>  		struct buffer_head *bh;
>  
> +		if (!grow_buffers(bdev, block, size, gfp))
> +			return NULL;
> +
>  		if (blocking)
>  			bh = __find_get_block_nonatomic(bdev, block, size);
>  		else
>  			bh = __find_get_block(bdev, block, size);
>  		if (bh)
>  			return bh;
> -
> -		if (!grow_buffers(bdev, block, size, gfp))
> -			return NULL;
>  	}
>  }
>  
> -- 
> 2.39.5
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR