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 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves
Date: Mon, 30 Nov 2026 14:58:20 +0000 [thread overview]
Message-ID: <aw2HygPvtVAnjRZ3@thinkstation> (raw)
In-Reply-To: <20261127-slab-ai-fixes-v1-2-cf13b6be6692@kernel.org>
On Fri, Nov 27, 2026 at 09:12:31PM +0100, Vlastimil Babka (SUSE) wrote:
> If a prefilled sheaf is requested with __GFP_NOFAIL in a
> gfp_pfmemalloc_allowed() context, the following can happen in the
> initial __GFP_NOMEMALOC attempt.
>
> refill_objects() __GFP_NOFAIL | __GFP_NOMEMALLOC
> new_slab()
> __alloc_pages_may_oom()
> if (gfp_mask & __GFP_NOFAIL)
> ALLOC_NO_WATERMARKS the slab is pfmemalloc
> alloc_from_new_slab() its objects go into the sheaf
>
> So the sheaf should be marked pfmemalloc, but isn't. Fix this by
> removing __GFP_NOFAIL from the __GFP_NOMEMALLOC attempt.
Hmm the underlying problem here is that slab can't tell if it might be
allocated from memory reserves or not just by looking at the GFP
flags?
We should probably set sheaf->pfmemalloc to true in refill_objects()
when it ended up allocating a pfmemalloc slab and refilled objects from
it.
> For consistency, also adjust kmem_cache_return_sheaf() in case somebody
> would hypothetically call it with __GFP_NOFAIL. Just drop it
> unconditionally and also add __GFP_NORETRY there to make returns
> cheaper - in a low memory situation, keeping the sheaf from being
> flushed isn't a priority.
>
> 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>
> ---
> mm/slub.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 5fd148f11efd..20570e4f1795 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5204,8 +5204,10 @@ static int __prefill_sheaf_pfmemalloc(struct kmem_cache *s,
> return 0;
>
> gfp_nomemalloc = gfp | __GFP_NOMEMALLOC;
> - if (gfp_pfmemalloc_allowed(gfp))
> + if (gfp_pfmemalloc_allowed(gfp)) {
As pointed out by Sashiko gfp_pfmemalloc_allowed could still
return false with __GFP_NOFAIL. __GFP_NOFAIL is not included in
__gfp_pfmemalloc_flags() but it _may_ end up setting
ALLOC_NO_WATERMARKS.
> + gfp_nomemalloc &= ~__GFP_NOFAIL;
> gfp_nomemalloc |= __GFP_NOWARN;
> + }
>
> ret = refill_sheaf(s, sheaf, gfp_nomemalloc);
>
> @@ -5345,12 +5347,18 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
>
> stat(s, SHEAF_RETURN_SLOW);
>
> + /*
> + * If we end up refilling the sheaf, don't try too hard.
> + */
> + gfp &= ~__GFP_NOFAIL;
> + gfp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
> +
> /*
> * If the barn has too many full sheaves or we fail to refill the sheaf,
> * simply flush and free it.
> */
> if (!barn || data_race(barn->nr_full) >= MAX_FULL_SHEAVES ||
> - refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
> + refill_sheaf(s, sheaf, gfp)) {
> sheaf_flush_unused(s, sheaf);
> free_empty_sheaf(s, sheaf);
> return;
>
> --
> 2.56.1
>
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2026-11-30 14:58 UTC|newest]
Thread overview: 9+ 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
2026-11-27 20:12 ` [PATCH 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves Vlastimil Babka (SUSE)
2026-11-30 14:58 ` Harry Yoo [this message]
2026-11-27 20:12 ` [PATCH 3/4] mm/slab: keep caches that drop debug flags unmergeable Vlastimil Babka (SUSE)
2026-11-30 15:14 ` Harry Yoo
2026-11-27 20:12 ` [PATCH 4/4] mm/slab: clear stale layout values in calculate_sizes() Vlastimil Babka (SUSE)
2026-11-30 15:26 ` Harry Yoo
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=aw2HygPvtVAnjRZ3@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
all inboxes | Powered by JetHome®