On Fri, Jun 20, 2025 at 10:29 AM Burak Emir <[email protected]> wrote: > > This series adds a Rust bitmap API for porting the approach from > commit 15d9da3f818c ("binder: use bitmap for faster descriptor lookup") > to Rust. The functionality in dbitmap.h makes use of bitmap and bitops. > > The Rust bitmap API provides a safe abstraction to underlying bitmap > and bitops operations. For now, only includes method necessary for > dbitmap.h, more can be added later. We perform bounds checks for > hardening, violations are programmer errors that result in panics. > > We include set_bit_atomic and clear_bit_atomic operations. One has > to avoid races with non-atomic operations, which is ensure by the > Rust type system: either callers have shared references &bitmap in > which case the mutations are atomic operations. Or there is a > exclusive reference &mut bitmap, in which case there is no concurrent > access. > > This series includes an optimization to represent the bitmap inline, > as suggested by Yury. > > We ran a simple microbenchmark which shows that overall the Rust API > can be expected to be about 4.5% slower than C API. > > We also introduce a Rust API in id_pool.rs that would replace > dbitmap.h from the commit referenced above. This data structure is coupled > with the bitmap API and adds support for growing and shrinking, along > with fine-grained control over when allocation happens. > The Binder code needs this since it holds a spinlock at the time it > discovers that growing is necessary; this has to be release > for performing a memory allocation with GFP_KERNEL that may cause > sleep. We includes example doctests that demonstrate this usage. > > This is v13, see [v12] for previous state. Thanks everyone for all the > helpful comments, this series has improved significantly as a result of > your work.
Reviewed-by: Alice Ryhl <[email protected]>
