Re: [PATCH v3] mm/slub: prevent pfmemalloc objects from entering the barn

From: Vlastimil Babka (SUSE)

Date: Tue Jul 21 2026 - 03:44:20 EST


On 7/21/26 09:34, Vlastimil Babka (SUSE) wrote:
> On 7/21/26 02:45, hu.shengming@xxxxxxxxxx wrote:
>> From: Shengming Hu <hu.shengming@xxxxxxxxxx>
>>
>> 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
>> non-pfmemalloc slabs. 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.
>>
>> Fixes: 3c1ea5c5019f ("slab: sheaf prefilling for guaranteed allocations")
>
> Wonder if 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with
> sheaves") is a better match. Until that commit we just didn't care, and it
> seems like this is a case that commit missed?

Added to slab/for-next with changed Fixes: per above, but can adjust it
further if it was wrong. Thanks!

>> Cc: stable@xxxxxxxxxxxxxxx
>> Signed-off-by: Shengming Hu <hu.shengming@xxxxxxxxxx>
>> ---
>> Changes in v3:
>> - Replace “normal memory” with the more precise “non-pfmemalloc slabs”,
>> and add Fixes: and Cc: stable@xxxxxxxxxxxxxxx, as suggested by Harry.
>> - Link to v2: https://lore.kernel.org/all/20260720211127124sYtTNbvsxCXN9_pDh-pwt@xxxxxxxxxx/
>>
>> Changes in v2:
>> - Add __GFP_NOWARN as suggested by Hao.
>> - Link to v1: https://lore.kernel.org/all/20260719113701797vZ3R8NxiqYt8dEfeUxtON@xxxxxxxxxx/
>>
>> ---
>> 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;
>