linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slab: pass __GFP_NOWARN to refill_sheaf() if fallback is available
@ 2026-02-23 13:33 Harry Yoo
  2026-02-23 16:48 ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 3+ messages in thread
From: Harry Yoo @ 2026-02-23 13:33 UTC (permalink / raw)
  To: Vlastimil Babka, Andrew Morton
  Cc: Christoph Lameter, David Rientjes, Roman Gushchin, Harry Yoo,
	Hao Li, linux-mm, Chris Bainbridge

When refill_sheaf() is called, failing to refill the sheaf doesn't
necessarily mean the allocation will fail because a fallback path
might be available and serve the allocation request.

Suppress spurious warnings by passing __GFP_NOWARN along with
__GFP_NOMEMALLOC whenever a fallback path is available.

When the caller is alloc_full_sheaf() or __pcs_replace_empty_main(),
the kernel always falls back to the slowpath (__slab_alloc_node()).
For __prefill_sheaf_pfmemalloc(), the fallback path is available
only when gfp_pfmemalloc_allowed() returns true.

Reported-by: Chris Bainbridge <chris.bainbridge@gmail.com>
Closes: https://lore.kernel.org/linux-mm/aZt2-oS9lkmwT7Ch@debian.local
Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves")
Link: https://lore.kernel.org/linux-mm/aZwSreGj9-HHdD-j@hyeyoo
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
 mm/slub.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index afa98065d74f..0c986c240bf6 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2823,7 +2823,7 @@ static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp)
 	if (!sheaf)
 		return NULL;
 
-	if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC)) {
+	if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
 		free_empty_sheaf(s, sheaf);
 		return NULL;
 	}
@@ -4576,7 +4576,7 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
 		return NULL;
 
 	if (empty) {
-		if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC)) {
+		if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
 			full = empty;
 		} else {
 			/*
@@ -4891,9 +4891,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node_noprof);
 static int __prefill_sheaf_pfmemalloc(struct kmem_cache *s,
 				      struct slab_sheaf *sheaf, gfp_t gfp)
 {
-	int ret = 0;
+	gfp_t gfp_nomemalloc;
+	int ret;
+
+	gfp_nomemalloc = gfp | __GFP_NOMEMALLOC;
+	if (gfp_pfmemalloc_allowed(gfp))
+		gfp_nomemalloc |= __GFP_NOWARN;
 
-	ret = refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC);
+	ret = refill_sheaf(s, sheaf, gfp_nomemalloc);
 
 	if (likely(!ret || !gfp_pfmemalloc_allowed(gfp)))
 		return ret;
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/slab: pass __GFP_NOWARN to refill_sheaf() if fallback is available
  2026-02-23 13:33 [PATCH] mm/slab: pass __GFP_NOWARN to refill_sheaf() if fallback is available Harry Yoo
@ 2026-02-23 16:48 ` Vlastimil Babka (SUSE)
  2026-02-23 19:46   ` Chris Bainbridge
  0 siblings, 1 reply; 3+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-02-23 16:48 UTC (permalink / raw)
  To: Harry Yoo, Vlastimil Babka, Andrew Morton
  Cc: Christoph Lameter, David Rientjes, Roman Gushchin, Hao Li,
	linux-mm, Chris Bainbridge

On 2/23/26 14:33, Harry Yoo wrote:
> When refill_sheaf() is called, failing to refill the sheaf doesn't
> necessarily mean the allocation will fail because a fallback path
> might be available and serve the allocation request.
> 
> Suppress spurious warnings by passing __GFP_NOWARN along with
> __GFP_NOMEMALLOC whenever a fallback path is available.
> 
> When the caller is alloc_full_sheaf() or __pcs_replace_empty_main(),
> the kernel always falls back to the slowpath (__slab_alloc_node()).
> For __prefill_sheaf_pfmemalloc(), the fallback path is available
> only when gfp_pfmemalloc_allowed() returns true.
> 
> Reported-by: Chris Bainbridge <chris.bainbridge@gmail.com>
> Closes: https://lore.kernel.org/linux-mm/aZt2-oS9lkmwT7Ch@debian.local
> Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves")
> Link: https://lore.kernel.org/linux-mm/aZwSreGj9-HHdD-j@hyeyoo
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>

Thanks, added to slab/for-next-fixes.
Hopefully Chris can confirm it works (without adding the __NOWARN to btrfs code)

> ---
>  mm/slub.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index afa98065d74f..0c986c240bf6 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2823,7 +2823,7 @@ static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp)
>  	if (!sheaf)
>  		return NULL;
>  
> -	if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC)) {
> +	if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
>  		free_empty_sheaf(s, sheaf);
>  		return NULL;
>  	}
> @@ -4576,7 +4576,7 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
>  		return NULL;
>  
>  	if (empty) {
> -		if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC)) {
> +		if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
>  			full = empty;
>  		} else {
>  			/*
> @@ -4891,9 +4891,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node_noprof);
>  static int __prefill_sheaf_pfmemalloc(struct kmem_cache *s,
>  				      struct slab_sheaf *sheaf, gfp_t gfp)
>  {
> -	int ret = 0;
> +	gfp_t gfp_nomemalloc;
> +	int ret;
> +
> +	gfp_nomemalloc = gfp | __GFP_NOMEMALLOC;
> +	if (gfp_pfmemalloc_allowed(gfp))
> +		gfp_nomemalloc |= __GFP_NOWARN;
>  
> -	ret = refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC);
> +	ret = refill_sheaf(s, sheaf, gfp_nomemalloc);
>  
>  	if (likely(!ret || !gfp_pfmemalloc_allowed(gfp)))
>  		return ret;



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/slab: pass __GFP_NOWARN to refill_sheaf() if fallback is available
  2026-02-23 16:48 ` Vlastimil Babka (SUSE)
@ 2026-02-23 19:46   ` Chris Bainbridge
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Bainbridge @ 2026-02-23 19:46 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Harry Yoo, Vlastimil Babka, Andrew Morton, Christoph Lameter,
	David Rientjes, Roman Gushchin, Hao Li, linux-mm

On Mon, Feb 23, 2026 at 05:48:25PM +0100, Vlastimil Babka (SUSE) wrote:
> On 2/23/26 14:33, Harry Yoo wrote:
> > When refill_sheaf() is called, failing to refill the sheaf doesn't
> > necessarily mean the allocation will fail because a fallback path
> > might be available and serve the allocation request.
> > 
> > Suppress spurious warnings by passing __GFP_NOWARN along with
> > __GFP_NOMEMALLOC whenever a fallback path is available.
> > 
> > When the caller is alloc_full_sheaf() or __pcs_replace_empty_main(),
> > the kernel always falls back to the slowpath (__slab_alloc_node()).
> > For __prefill_sheaf_pfmemalloc(), the fallback path is available
> > only when gfp_pfmemalloc_allowed() returns true.
> > 
> > Reported-by: Chris Bainbridge <chris.bainbridge@gmail.com>
> > Closes: https://lore.kernel.org/linux-mm/aZt2-oS9lkmwT7Ch@debian.local
> > Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves")
> > Link: https://lore.kernel.org/linux-mm/aZwSreGj9-HHdD-j@hyeyoo
> > Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> 
> Thanks, added to slab/for-next-fixes.
> Hopefully Chris can confirm it works (without adding the __NOWARN to btrfs code)

Yes, it works for my test case.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-23 19:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-23 13:33 [PATCH] mm/slab: pass __GFP_NOWARN to refill_sheaf() if fallback is available Harry Yoo
2026-02-23 16:48 ` Vlastimil Babka (SUSE)
2026-02-23 19:46   ` Chris Bainbridge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox