[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ba769013-b6ef-49f4-93ad-68f3b7c8116e@proton.me>
Date: Wed, 14 Aug 2024 21:10:19 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Danilo Krummrich <dakr@...nel.org>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com, boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, a.hindborg@...sung.com, aliceryhl@...gle.com, akpm@...ux-foundation.org, daniel.almeida@...labora.com, faith.ekstrand@...labora.com, boris.brezillon@...labora.com, lina@...hilina.net, mcanal@...lia.com, zhiw@...dia.com, cjia@...dia.com, jhubbard@...dia.com, airlied@...hat.com, ajanulgu@...hat.com, lyude@...hat.com, linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH v5 04/26] rust: alloc: implement `Allocator` for `Kmalloc`
On 14.08.24 19:13, Danilo Krummrich wrote:
> On Wed, Aug 14, 2024 at 04:28:04PM +0000, Benno Lossin wrote:
>> On 12.08.24 20:22, Danilo Krummrich wrote:
>>> +unsafe impl Allocator for Kmalloc {
>>
>> There is a missing SAFETY comment here (and also for Vmalloc, probably
>> also for VKmalloc then).
>
> Any suggestion on what to write here?
>
> I'd probably come up with something like:
>
> --
> Memory returned from `Kmalloc` remains valid until explicitly freed.
>
> It is valid to pass any pointer to an allocated memory buffer obtained with any
> function of `Kmalloc` to any other function of `Kmalloc`.
>
> If `Kmalloc::realloc` is called with a size of zero, the given memory
> allocation, if any, is freed.
>
> If `Kmalloc::realloc` is called with `None` it behaves like `Kmalloc::alloc`,
> i.e. a new memory allocation is created.
> --
>
> and repeat that for `Vmalloc` and `KVmalloc`.
>
> I'm not sure how useful that is though.
Ideally you would write down how the guarantees are satisfied in
addition to the invariants. But I guess this is only guaranteed by the
`ReallocFunc::call`, since that handles the ZSTs... Maybe this is a bit
excessive. If I come up with something better I will let you know.
---
Cheers,
Benno
Powered by blists - more mailing lists