Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
	 David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	 "David Hildenbrand (Arm)" <david@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 Chris Mason <mason@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/4] mm/slab: drop __GFP_NOFAIL when refilling sheaves
Date: Mon, 30 Nov 2026 14:10:24 +0000	[thread overview]
Message-ID: <aw2Ah-_g0LGyRXpo@thinkstation> (raw)
In-Reply-To: <20261127-slab-ai-fixes-v1-1-cf13b6be6692@kernel.org>

On Fri, Nov 27, 2026 at 09:12:30PM +0100, Vlastimil Babka (SUSE) wrote:
> A __GFP_NOFAIL slab allocation in a low memory situation may end up
> refilling a whole sheaf from slabs (possibly newly allocated), passing
> the __GFP_NOFAIL to all underlying allocations. This can make the low
> memory condition worse and it's unnecessary, given there's a fallback.
> 
> Given how we use __GFP_MEMALLOC for the refill, there are also some

s/__GFP_MEMALLOC/__GFP_NOMEMALLOC/

> undesirable corner cases, as reported by Chris Mason. If the allocation
> happens in a PF_MEMALLOC task (which it should not in the first place,
> but there's no guarantee), the following can occur:
> 
>     refill_sheaf(gfp | __GFP_NOMEMALLOC)
>       __alloc_pages_slowpath()
> 	WARN_ON_ONCE(nofail && PF_MEMALLOC)
>         retry:
>         reserve_flags = 0           /* __GFP_NOMEMALLOC */
>         goto nopage                 /* PF_MEMALLOC */
>         goto retry                  /* __GFP_NOFAIL */
> 
> The allocation will loop without reclaim and no access to memory
> reserves.
> 
> Additionally the slab page may be marked pfmemalloc, which the sheaf
> refill does not expect and handle:
> 
>     refill_objects()              __GFP_NOFAIL | __GFP_NOMEMALLOC
>       new_slab()
>         __alloc_pages_may_oom()
>           if (gfp_mask & __GFP_NOFAIL)
>             ALLOC_NO_WATERMARKS   the slab is then pfmemalloc
>       alloc_from_new_slab()       its objects go into the sheaf
> 
> Improve or prevent all of the above by dropping __GFP_NOFAIL for the
> sheaf refill. Also perform all adjustments before potentially calling
> alloc_empty_sheaf(). While that one already clears __GFP_NOFAIL, it
> should also get the __GFP_NOMEMALLOC | __GFP_NOWARN flags, since a
> fallback exists.
> 
> One consequence is that the WARN_ON_ONCE(nofail && PF_MEMALLOC) in the
> page allocator will now only be reachable from the fallback and thus in
> case such a caller is introduced, might lurk undetected for a while. If
> people think it's an issue, we can duplicate the warning here as well.
> 
> Reported-by: Chris Mason <mason@kernel.org>
> Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> ---

Looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>

>  mm/slub.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 145a32c334cb..5fd148f11efd 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -4807,13 +4807,20 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
>  	if (!allow_spin)
>  		return NULL;
>  
> +	/*
> +	 * We don't want refills to rely on __GFP_NOFAIL or memalloc reserves to
> +	 * succeed, nor to warn on failure. Leave that to the fallback.
> +	 */
> +	gfp &= ~__GFP_NOFAIL;
> +	gfp |= __GFP_NOMEMALLOC | __GFP_NOWARN;
> +
>  	if (!empty) {
>  		empty = alloc_empty_sheaf(s, gfp, alloc_flags);
>  		if (!empty)
>  			return NULL;
>  	}
>  
> -	if (refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
> +	if (refill_sheaf(s, empty, gfp)) {
>  		/*
>  		 * we must be very low on memory so don't bother
>  		 * with the barn
> 
> -- 
> 2.56.1
> 

-- 
Cheers,
Harry / Hyeonggon

  reply	other threads:[~2026-11-30 14:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 20:12 [PATCH 0/4] slab AI fixes Vlastimil Babka (SUSE)
2026-11-27 20:12 ` [PATCH 1/4] mm/slab: drop __GFP_NOFAIL when refilling sheaves Vlastimil Babka (SUSE)
2026-11-30 14:10   ` Harry Yoo [this message]
2026-11-27 20:12 ` [PATCH 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves Vlastimil Babka (SUSE)
2026-11-27 20:12 ` [PATCH 3/4] mm/slab: keep caches that drop debug flags unmergeable Vlastimil Babka (SUSE)
2026-11-27 20:12 ` [PATCH 4/4] mm/slab: clear stale layout values in calculate_sizes() Vlastimil Babka (SUSE)

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=aw2Ah-_g0LGyRXpo@thinkstation \
    --to=harry@kernel.org \
    --cc=cl@gentwo.org \
    --cc=david@kernel.org \
    --cc=hao.li@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mason@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=vbabka@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox