From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Dave Ertman" <david.m.ertman@intel.com>,
"Ira Weiny" <ira.weiny@intel.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
"Serge Hallyn" <sergeh@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>,
"Igor Korotin" <igor.korotin.linux@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Viresh Kumar" <vireshk@kernel.org>, "Nishanth Menon" <nm@ti.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Uladzislau Rezki" <urezki@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>,
<linux-block@vger.kernel.org>,
<linux-security-module@vger.kernel.org>,
<dri-devel@lists.freedesktop.org>,
<linux-fsdevel@vger.kernel.org>, <linux-mm@kvack.org>,
<linux-pm@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: Re: [PATCH v16 01/10] rust: alloc: add `KBox::into_nonnull`
Date: Sun, 01 Mar 2026 19:25:53 +0000 [thread overview]
Message-ID: <DGROXQD756OU.T2CRAPKA2HCB@garyguo.net> (raw)
In-Reply-To: <87ldgbbjal.fsf@t14s.mail-host-address-is-not-set>
On Sun Mar 1, 2026 at 4:34 PM GMT, Andreas Hindborg wrote:
> "Gary Guo" <gary@garyguo.net> writes:
>
>> On Tue Feb 24, 2026 at 11:17 AM GMT, Andreas Hindborg wrote:
>>> Add a method to consume a `Box<T, A>` and return a `NonNull<T>`. This
>>> is a convenience wrapper around `Self::into_raw` for callers that need
>>> a `NonNull` pointer rather than a raw pointer.
>>>
>>> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> ---
>>> rust/kernel/alloc/kbox.rs | 8 ++++++++
>>> 1 file changed, 8 insertions(+)
>>>
>>> diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
>>> index 622b3529edfcb..e6efdd572aeea 100644
>>> --- a/rust/kernel/alloc/kbox.rs
>>> +++ b/rust/kernel/alloc/kbox.rs
>>> @@ -213,6 +213,14 @@ pub fn leak<'a>(b: Self) -> &'a mut T {
>>> // which points to an initialized instance of `T`.
>>> unsafe { &mut *Box::into_raw(b) }
>>> }
>>> +
>>> + /// Consumes the `Box<T,A>` and returns a `NonNull<T>`.
>>> + ///
>>> + /// Like [`Self::into_raw`], but returns a `NonNull`.
>>> + pub fn into_nonnull(b: Self) -> NonNull<T> {
>>> + // SAFETY: `KBox::into_raw` returns a valid pointer.
>>> + unsafe { NonNull::new_unchecked(Self::into_raw(b)) }
>>> + }
>>
>> Hi Andreas,
>>
>> It looks like this patch and many others in the series are missing `#[inline]`
>> for quite a few very simple functions. Could you go through the series and mark
>> small functions as such?
>
> Sure.
>
> Could you remind me why we need this directive? Would the compiler not
> be able to decide?
`#[inline]` is a hint to make it more likely for compilers to inline. Without
them, you're relying on compiler heurstics only. There're cases (especially with
abstractions) where the function may look complex as it contains lots of
function calls (so compiler heurstics avoid inlining them), but they're all
zero-cost abstractions so eventually things get optimized away.
For non-generic functions, there is additional issue where only very small
functions get automatically inlined, otherwise a single copy is generated at the
defining crate and compiler run on a dependant crate has no chance to even peek
what's in the function.
If you know a function should be inlined, it's better to just mark them as such,
so there're no surprises.
Best,
Gary
>
> I know we have an issue when we have call to C function in short
> functions, but not in the general case?
>
>
> Best regards,
> Andreas Hindborg
next prev parent reply other threads:[~2026-03-01 19:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-24 11:17 [PATCH v16 00/10] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-02-24 11:17 ` [PATCH v16 01/10] rust: alloc: add `KBox::into_nonnull` Andreas Hindborg
2026-03-01 13:26 ` Gary Guo
2026-03-01 16:34 ` Andreas Hindborg
2026-03-01 19:25 ` Gary Guo [this message]
2026-03-01 19:59 ` Benno Lossin
2026-03-01 20:47 ` Gary Guo
2026-02-24 11:17 ` [PATCH v16 02/10] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-02-24 11:17 ` [PATCH v16 03/10] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-02-24 11:17 ` [PATCH v16 04/10] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 05/10] rust: aref: update formatting of use statements Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 06/10] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 07/10] rust: page: update formatting of `use` statements Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 08/10] rust: page: convert to `Ownable` Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 09/10] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-02-24 11:18 ` [PATCH v16 10/10] rust: page: add `from_raw()` Andreas Hindborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DGROXQD756OU.T2CRAPKA2HCB@garyguo.net \
--to=gary@garyguo.net \
--cc=Liam.Howlett@oracle.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david.m.ertman@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=igor.korotin.linux@gmail.com \
--cc=ira.weiny@intel.com \
--cc=jack@suse.cz \
--cc=kwilczynski@kernel.org \
--cc=leon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=lossin@kernel.org \
--cc=nm@ti.com \
--cc=ojeda@kernel.org \
--cc=paul@paul-moore.com \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=sergeh@kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
--cc=vireshk@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox