diff mbox series

[1/5] xfs: Remove kmem_zone_alloc() usage

Message ID 20200722090518.214624-2-cmaiolino@redhat.com (mailing list archive)
State Accepted, archived
Headers show
Series Continue xfs kmem cleanup - V3 | expand

Commit Message

Carlos Maiolino July 22, 2020, 9:05 a.m. UTC
Use kmem_cache_alloc() directly.

All kmem_zone_alloc() users pass 0 as flags, which are translated into:
GFP_KERNEL | __GFP_NOWARN, and kmem_zone_alloc() loops forever until the
allocation succeeds.

We can use __GFP_NOFAIL to tell the allocator to loop forever rather
than doing it ourself, and because the allocation will never fail, we do
not need to use __GFP_NOWARN anymore. Hence, all callers can be
converted to use GFP_KERNEL | __GFP_NOFAIL

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---

Changelog:
	V2:
		- Wire up xfs_inode_alloc to use __GFP_NOFAIL
		  if it's called inside a transaction
		- Rewrite changelog in a more decent way.
	V3:
		- Use __GFP_NOFAIL unconditionally in xfs_inode_alloc(),
		  use of PF_FSTRANS will be added when the patch re-adding
		  it is moved to mainline.

 fs/xfs/libxfs/xfs_alloc.c |  3 ++-
 fs/xfs/libxfs/xfs_bmap.c  |  3 ++-
 fs/xfs/xfs_icache.c       | 10 ++--------
 3 files changed, 6 insertions(+), 10 deletions(-)

Comments

Christoph Hellwig July 22, 2020, 2:13 p.m. UTC | #1
On Wed, Jul 22, 2020 at 11:05:14AM +0200, Carlos Maiolino wrote:
> -	/*
> -	 * if this didn't occur in transactions, we could use
> -	 * KM_MAYFAIL and return NULL here on ENOMEM. Set the
> -	 * code up to do this anyway.
> -	 */
> -	ip = kmem_zone_alloc(xfs_inode_zone, 0);
> -	if (!ip)
> -		return NULL;
> +	ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL);
> +

I would have kept a version of this comment.  But if this on your
radar for the next merge window anyway this should be ok:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Carlos Maiolino July 23, 2020, 9:02 a.m. UTC | #2
On Wed, Jul 22, 2020 at 03:13:46PM +0100, Christoph Hellwig wrote:
> On Wed, Jul 22, 2020 at 11:05:14AM +0200, Carlos Maiolino wrote:
> > -	/*
> > -	 * if this didn't occur in transactions, we could use
> > -	 * KM_MAYFAIL and return NULL here on ENOMEM. Set the
> > -	 * code up to do this anyway.
> > -	 */
> > -	ip = kmem_zone_alloc(xfs_inode_zone, 0);
> > -	if (!ip)
> > -		return NULL;
> > +	ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL);
> > +
> 
> I would have kept a version of this comment.  But if this on your
> radar for the next merge window anyway this should be ok:

I thought it makes no sense to keep the comment, and yes, I'll keep an eye on it
and rework this as soon as we have PF_FSTRANS back.

Thanks for the review.

> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
Dave Chinner July 24, 2020, 1:40 a.m. UTC | #3
On Wed, Jul 22, 2020 at 11:05:14AM +0200, Carlos Maiolino wrote:
> Use kmem_cache_alloc() directly.
> 
> All kmem_zone_alloc() users pass 0 as flags, which are translated into:
> GFP_KERNEL | __GFP_NOWARN, and kmem_zone_alloc() loops forever until the
> allocation succeeds.
> 
> We can use __GFP_NOFAIL to tell the allocator to loop forever rather
> than doing it ourself, and because the allocation will never fail, we do
> not need to use __GFP_NOWARN anymore. Hence, all callers can be
> converted to use GFP_KERNEL | __GFP_NOFAIL
> 
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
> 
> Changelog:
> 	V2:
> 		- Wire up xfs_inode_alloc to use __GFP_NOFAIL
> 		  if it's called inside a transaction
> 		- Rewrite changelog in a more decent way.
> 	V3:
> 		- Use __GFP_NOFAIL unconditionally in xfs_inode_alloc(),
> 		  use of PF_FSTRANS will be added when the patch re-adding
> 		  it is moved to mainline.
> 
>  fs/xfs/libxfs/xfs_alloc.c |  3 ++-
>  fs/xfs/libxfs/xfs_bmap.c  |  3 ++-
>  fs/xfs/xfs_icache.c       | 10 ++--------
>  3 files changed, 6 insertions(+), 10 deletions(-)

Looks fine with or without the comment as christoph noted.

