Re: [PATCH v6 08/12] rust: mm: add abstractions for allocating from a `sheaf`

From: Danilo Krummrich

Date: Sat Nov 21 2026 - 09:17:48 EST


On Fri Nov 20, 2026 at 2:10 PM CET, Andreas Hindborg wrote:
> +/// An owned allocation from a cache sheaf.
> +///
> +/// `SBox` is similar to `Box` but is backed by a slab cache allocation obtained
> +/// through a [`Sheaf`]. It provides owned access to an initialized object and
> +/// ensures the object is properly freed back to the cache when dropped.
> +///
> +/// The contained `T` is initialized when the `SBox` is returned from alloc and
> +/// dropped when the `SBox` is dropped.
> +///
> +/// An `SBox` holds a reference to the [`KMemCache`] it was allocated from.
> +/// Dropping the `SBox` may thus drop the last reference to the cache and
> +/// destroy the cache, which may sleep. See the `# Context` section of
> +/// [`KMemCache`].
> +///
> +/// # Invariants
> +///
> +/// - `ptr` points to a valid, initialized object of type `T`.
> +/// - `cache` is the cache from which this object was allocated.
> +/// - The object remains valid for the lifetime of the `SBox`.
> +pub struct SBox<T: KMemCacheInit<T>> {
> + ptr: NonNull<T>,
> + cache: Arc<KMemCache<T>>,
> +}

I did only notice this patch just now, will take a closer look later on. But
this all looks like it belongs into the alloc module.

Thanks,
Danilo