All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Carlos Maiolino <cmaiolino@redhat.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/4] xfs: Remove kmem_zone_alloc() usage
Date: Thu, 9 Jul 2020 12:45:06 +1000	[thread overview]
Message-ID: <20200709024506.GS2005@dread.disaster.area> (raw)
In-Reply-To: <20200708125608.155645-2-cmaiolino@redhat.com>

On Wed, Jul 08, 2020 at 02:56:05PM +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.
> 
> So, call kmem_cache_alloc() with __GFP_NOFAIL directly. which will have
> the same result.
> 
> Once allocation will never fail, don't bother to add __GFP_NOWARN.

Last two paragraphs are a little odd. Maybe:

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>
> ---
>  fs/xfs/libxfs/xfs_alloc.c |  3 ++-
>  fs/xfs/libxfs/xfs_bmap.c  |  3 ++-
>  fs/xfs/xfs_icache.c       | 11 +++--------
>  3 files changed, 7 insertions(+), 10 deletions(-)
> 
> @@ -36,14 +36,9 @@ 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);
> +

Hmmmm. We really should check PF_FSTRANS here for the flags we
should be setting. Something like:

	gfp_t		gfp_mask = GFP_KERNEL;

	if (current->flags & PF_FSTRANS)
		gfp_mask |= __GFP_NOFAIL;

	ip = kmem_cache_alloc(xfs_inode_zone, gfp_mask);
	if (!ip)
		return NULL;

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2020-07-09  2:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08 12:56 [PATCH 0/4] Continue xfs kmem cleanup Carlos Maiolino
2020-07-08 12:56 ` [PATCH 1/4] xfs: Remove kmem_zone_alloc() usage Carlos Maiolino
2020-07-09  2:45   ` Dave Chinner [this message]
2020-07-08 12:56 ` [PATCH 2/4] xfs: Remove kmem_zone_zalloc() usage Carlos Maiolino
2020-07-09  2:55   ` Dave Chinner
2020-07-09  8:55     ` Carlos Maiolino
2020-07-09 16:42       ` Darrick J. Wong
2020-07-09 21:52         ` Dave Chinner
2020-07-08 12:56 ` [PATCH 3/4] xfs: Modify xlog_ticket_alloc() to use kernel's MM API Carlos Maiolino
2020-07-09  3:00   ` Dave Chinner
2020-07-08 12:56 ` [PATCH 4/4] xfs: remove xfs_zone_{alloc,zalloc} helpers Carlos Maiolino
2020-07-09  3:00   ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200709024506.GS2005@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=cmaiolino@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.