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

Boqun Feng
2025-09-25T18:11:05Z

On Thu, Sep 25, 2025 at 02:02:55PM -0400, 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?
>

For current in-tree API, yes, because we have to start with something
simple and the user (binder I believe?) doesn't require
external-allocated nodes.

Regards,
Boqun

> That is, the kmemcache would allocate the struct that contains the
> rbtree linkage (or nodes, I guess), but not the nodes alone.
>
> Thanks,
> Liam