[PATCH 1/3] rust: maple_tree: add MapleTree
Alice Ryhl
aliceryhl at google.com
Tue Aug 19 02:09:58 PDT 2025
On Sat, Jul 26, 2025 at 5:45 PM Gary Guo <gary at garyguo.net> wrote:
>
> On Sat, 26 Jul 2025 13:23:22 +0000
> Alice Ryhl <aliceryhl at google.com> wrote:
>
> > The maple tree will be used in the Tyr driver to allocate and keep track
> > of GPU allocations created internally (i.e. not by userspace). It will
> > likely also be used in the Nova driver eventually.
> >
> > This adds the simplest methods for additional and removal that do not
> > require any special care with respect to concurrency.
> >
> > This implementation is based on the RFC by Andrew but with significant
> > changes to simplify the implementation.
> >
> > Co-developed-by: Andrew Ballance <andrewjballance at gmail.com>
> > Signed-off-by: Andrew Ballance <andrewjballance at gmail.com>
> > Signed-off-by: Alice Ryhl <aliceryhl at google.com>
>
> Overall looks good to me, some nits and thoughts about the error type
> below.
>
> Best,
> GAry
>
> > +/// Error type for failure to insert a new value.
> > +pub struct InsertError<T> {
> > + /// The value that could not be inserted.
> > + pub value: T,
> > + /// The reason for the failure to insert.
> > + pub cause: InsertErrorKind,
> > +}
>
> Hmm, we've already have quite a few errors that look like this, e.g.
> `StoreError`. I wonder if we should just have a generic
>
> struct ErrroWithData<T, E> {
> pub value: T,
> pub cause: E,
> }
I don't think we have any existing errors that look like this?
> > +
> > +/// The reason for the failure to insert.
> > +#[derive(PartialEq, Eq, Copy, Clone)]
> > +pub enum InsertErrorKind {
> > + /// There is already a value in the requested range.
> > + Occupied,
> > + /// Failure to allocate memory.
> > + Nomem,
>
> Given that we already have an error type for allocation failure, how
> about
>
> AllocError(crate::alloc::AllocError)
>
> ? I know we're getting ENOMEM from C, but this would match what the
> error type would be if it were from pure Rust code.
I don't think it makes a big difference, but ok.
Alice
More information about the maple-tree
mailing list