Re: [PATCH] mm/slab: only require the requested size when refilling prefilled sheaves

From: Harry Yoo

Date: Fri Oct 23 2026 - 10:27:26 EST


On Fri, Oct 23, 2026 at 05:44:01PM +0800, Qing Wang wrote:
> kmem_cache_prefill_sheaf() and kmem_cache_refill_sheaf() only guarantee
> @size objects, but for standard capacity sheaves
> __prefill_sheaf_pfmemalloc() uses refill_sheaf(), which actually fills
> the sheaf up to s->sheaf_capacity.
>
> The call thus fails with -ENOMEM > whenever the sheaf cannot be filled
> completely, even when @size objects were already obtained.

This is extremely rare condition to happen, and so...

> This leads to needless flushing of the partially
> filled sheaf in kmem_cache_prefill_sheaf(),

It doesn't make much sense to micro-optimize slab in low or out of
memory situations.

> and may use pfmemalloc
> reserves to fill the sheaf beyond what was requested.

But the request size itself is a speculation and unused objects will be
returned back to the allocator anyway.

> Pass the @size from kmem_cache_prefill_sheaf() and
> kmem_cache_refill_sheaf() down to __prefill_sheaf_pfmemalloc(), and have
> it use the newly added refill_sheaf_min(), which returns success once
> the sheaf holds @min_size objects while still trying to fill it up to
> s->sheaf_capacity.
>
> refill_sheaf() remains the full-capacity variant for
> __pcs_replace_empty_main() and kmem_cache_return_sheaf(), because sheaves
> on the barn's full list must be full.
>
> Signed-off-by: Qing Wang <wangqing7171@xxxxxxxxx>

--
Cheers,
Harry / Hyeonggon