Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	"Harry Yoo" <harry@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, "Chris Mason" <mason@kernel.org>
Subject: Re: [PATCH 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves
Date: Fri, 27 Nov 2026 21:15:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-238285@kernel.org> (raw)
In-Reply-To: <20261127-slab-ai-fixes-v1-2-cf13b6be6692@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/slub: __prefill_sheaf_pfmemalloc() misses __GFP_NOFAIL
  without pfmemalloc
--

commit 7b605e7e1980fd6063399368212254f7119ec46c
Author: Vlastimil Babka (SUSE) <vbabka@kernel.org>

mm/slab: handle __GFP_NOFAIL better with prefilled sheaves

This commit strips __GFP_NOFAIL from the initial __GFP_NOMEMALLOC sheaf
refill attempt in __prefill_sheaf_pfmemalloc() when pfmemalloc is allowed,
and also clears __GFP_NOFAIL and adds __GFP_NORETRY in
kmem_cache_return_sheaf().

> diff --git a/mm/slub.c b/mm/slub.c
> index 5fd148f11efd1..20570e4f1795e 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)) {
> +		gfp_nomemalloc &= ~__GFP_NOFAIL;
>  		gfp_nomemalloc |= __GFP_NOWARN;
> +	}
>  
>  	ret = refill_sheaf(s, sheaf, gfp_nomemalloc);

[Severity: Medium]
Can a __GFP_NOFAIL refill still allocate a pfmemalloc slab without marking
sheaf->pfmemalloc when gfp_pfmemalloc_allowed(gfp) is false?

Callers such as mas_nomem_nofail() -> mas_alloc_nodes() pass
GFP_KERNEL | __GFP_NOFAIL in normal process context, where
gfp_pfmemalloc_allowed(gfp) returns false because __gfp_pfmemalloc_flags()
only checks __GFP_MEMALLOC, PF_MEMALLOC and oom_reserves_allowed(current).

In that case __GFP_NOFAIL remains set in gfp_nomemalloc.  If direct
reclaim fails, __alloc_pages_may_oom() grants ALLOC_NO_WATERMARKS to
__GFP_NOFAIL regardless of __GFP_NOMEMALLOC:

mm/page_alloc.c:__alloc_pages_may_oom() {
	...
		if (gfp_mask & __GFP_NOFAIL)
			page = __alloc_pages_cpuset_fallback(gfp_mask, order,
					ac->alloc_flags|ALLOC_NO_WATERMARKS, ac);
	...
}

The resulting slab is marked pfmemalloc, but refill_sheaf() succeeds on the
first attempt and returns with sheaf->pfmemalloc left false, allowing
kmem_cache_return_sheaf() to place pfmemalloc objects into pcs->spare or
the node barn.  Even if __GFP_NOFAIL is stripped unconditionally from
gfp_nomemalloc, the fallback condition (!ret || !gfp_pfmemalloc_allowed(gfp))
below would still return -ENOMEM without retrying unless it also checks for
gfp & __GFP_NOFAIL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-slab-ai-fixes-v1-0-cf13b6be6692@kernel.org?part=2


  reply	other threads:[~2026-11-27 21:16 UTC|newest]

Thread overview: 8+ 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-27 20:12 ` [PATCH 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves Vlastimil Babka (SUSE)
2026-11-27 21:15   ` sashiko-bot [this message]
2026-11-27 20:12 ` [PATCH 3/4] mm/slab: keep caches that drop debug flags unmergeable Vlastimil Babka (SUSE)
2026-11-27 21:15   ` sashiko-bot
2026-11-27 20:12 ` [PATCH 4/4] mm/slab: clear stale layout values in calculate_sizes() Vlastimil Babka (SUSE)
2026-11-27 21:16   ` sashiko-bot

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=sashiko-outbox-238285@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cl@gentwo.org \
    --cc=david@kernel.org \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mason@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --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