Reviewed-by: Dave Chinner <dchinner@redhat.com>
Darrick J. Wong July 24, 2020, 5:36 a.m. UTC | #4
On Wed, Jul 22, 2020 at 11:05:14AM +0200, Carlos Maiolino wrote:
> Use kmem_cache_alloc() directly.
> 
> All kmem_zone_alloc() users pass 0 as flags, which are translated into:
> GFP_KERNEL | __GFP_NOWARN, and kmem_zone_alloc() loops forever until the
> allocation succeeds.
> 
> We can use __GFP_NOFAIL to tell the allocator to loop forever rather
> than doing it ourself, and because the allocation will never fail, we do
> not need to use __GFP_NOWARN anymore. Hence, all callers can be
> converted to use GFP_KERNEL | __GFP_NOFAIL
> 
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>

Looks ok to me too (I put the comment back in),
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
> 
> Changelog:
> 	V2:
> 		- Wire up xfs_inode_alloc to use __GFP_NOFAIL
> 		  if it's called inside a transaction
> 		- Rewrite changelog in a more decent way.
> 	V3:
> 		- Use __GFP_NOFAIL unconditionally in xfs_inode_alloc(),
> 		  use of PF_FSTRANS will be added when the patch re-adding
> 		  it is moved to mainline.
> 
>  fs/xfs/libxfs/xfs_alloc.c |  3 ++-
>  fs/xfs/libxfs/xfs_bmap.c  |  3 ++-
>  fs/xfs/xfs_icache.c       | 10 ++--------
>  3 files changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
> index 203e74fa64aa6..583242253c027 100644
> --- a/fs/xfs/libxfs/xfs_alloc.c
> +++ b/fs/xfs/libxfs/xfs_alloc.c
> @@ -2467,7 +2467,8 @@ xfs_defer_agfl_block(
>  	ASSERT(xfs_bmap_free_item_zone != NULL);
>  	ASSERT(oinfo != NULL);
>  
> -	new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
> +	new = kmem_cache_alloc(xfs_bmap_free_item_zone,
> +			       GFP_KERNEL | __GFP_NOFAIL);
>  	new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
>  	new->xefi_blockcount = 1;
>  	new->xefi_oinfo = *oinfo;
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index 667cdd0dfdf4a..fd5c0d669d0d7 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -553,7 +553,8 @@ __xfs_bmap_add_free(
>  #endif
>  	ASSERT(xfs_bmap_free_item_zone != NULL);
>  
> -	new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
> +	new = kmem_cache_alloc(xfs_bmap_free_item_zone,
> +			       GFP_KERNEL | __GFP_NOFAIL);
>  	new->xefi_startblock = bno;
>  	new->xefi_blockcount = (xfs_extlen_t)len;
>  	if (oinfo)
> diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
> index 58a750ce689c0..c2d97e4f131fb 100644
> --- a/fs/xfs/xfs_icache.c
> +++ b/fs/xfs/xfs_icache.c
> @@ -36,14 +36,8 @@ xfs_inode_alloc(
>  {
>  	struct xfs_inode	*ip;
>  
> -	/*
> -	 * if this didn't occur in transactions, we could use
> -	 * KM_MAYFAIL and return NULL here on ENOMEM. Set the
> -	 * code up to do this anyway.
> -	 */
> -	ip = kmem_zone_alloc(xfs_inode_zone, 0);
> -	if (!ip)
> -		return NULL;
> +	ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL);
> +
>  	if (inode_init_always(mp->m_super, VFS_I(ip))) {
>  		kmem_cache_free(xfs_inode_zone, ip);
>  		return NULL;
> -- 
> 2.26.2
>
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 203e74fa64aa6..583242253c027 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -2467,7 +2467,8 @@  xfs_defer_agfl_block(
 	ASSERT(xfs_bmap_free_item_zone != NULL);
 	ASSERT(oinfo != NULL);
 
-	new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
+	new = kmem_cache_alloc(xfs_bmap_free_item_zone,
+			       GFP_KERNEL | __GFP_NOFAIL);
 	new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
 	new->xefi_blockcount = 1;
 	new->xefi_oinfo = *oinfo;
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 667cdd0dfdf4a..fd5c0d669d0d7 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -553,7 +553,8 @@  __xfs_bmap_add_free(
 #endif
 	ASSERT(xfs_bmap_free_item_zone != NULL);
 
-	new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
+	new = kmem_cache_alloc(xfs_bmap_free_item_zone,
+			       GFP_KERNEL | __GFP_NOFAIL);
 	new->xefi_startblock = bno;
 	new->xefi_blockcount = (xfs_extlen_t)len;
 	if (oinfo)
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 58a750ce689c0..c2d97e4f131fb 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -36,14 +36,8 @@  xfs_inode_alloc(
 {
 	struct xfs_inode	*ip;
 
-	/*
-	 * if this didn't occur in transactions, we could use
-	 * KM_MAYFAIL and return NULL here on ENOMEM. Set the
-	 * code up to do this anyway.
-	 */
-	ip = kmem_zone_alloc(xfs_inode_zone, 0);
-	if (!ip)
-		return NULL;
+	ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL);
+
 	if (inode_init_always(mp->m_super, VFS_I(ip))) {
 		kmem_cache_free(xfs_inode_zone, ip);
 		return NULL;