Re: [PATCH] rust: slab: add basic slab module
From: Vlastimil Babka
Date: Fri Sep 26 2025 - 12:32:14 EST
On 9/26/25 17:55, Danilo Krummrich wrote:
> On Fri Sep 26, 2025 at 5:33 PM CEST, Danilo Krummrich wrote:
>> The only thing we need on the Rust side is that existing allocations remain
>> valid even if the cache is destroyed. Or the other way around the cache is
>> silently kept alive internally.
>
> Or to express it in C code:
>
> struct kmem_cache *cache = kmem_cache_create();
> struct Foo *foo = kmem_cache_alloc();
>
> // After this call cache will never be accessed; leaves a zombie cache,
> // since foo is still alive.
> kmem_cache_destroy(cache);
This will cause a WARN.
> // This must still be valid.
> foo->bar = 42;
Yes this will be safe.
> // Frees foo and causes the "zombie" cache to actually be destroyed.
> kmem_cache_free(foo);
The free will be fine. But not cause the cache destruction, as that would
require checks on each free. But should be fine wrt safety if we only leak
some memory due to a wrong usage, no?