[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjLouU9ZRabJtP9qK6RWNLHZvW6dtUqbCkzFqZO+9skTQ@mail.gmail.com>
Date: Thu, 24 Oct 2024 09:33:00 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Abdiel Janulgue <abdiel.janulgue@...il.com>, rust-for-linux@...r.kernel.org,
dakr@...hat.com, linux-kernel@...r.kernel.org, airlied@...hat.com,
miguel.ojeda.sandonis@...il.com
Subject: Re: [PATCH v2 1/5] rust: types: add `Owned` type and `Ownable` trait
On Thu, Oct 24, 2024 at 9:23 AM Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> On Wed, Oct 23, 2024 at 8:07 PM Boqun Feng <boqun.feng@...il.com> wrote:
> >
> > On Wed, Oct 23, 2024 at 07:52:23PM +0200, Alice Ryhl wrote:
> > [...]
> > > > > > > +impl<T: Ownable> Owned<T> {
> > > > > > > + /// Creates a new smart pointer that owns `T`.
> > > > > > > + ///
> > > > > > > + /// # Safety
> > > > > > > + /// `ptr` needs to be a valid pointer, and it should be the unique owner to the object,
> > > > > > > + /// in other words, no other entity should free the underlying data.
> > > > > > > + pub unsafe fn to_owned(ptr: *mut T) -> Self {
> > > > > >
> > > > > > Please rename this function to from_raw to match the name used by
> > > > > > other similar functions.
> > > > > >
> > > > > > Also, I don't love this wording. We don't really want to guarantee
> > > > > > that it is unique. For example, pages have one primary owner, but
> > > > > > there can be others who also have refcounts to the page, so it's not
> > > > > > really unique. I think you just want to say that `ptr` must point at a
> > > >
> > > > But then when `Owned<Page>` dropped, it will call __free_pages() which
> > > > invalidate any other existing users. Do you assume that the users will
> > > > use pointers anyway, so it's their unsafe responsiblity to guarantee
> > > > that they don't use an invalid pointer?
> > > >
> > > > Also I assume you mean the others have refcounts to the page *before* an
> > > > `Owned<Page>` is created, right? Because if we really have a use case
> > > > where we want to have multiple users of a page after `Owned<Page>`
> > > > created, we should better provide a `Owned<Page>` to `ARef<Page>`
> > > > function.
> > >
> > > The __free_pages function just decrements a refcount. If there are
> > > other references to it, it's not actually freed.
> > >
> >
> > Then why don't we use page_put() there? ;-) And instead of
> > `Owned<Page>`, we can wrap the kernel::page as `ARef<Page>`, no?
>
> I don't think there's a function called page_put?
Sorry I confused myself. It's because it's called put_page.
Alice
Powered by blists - more mailing lists