diff mbox series

[2/5] xfs: remove xfs_buf_get_maps

Message ID 20250317054850.1132557-3-hch@lst.de (mailing list archive)
State Queued
Headers show
Series [1/5] xfs: call xfs_buf_alloc_backing_mem from _xfs_buf_alloc | expand

Commit Message

hch March 17, 2025, 5:48 a.m. UTC
xfs_buf_get_maps has a single caller, and can just be open coded there.
When doing that, stop handling the allocation failure as we always pass
__GFP_NOFAIL to the slab allocator, and use the proper kcalloc helper for
array allocations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_buf.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

Comments

Carlos Maiolino March 18, 2025, 12:35 p.m. UTC | #1
On Mon, Mar 17, 2025 at 06:48:33AM +0100, Christoph Hellwig wrote:
> xfs_buf_get_maps has a single caller, and can just be open coded there.
> When doing that, stop handling the allocation failure as we always pass
> __GFP_NOFAIL to the slab allocator, and use the proper kcalloc helper for
> array allocations.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/xfs_buf.c | 33 ++++++---------------------------
>  1 file changed, 6 insertions(+), 27 deletions(-)
> 


Looks good.
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index f42f6e47f783..878dc0f108d1 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -88,26 +88,6 @@ xfs_buf_stale(
>  	spin_unlock(&bp->b_lock);
>  }
> 
> -static int
> -xfs_buf_get_maps(
> -	struct xfs_buf		*bp,
> -	int			map_count)
> -{
> -	ASSERT(bp->b_maps == NULL);
> -	bp->b_map_count = map_count;
> -
> -	if (map_count == 1) {
> -		bp->b_maps = &bp->__b_map;
> -		return 0;
> -	}
> -
> -	bp->b_maps = kzalloc(map_count * sizeof(struct xfs_buf_map),
> -			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
> -	if (!bp->b_maps)
> -		return -ENOMEM;
> -	return 0;
> -}
> -
>  static void
>  xfs_buf_free_maps(
>  	struct xfs_buf	*bp)
> @@ -317,15 +297,14 @@ xfs_buf_alloc(
>  	bp->b_target = target;
>  	bp->b_mount = target->bt_mount;
>  	bp->b_flags = flags;
> -
> -	error = xfs_buf_get_maps(bp, nmaps);
> -	if (error)  {
> -		kmem_cache_free(xfs_buf_cache, bp);
> -		return error;
> -	}
> -
>  	bp->b_rhash_key = map[0].bm_bn;
>  	bp->b_length = 0;
> +	bp->b_map_count = nmaps;
> +	if (nmaps == 1)
> +		bp->b_maps = &bp->__b_map;
> +	else
> +		bp->b_maps = kcalloc(nmaps, sizeof(struct xfs_buf_map),
> +				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
>  	for (i = 0; i < nmaps; i++) {
>  		bp->b_maps[i].bm_bn = map[i].bm_bn;
>  		bp->b_maps[i].bm_len = map[i].bm_len;
> --
> 2.45.2
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index f42f6e47f783..878dc0f108d1 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -88,26 +88,6 @@  xfs_buf_stale(
 	spin_unlock(&bp->b_lock);
 }
 
-static int
-xfs_buf_get_maps(
-	struct xfs_buf		*bp,
-	int			map_count)
-{
-	ASSERT(bp->b_maps == NULL);
-	bp->b_map_count = map_count;
-
-	if (map_count == 1) {
-		bp->b_maps = &bp->__b_map;
-		return 0;
-	}
-
-	bp->b_maps = kzalloc(map_count * sizeof(struct xfs_buf_map),
-			GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
-	if (!bp->b_maps)
-		return -ENOMEM;
-	return 0;
-}
-
 static void
 xfs_buf_free_maps(
 	struct xfs_buf	*bp)
@@ -317,15 +297,14 @@  xfs_buf_alloc(
 	bp->b_target = target;
 	bp->b_mount = target->bt_mount;
 	bp->b_flags = flags;
-
-	error = xfs_buf_get_maps(bp, nmaps);
-	if (error)  {
-		kmem_cache_free(xfs_buf_cache, bp);
-		return error;
-	}
-
 	bp->b_rhash_key = map[0].bm_bn;
 	bp->b_length = 0;
+	bp->b_map_count = nmaps;
+	if (nmaps == 1)
+		bp->b_maps = &bp->__b_map;
+	else
+		bp->b_maps = kcalloc(nmaps, sizeof(struct xfs_buf_map),
+				GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
 	for (i = 0; i < nmaps; i++) {
 		bp->b_maps[i].bm_bn = map[i].bm_bn;
 		bp->b_maps[i].bm_len = map[i].bm_len;