[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c750ab62-a3d4-422e-ac5b-c531dfcc749d@suse.cz>
Date: Tue, 7 Oct 2025 10:03:04 +0200
From: Vlastimil Babka <vbabka@...e.cz>
To: Christoph Hellwig <hch@...radead.org>
Cc: Suren Baghdasaryan <surenb@...gle.com>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Christoph Lameter <cl@...two.org>, David Rientjes <rientjes@...gle.com>,
Roman Gushchin <roman.gushchin@...ux.dev>, Harry Yoo <harry.yoo@...cle.com>,
Uladzislau Rezki <urezki@...il.com>,
Sidhartha Kumar <sidhartha.kumar@...cle.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, rcu@...r.kernel.org,
maple-tree@...ts.infradead.org, Alexei Starovoitov <ast@...nel.org>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Venkat Rao Bagalkote <venkat88@...ux.ibm.com>,
Qianfeng Rong <rongqianfeng@...o.com>, Wei Yang <richard.weiyang@...il.com>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
WangYuli <wangyuli@...ontech.com>, Jann Horn <jannh@...gle.com>,
Pedro Falcato <pfalcato@...e.de>
Subject: Re: [PATCH v8 00/23] SLUB percpu sheaves
On 10/7/25 08:34, Christoph Hellwig wrote:
> On Wed, Sep 10, 2025 at 10:01:02AM +0200, Vlastimil Babka wrote:
>> Hi,
>>
>> I'm sending full v8 due to more changes in the middle of the series that
>> resulted in later patches being fixed up due to conflicts (details in
>> the changelog below).
>> The v8 will replace+extend the v7 in slab/for-next.
>
> So I've been reading through this and wonder how the preallocation
> using shaves is to be used. Do you have example code for that
> somewhere?
Maple tree uses this but through its internal layers it's not super clear.
Basically it's for situations where you have an upper bound on the objects
you might need to allocate in some restricted context where you can't fail
but also can't reclaim etc. The steps are:
- kmem_cache_create() with kmem_cache_args.sheaf_capacity to be enough for
any reasonable upper bounds you might need (but also at least e.g. 32 to get
the performance effect of sheaves in general - this will be autotuned in the
followup work). If there's a possibility you might need more than this
capacity in some rare cases, it's fine, just will be slower when it happens.
- kmem_cache_prefill_sheaf() with size being your upper bound for the
following critical section operation, you might get more but not less if
that succeeds
(enter critical section)
- kmem_cache_alloc_from_sheaf(gfp, sheaf) - this is guaranteed to succeed as
many times as the size you requested in your prefill. gfp is there only for
__GFP_ZERO or __GFP_ACCOUNT, where the latter will breach the memcg limit
instead of failing
- kmem_cache_sheaf_size() tells you how much is left in the prefilled sheaf
(exit critical section)
- kmem_cache_return_sheaf() will return the sheaf with unused objects
later freeing the objects allocated via prefilled sheaf is done normally
- alternatively kmem_cache_refill_sheaf() for another round
The whole point compared to preallocation via bulk alloc/bulk free is if you
have a large upper bound for some corner case but only need few objects
typically, this way will be more effective on average.
If you preallocate and know you will use everything, you can keep using
kmem_cache_alloc_bulk() and this won't give you extra benefits.
Powered by blists - more mailing lists