* [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
@ 2026-06-11 19:05 Gary Guo
2026-06-11 23:01 ` Alice Ryhl
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Gary Guo @ 2026-06-11 19:05 UTC (permalink / raw)
To: Alexandre Courbot, Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich
Cc: rust-for-linux, linux-kernel
From: Gary Guo <gary@garyguo.net>
A `Debug` impl is for debugging and is normally not used, and therefore
should ideally not be code-generated unless used. However, Rust has no way
of knowing if a dependent crate is going to use the trait impl or not, so
unless it is marked as `#[inline]`, it will be code-generated in the
defining crate (as it is not generic).
Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
in the binary unless used.
This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/bitfield.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
index 554a5a2ff0ab..35ede53f2b8e 100644
--- a/rust/kernel/bitfield.rs
+++ b/rust/kernel/bitfield.rs
@@ -535,6 +535,7 @@ const fn [<__with_ $field>](
// `Debug` implementation.
(@debug $name:ident { $($field:ident;)* }) => {
impl ::kernel::fmt::Debug for $name {
+ #[inline]
fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result {
f.debug_struct(stringify!($name))
.field("<raw>", &::kernel::prelude::fmt!("{:#x}", self.inner))
base-commit: 7f07865bda5f5770d2f7927bc76cb2b4acd46074
--
2.54.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
2026-06-11 19:05 [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]` Gary Guo
@ 2026-06-11 23:01 ` Alice Ryhl
2026-06-12 4:40 ` Alexandre Courbot
2026-06-13 8:24 ` Miguel Ojeda
2 siblings, 0 replies; 6+ messages in thread
From: Alice Ryhl @ 2026-06-11 23:01 UTC (permalink / raw)
To: Gary Guo
Cc: Alexandre Courbot, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel
On Thu, Jun 11, 2026 at 08:05:54PM +0100, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
>
> A `Debug` impl is for debugging and is normally not used, and therefore
> should ideally not be code-generated unless used. However, Rust has no way
> of knowing if a dependent crate is going to use the trait impl or not, so
> unless it is marked as `#[inline]`, it will be code-generated in the
> defining crate (as it is not generic).
>
> Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
> in the binary unless used.
>
> This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
>
> Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
2026-06-11 19:05 [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]` Gary Guo
2026-06-11 23:01 ` Alice Ryhl
@ 2026-06-12 4:40 ` Alexandre Courbot
2026-06-13 5:43 ` Alexandre Courbot
2026-06-13 8:24 ` Miguel Ojeda
2 siblings, 1 reply; 6+ messages in thread
From: Alexandre Courbot @ 2026-06-12 4:40 UTC (permalink / raw)
To: Gary Guo
Cc: Gary Guo, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel
On Fri Jun 12, 2026 at 4:05 AM JST, Gary Guo wrote:
> From: Gary Guo <gary@garyguo.net>
>
> A `Debug` impl is for debugging and is normally not used, and therefore
> should ideally not be code-generated unless used. However, Rust has no way
> of knowing if a dependent crate is going to use the trait impl or not, so
> unless it is marked as `#[inline]`, it will be code-generated in the
> defining crate (as it is not generic).
>
> Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
> in the binary unless used.
>
> This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
>
> Signed-off-by: Gary Guo <gary@garyguo.net>
Ouch, well-spotted. Thanks for this.
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
2026-06-12 4:40 ` Alexandre Courbot
@ 2026-06-13 5:43 ` Alexandre Courbot
2026-06-13 8:25 ` Miguel Ojeda
0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Courbot @ 2026-06-13 5:43 UTC (permalink / raw)
To: Gary Guo
Cc: Gary Guo, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel
On Fri Jun 12, 2026 at 1:40 PM JST, Alexandre Courbot wrote:
> On Fri Jun 12, 2026 at 4:05 AM JST, Gary Guo wrote:
>> From: Gary Guo <gary@garyguo.net>
>>
>> A `Debug` impl is for debugging and is normally not used, and therefore
>> should ideally not be code-generated unless used. However, Rust has no way
>> of knowing if a dependent crate is going to use the trait impl or not, so
>> unless it is marked as `#[inline]`, it will be code-generated in the
>> defining crate (as it is not generic).
>>
>> Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
>> in the binary unless used.
>>
>> This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
>>
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>
> Ouch, well-spotted. Thanks for this.
>
> Acked-by: Alexandre Courbot <acourbot@nvidia.com>
Btw, should this be
Fixes: b7b8b4ccdad4 ("rust: extract `bitfield!` macro from `register!`")
?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
2026-06-11 19:05 [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]` Gary Guo
2026-06-11 23:01 ` Alice Ryhl
2026-06-12 4:40 ` Alexandre Courbot
@ 2026-06-13 8:24 ` Miguel Ojeda
2 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-06-13 8:24 UTC (permalink / raw)
To: Gary Guo
Cc: Alexandre Courbot, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel
On Thu, Jun 11, 2026 at 9:06 PM Gary Guo <gary@kernel.org> wrote:
>
> This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).
That's definitely something :)
I wonder if we could lint this for `fmt` bits.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
2026-06-13 5:43 ` Alexandre Courbot
@ 2026-06-13 8:25 ` Miguel Ojeda
0 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-06-13 8:25 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Gary Guo, Gary Guo, Yury Norov, Miguel Ojeda, Boqun Feng,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, rust-for-linux, linux-kernel
On Sat, Jun 13, 2026 at 7:43 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> Btw, should this be
>
> Fixes: b7b8b4ccdad4 ("rust: extract `bitfield!` macro from `register!`")
>
> ?
I think it is reasonable either way. One can see it as a "size
improvement" or as a "fix" if it was unintentional to not have the
annotation.
It also depends on the magnitude of the size reduction -- if it were
very low, would we see it as a fix?
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-13 8:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 19:05 [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]` Gary Guo
2026-06-11 23:01 ` Alice Ryhl
2026-06-12 4:40 ` Alexandre Courbot
2026-06-13 5:43 ` Alexandre Courbot
2026-06-13 8:25 ` Miguel Ojeda
2026-06-13 8:24 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox