Re: [PATCH 09/10] rust: xarray: add preload API
From: Andreas Hindborg
Date: Wed Jan 21 2026 - 14:09:32 EST
"Gary Guo" <gary@xxxxxxxxxxx> writes:
> On Wed Dec 3, 2025 at 10:26 PM GMT, Andreas Hindborg wrote:
>> Add a preload API that allows preallocating memory for XArray
>> insertions. This enables insertions to proceed without allocation
>> failures in contexts where memory allocation is not desirable, such as
>> in atomic contexts or where reliability is critical.
>>
>> The API includes:
>>
>> - `XArrayPreloadBuffer` for managing a pool of preallocated nodes.
>> - `XArrayPreloadNode` representing a single preallocated node.
>> - Integration with the entry API, allowing `VacantEntry::insert` and
>> `VacantEntry::insert_entry` to accept an optional preload buffer.
>> - A new `Guard::insert_entry` method for inserting with preload support.
>>
>> The implementation uses a circular buffer to efficiently manage
>> preallocated nodes. When an insertion would fail due to ENOMEM, the
>> XArray state API automatically consumes a preallocated node from the
>> buffer if available.
>
> It looks like this code doesn't neede to be XArray specific. You can provide
> a generic abstraction for kmem_cache and just use a specific instance for
> XArray?
I guess. Perhaps we can go with this for now and make the code generic
when we have more users? Just so that we don't over engineer if there is
not reason.
In the session at LPC25 where we discussed this series, I was
recommended to use a sheaf rather than managing the preallocated objects
myself. I did not look into this yet, but I will.
Best regards,
Andreas Hindborg