[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240209130426.1791631-1-aliceryhl@google.com>
Date: Fri, 9 Feb 2024 13:04:26 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: mattgilbride@...gle.com
Cc: a.hindborg@...sung.com, alex.gaynor@...il.com, aliceryhl@...gle.com,
arve@...roid.com, benno.lossin@...ton.me, bjorn3_gh@...tonmail.com,
boqun.feng@...il.com, brauner@...nel.org, cmllamas@...gle.com,
dave@...olabs.net, gary@...yguo.net, gregkh@...uxfoundation.org,
joel@...lfernandes.org, linux-kernel@...r.kernel.org, maco@...roid.com,
michel@...pinasse.org, ojeda@...nel.org, rob@...dley.net,
rust-for-linux@...r.kernel.org, surenb@...gle.com, tkjos@...roid.com,
wedsonaf@...il.com
Subject: Re: [PATCH 2/6] rust: rbtree: add red-black tree implementation
backed by the C version
> From: Wedson Almeida Filho <wedsonaf@...il.com>
>
> The rust rbtree exposes a map-like interface over keys and values,
> backed by the kernel red-black tree implementation. Values can be
> inserted, deleted, and retrieved from a `RBTree` by key.
>
> This base abstraction is used by binder to store key/value
> pairs and perform lookups, for example the patch
> "[PATCH RFC 03/20] rust_binder: add threading support"
> in the binder RFC [1].
>
> Link: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-3-08ba9197f637@google.com/ [1]
> Signed-off-by: Wedson Almeida Filho <wedsonaf@...il.com>
> Signed-off-by: Matt Gilbride <mattgilbride@...gle.com>
I have looked at these bindings many times over the past year. They
look good to me, modulo a few nits included in this email.
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
These abstractions have been very heavily exercised by the Rust Binder
driver.
Tested-by: Alice Ryhl <aliceryhl@...gle.com>
> +//! Red-black trees.
> +//!
> +//! C header: [`include/linux/rbtree.h`](../../../../include/linux/rbtree.h)
> +//!
> +//! Reference: <https://www.kernel.org/doc/html/latest/core-api/rbtree.html>
We changed these links, so it should say this instead:
[`include/linux/rbtree.h`](srctree/include/linux/rbtree.h)
> + /// Allocates memory for a node to be eventually initialised and inserted into the tree via a
> + /// call to [`RBTree::insert`].
> + pub fn try_reserve_node() -> Result<RBTreeNodeReservation<K, V>> {
> + Ok(RBTreeNodeReservation {
> + node: Box::try_new(MaybeUninit::uninit())?,
> + })
> + }
This can be:
use crate::prelude::*;
use core::convert::Infallible;
Ok(RBTreeNodeReservation {
node: Box::init::<Infallible>(crate::init::uninit())?,
})
It might be slightly more verbose, but guarantees that we don't allocate
space for the value on the stack.
Alice
Powered by blists - more mailing lists