mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
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
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
© 2016 - 2026 Red Hat, Inc.