* [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
@ 2026-06-11 19:05 Gary Guo
2026-06-11 23:01 ` Alice Ryhl
2026-06-12 4:40 ` Alexandre Courbot
0 siblings, 2 replies; 3+ 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] 3+ 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
1 sibling, 0 replies; 3+ 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] 3+ 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
1 sibling, 0 replies; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2026-06-12 4:41 UTC | newest]
Thread overview: 3+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox