Re: [PATCH v2 2/4] mm/slab: handle __GFP_NOFAIL better with prefilled sheaves

From: Harry Yoo

Date: Wed Dec 02 2026 - 10:06:21 EST


On Tue, Dec 01, 2026 at 07:16:03PM +0100, Vlastimil Babka (SUSE) wrote:
> If a prefilled sheaf is requested with __GFP_NOFAIL in a
> gfp_pfmemalloc_allowed() context, the following can happen in the
> initial __GFP_NOMEMALOC attempt.
>
> refill_objects() __GFP_NOFAIL | __GFP_NOMEMALLOC
> new_slab()
> __alloc_pages_may_oom()
> if (gfp_mask & __GFP_NOFAIL)
> ALLOC_NO_WATERMARKS the slab is pfmemalloc
> alloc_from_new_slab() its objects go into the sheaf
>
> So the sheaf should be marked pfmemalloc, but isn't. Fix this by
> precisely determining in the refill path, whether a pfmemalloc slab was
> used to refill the sheaf, whether it was on the partial list or newly
> allocated.
>
> Additionally, remove the __GFP_NOFAIL from the initial nomemalloc
> attempt so it really cannot end up with a pfmemalloc slab, as intended.
>
> For consistency, also adjust kmem_cache_return_sheaf() in case somebody
> would hypothetically call it with __GFP_NOFAIL. Just drop it
> unconditionally and also add __GFP_NORETRY there to make returns
> cheaper - in a low memory situation, keeping the sheaf from being
> flushed isn't a priority.
>
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Fixes: 1ce20c28eafd ("slab: handle pfmemalloc slabs properly with sheaves")
> Cc: <stable@xxxxxxxxxxxxxxx>

s/orG/org/

I'll fix it when applying it :)

> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
> ---

Looks good to me,
Reviewed-by: Harry Yoo (Meta) <harry@xxxxxxxxxx>

--
Cheers,
Harry / Hyeonggon