Re: [PATCH] rust_binder: Reuse the free-index node in the range allocator

From: Alice Ryhl

Date: Sun Nov 29 2026 - 08:21:47 EST


On Thu, Nov 26, 2026 at 07:06:03PM +0100, Peder Bergan wrote:
> Convert the detached node into an RBTreeNodeReservation and store it
> with the buffer. The release path can initialize the key after
> coalescing the range. This reduces preparation from three fresh node
> allocations to two and avoids one free under the process spinlock
> per successful tree reservation, for both exact fits and splits.

Nice optimization, thanks!

> + // Keep the removed index node so releasing this buffer can restore a free range
> + // without allocating under the lock.
> + let free_node_res = self
> + .free_tree
> + .remove_node(&(found_size, found_off))
> + .ok_or(EINVAL)?
> + .into_reservation();
> + desc.state = Some((DescriptorState::new(is_oneway, debug_id, pid), free_node_res));

Please run `rustfmt` on drivers/android/binder/range_alloc/tree.rs.

Also, optionally, you could use `self.free_tree.cursor_lower_bound_mut()`
and `cursor.remove_current().1.into_reservation()` to avoid the second
`free_tree` lookup and the unreachable `EINVAL` path, though I'm fine
with either approach.

With the `rustfmt` diff fixed, feel free to add:

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>

Alice