Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/slub: prevent pfmemalloc objects from entering the barn 
@ 2026-07-20 13:11 hu.shengming
  2026-07-20 14:17 ` Harry Yoo
  0 siblings, 1 reply; 3+ messages in thread
From: hu.shengming @ 2026-07-20 13:11 UTC (permalink / raw)
  To: vbabka, harry, akpm
  Cc: hao.li, cl, rientjes, roman.gushchin, linux-mm, linux-kernel,
	zhang.run, cai.qu

From: Shengming Hu <hu.shengming@zte.com.cn>

kmem_cache_return_sheaf() may refill a partially consumed sheaf before
placing it in the barn. Without an explicit restriction, this refill may
draw objects from pfmemalloc slabs and consume emergency reserves.

Add __GFP_NOMEMALLOC so that returned sheaves are refilled only from
normal memory. Also add __GFP_NOWARN, as suggested by Hao Li, because this
refill is a best-effort attempt and failure is acceptable. If the refill
fails, flush and free the sheaf instead.

Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
---
Changes in v2:
- add __GFP_NOWARN as suggested by Hao.
- Link to v1: https://lore.kernel.org/all/20260719113701797vZ3R8NxiqYt8dEfeUxtON@zte.com.cn/

---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index 53b4976d3831..357b7522c817 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5123,7 +5123,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
 	 * simply flush and free it.
 	 */
 	if (!barn || data_race(barn->nr_full) >= MAX_FULL_SHEAVES ||
-	    refill_sheaf(s, sheaf, gfp)) {
+	    refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
 		sheaf_flush_unused(s, sheaf);
 		free_empty_sheaf(s, sheaf);
 		return;
-- 
2.25.1


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

* Re: [PATCH v2] mm/slub: prevent pfmemalloc objects from entering the barn
  2026-07-20 13:11 [PATCH v2] mm/slub: prevent pfmemalloc objects from entering the barn hu.shengming
@ 2026-07-20 14:17 ` Harry Yoo
  2026-07-21  0:33   ` hu.shengming
  0 siblings, 1 reply; 3+ messages in thread
From: Harry Yoo @ 2026-07-20 14:17 UTC (permalink / raw)
  To: hu.shengming, vbabka, akpm
  Cc: hao.li, cl, rientjes, roman.gushchin, linux-mm, linux-kernel,
	zhang.run, cai.qu


[-- Attachment #1.1: Type: text/plain, Size: 1776 bytes --]



On 7/20/26 10:11 PM, hu.shengming@zte.com.cn wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
> 
> kmem_cache_return_sheaf() may refill a partially consumed sheaf before
> placing it in the barn. Without an explicit restriction, this refill may
> draw objects from pfmemalloc slabs and consume emergency reserves.
> 
> Add __GFP_NOMEMALLOC so that returned sheaves are refilled only from
> normal memory. Also add __GFP_NOWARN, as suggested by Hao Li, because this

normal memory -> non-pfmemalloc slabs?

> refill is a best-effort attempt and failure is acceptable. If the refill
> fails, flush and free the sheaf instead.
>
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> ---

Overall looks good to me.

Probably worth adding Fixes: and Cc: stable to make processes' life
slightly easier under low memory situations?

Given that the API is not widely used yet I'm not sure how bad it would
be in practice, but the fix is quite simple.

> Changes in v2:
> - add __GFP_NOWARN as suggested by Hao.
> - Link to v1: https://lore.kernel.org/all/20260719113701797vZ3R8NxiqYt8dEfeUxtON@zte.com.cn/
> 
> ---
>  mm/slub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 53b4976d3831..357b7522c817 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5123,7 +5123,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
>  	 * simply flush and free it.
>  	 */
>  	if (!barn || data_race(barn->nr_full) >= MAX_FULL_SHEAVES ||
> -	    refill_sheaf(s, sheaf, gfp)) {
> +	    refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
>  		sheaf_flush_unused(s, sheaf);
>  		free_empty_sheaf(s, sheaf);
>  		return;

-- 
Cheers,
Harry / Hyeonggon


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v2] mm/slub: prevent pfmemalloc objects from entering the barn
  2026-07-20 14:17 ` Harry Yoo
@ 2026-07-21  0:33   ` hu.shengming
  0 siblings, 0 replies; 3+ messages in thread
From: hu.shengming @ 2026-07-21  0:33 UTC (permalink / raw)
  To: harry
  Cc: vbabka, akpm, hao.li, cl, rientjes, roman.gushchin, linux-mm,
	linux-kernel, zhang.run, cai.qu

Harry wrote:
> On 7/20/26 10:11 PM, hu.shengming@zte.com.cn wrote:
> > From: Shengming Hu <hu.shengming@zte.com.cn>
> > 
> > kmem_cache_return_sheaf() may refill a partially consumed sheaf before
> > placing it in the barn. Without an explicit restriction, this refill may
> > draw objects from pfmemalloc slabs and consume emergency reserves.
> > 
> > Add __GFP_NOMEMALLOC so that returned sheaves are refilled only from
> > normal memory. Also add __GFP_NOWARN, as suggested by Hao Li, because this
> 
> normal memory -> non-pfmemalloc slabs?
> 

Thanks, “non-pfmemalloc slabs” is indeed more precise. I’ll update it.

> > refill is a best-effort attempt and failure is acceptable. If the refill
> > fails, flush and free the sheaf instead.
> >
> > Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> > ---
> 
> Overall looks good to me.
> 
> Probably worth adding Fixes: and Cc: stable to make processes' life
> slightly easier under low memory situations?
> 
> Given that the API is not widely used yet I'm not sure how bad it would
> be in practice, but the fix is quite simple.
> 

I’ll also add the Fixes: tag and Cc: stable in v3.

--
With Best Regards,
Shengming


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

end of thread, other threads:[~2026-07-21  0:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 13:11 [PATCH v2] mm/slub: prevent pfmemalloc objects from entering the barn hu.shengming
2026-07-20 14:17 ` Harry Yoo
2026-07-21  0:33   ` hu.shengming

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