Re: [PATCH v3 11/12] xarray, radix-tree: enable sheaf support for kmem_cache

From: Andreas Hindborg

Date: Wed Feb 11 2026 - 02:46:06 EST


Daniel Gomez <da.gomez@xxxxxxxxxx> writes:

> On 2026-02-09 15:38, Andreas Hindborg wrote:
>> The rust null block driver plans to rely on preloading xarray nodes from
>> the radix_tree_node_cachep kmem_cache.
>>
>> Cc: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
>> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>> ---
>> lib/radix-tree.c | 14 ++++++++++----
>> 1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib/radix-tree.c b/lib/radix-tree.c
>> index 976b9bd02a1b5..1cf0012b15ade 100644
>> --- a/lib/radix-tree.c
>> +++ b/lib/radix-tree.c
>> @@ -1598,10 +1598,16 @@ void __init radix_tree_init(void)
>> BUILD_BUG_ON(RADIX_TREE_MAX_TAGS + __GFP_BITS_SHIFT > 32);
>> BUILD_BUG_ON(ROOT_IS_IDR & ~GFP_ZONEMASK);
>> BUILD_BUG_ON(XA_CHUNK_SIZE > 255);
>> - radix_tree_node_cachep = kmem_cache_create("radix_tree_node",
>> - sizeof(struct radix_tree_node), 0,
>> - SLAB_PANIC | SLAB_RECLAIM_ACCOUNT,
>> - radix_tree_node_ctor);
>> +
>> + struct kmem_cache_args args = {
>> + .ctor = radix_tree_node_ctor,
>> + .sheaf_capacity = 64,
>> + };
>
> Is the sheaf_capacity matching the number of slots in an XArray node? If so,
> this should be bindings::XA_CHUNK_SIZE.

It is not, it is arbitrarily chosen to large enough to gain an advantage
but small enough to not waste too much memory.

For rust null block, it needs to be at least large enough to insert two
leaf nodes.


Best regards,
Andreas Hindborg