Re: [PATCH] rust: slab: add basic slab module

Danilo Krummrich
2025-09-25T18:08:18Z

On Thu Sep 25, 2025 at 8:02 PM CEST, Liam R. Howlett wrote:
> * Danilo Krummrich <dakr@kernel.org> [250925 13:43]:
>> On Thu Sep 25, 2025 at 7:20 PM CEST, Elijah wrote:
>>
>
> ...
>
>>
>> > I was thinking of maybe creating something like KBox for kmem_cache but
>> > I didn't want to touch allocator code yet, I figured I would just create
>> > the groundwork for that to exist. rbtree.rs uses KBox now but I'm not
>> > sure it should, at least if it's going to scale to many nodes
>>
>> Ok, so you want to support kmemcache for rbtree nodes. Ideally, you should also
>> have a use-case for that, but given that we'll also need kmemcache in other
>> drivers (such as Nova) anyways, I think that's fine.
>
> This seems different than what exists on the C side, at least to me.
> The rbtree is implemented by embedding the links to the prev/next into
> the struct which is using the tree.
>
> The above sounds like the nodes of the rbtree are allocated on its own
> and not part of another allocation on the rust side?
>
> That is, the kmemcache would allocate the struct that contains the
> rbtree linkage (or nodes, I guess), but not the nodes alone.

On the Rust side the rbtree's Node structure looks like this:

struct Node<K, V> {
links: bindings::rb_node,
key: K,
value: V,
}

The allocation would be for the entire rbtree::Node and not only for the C
struct rb_node.