* [PATCH v2] rust: sync: rcu: Mark Guard methods as inline
@ 2025-03-19 2:26 I Hsin Cheng
2025-03-21 20:40 ` Joel Fernandes
0 siblings, 1 reply; 2+ messages in thread
From: I Hsin Cheng @ 2025-03-19 2:26 UTC (permalink / raw)
To: rostedt
Cc: paulmck, frederic, neeraj.upadhyay, joel, josh, boqun.feng,
urezki, mathieu.desnoyers, jiangshanlai, qiang.zhang1211, ojeda,
alex.gaynor, gary, bjorn3_gh, benno.lossin, a.hindborg, aliceryhl,
tmgross, dakr, rcu, rust-for-linux, linux-kernel, skhan,
linux-kernel-mentees, jserv, I Hsin Cheng
Currently the implementation of "Guard" methods are basically wrappers
around rcu's function within kernel. Building the kernel with llvm
18.1.8 on x86_64 machine will generate the following symbols:
$ nm vmlinux | grep ' _R'.*Guard | rustfilt
ffffffff817b6c90 T <kernel::sync::rcu::Guard>::new
ffffffff817b6cb0 T <kernel::sync::rcu::Guard>::unlock
ffffffff817b6cd0 T <kernel::sync::rcu::Guard as core::ops::drop::Drop>::drop
ffffffff817b6c90 T <kernel::sync::rcu::Guard as core::default::Default>::default
These Rust symbols are basically wrappers around functions
"rcu_read_lock" and "rcu_read_unlock". Marking them as inline can
reduce the generation of these symbols, and saves the size of code
generation for 132 bytes.
$ ./scripts/bloat-o-meter vmlinux_old vmlinux_new
add/remove: 0/10 grow/shrink: 0/1 up/down: 0/-132 (-132)
Function old new delta
_RNvXs1_Cs4gouIKNZ4iT_15rust_driver_pciNtB5_12SampleDriverNtNtCsaYBeKL739Xz_6kernel3pci6Driver5probe 1041 1034 -7
_RNvXs_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB4_5GuardNtNtCsdaXADs8PRFB_4core7default7Default7default 9 - -9
_RNvXs0_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB5_5GuardNtNtNtCsdaXADs8PRFB_4core3ops4drop4Drop4drop 9 - -9
_RNvNtNtCsaYBeKL739Xz_6kernel4sync3rcu9read_lock 9 - -9
_RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard6unlock 9 - -9
_RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard3new 9 - -9
__pfx__RNvXs_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB4_5GuardNtNtCsdaXADs8PRFB_4core7default7Default7default 16 - -16
__pfx__RNvXs0_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB5_5GuardNtNtNtCsdaXADs8PRFB_4core3ops4drop4Drop4drop 16 - -16
__pfx__RNvNtNtCsaYBeKL739Xz_6kernel4sync3rcu9read_lock 16 - -16
__pfx__RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard6unlock 16 - -16
__pfx__RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard3new 16 - -16
Total: Before=23365955, After=23365823, chg -0.00%
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
Changelog:
v1 -> v2:
- Mark read_lock() as inline as well
- Fix typos
---
rust/kernel/sync/rcu.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs
index b51d9150ffe2..a32bef6e490b 100644
--- a/rust/kernel/sync/rcu.rs
+++ b/rust/kernel/sync/rcu.rs
@@ -17,6 +17,7 @@
impl Guard {
/// Acquires the RCU read side lock and returns a guard.
+ #[inline]
pub fn new() -> Self {
// SAFETY: An FFI call with no additional requirements.
unsafe { bindings::rcu_read_lock() };
@@ -25,16 +26,19 @@ pub fn new() -> Self {
}
/// Explicitly releases the RCU read side lock.
+ #[inline]
pub fn unlock(self) {}
}
impl Default for Guard {
+ #[inline]
fn default() -> Self {
Self::new()
}
}
impl Drop for Guard {
+ #[inline]
fn drop(&mut self) {
// SAFETY: By the type invariants, the RCU read side is locked, so it is ok to unlock it.
unsafe { bindings::rcu_read_unlock() };
@@ -42,6 +46,7 @@ fn drop(&mut self) {
}
/// Acquires the RCU read side lock.
+#[inline]
pub fn read_lock() -> Guard {
Guard::new()
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] rust: sync: rcu: Mark Guard methods as inline
2025-03-19 2:26 [PATCH v2] rust: sync: rcu: Mark Guard methods as inline I Hsin Cheng
@ 2025-03-21 20:40 ` Joel Fernandes
0 siblings, 0 replies; 2+ messages in thread
From: Joel Fernandes @ 2025-03-21 20:40 UTC (permalink / raw)
To: I Hsin Cheng
Cc: rostedt, paulmck, frederic, neeraj.upadhyay, joel, josh,
boqun.feng, urezki, mathieu.desnoyers, jiangshanlai,
qiang.zhang1211, ojeda, alex.gaynor, gary, bjorn3_gh,
benno.lossin, a.hindborg, aliceryhl, tmgross, dakr, rcu,
rust-for-linux, linux-kernel, skhan, linux-kernel-mentees, jserv
On Wed, Mar 19, 2025 at 10:26:40AM +0800, I Hsin Cheng wrote:
> Currently the implementation of "Guard" methods are basically wrappers
> around rcu's function within kernel. Building the kernel with llvm
> 18.1.8 on x86_64 machine will generate the following symbols:
>
> $ nm vmlinux | grep ' _R'.*Guard | rustfilt
> ffffffff817b6c90 T <kernel::sync::rcu::Guard>::new
> ffffffff817b6cb0 T <kernel::sync::rcu::Guard>::unlock
> ffffffff817b6cd0 T <kernel::sync::rcu::Guard as core::ops::drop::Drop>::drop
> ffffffff817b6c90 T <kernel::sync::rcu::Guard as core::default::Default>::default
>
> These Rust symbols are basically wrappers around functions
> "rcu_read_lock" and "rcu_read_unlock". Marking them as inline can
> reduce the generation of these symbols, and saves the size of code
> generation for 132 bytes.
>
> $ ./scripts/bloat-o-meter vmlinux_old vmlinux_new
[..]
I am queuing this version for 6.16, please in the future add all reviewed-by
and acked-by tags on resubmissions. This time I added it.
Also I fixed up the demanging to make the change log look less ugly, let me
know if it doesn't look Ok.
------------8<-------------
From: I Hsin Cheng <richard120310@gmail.com>
Subject: [PATCH v2] rust: sync: rcu: Mark Guard methods as inline
Currently the implementation of "Guard" methods are basically wrappers
around rcu's function within kernel. Building the kernel with llvm
18.1.8 on x86_64 machine will generate the following symbols:
$ nm vmlinux | grep ' _R'.*Guard | rustfilt
ffffffff817b6c90 T <kernel::sync::rcu::Guard>::new
ffffffff817b6cb0 T <kernel::sync::rcu::Guard>::unlock
ffffffff817b6cd0 T <kernel::sync::rcu::Guard as core::ops::drop::Drop>::drop
ffffffff817b6c90 T <kernel::sync::rcu::Guard as core::default::Default>::default
These Rust symbols are basically wrappers around functions
"rcu_read_lock" and "rcu_read_unlock". Marking them as inline can
reduce the generation of these symbols, and saves the size of code
generation for 132 bytes.
$ ./scripts/bloat-o-meter vmlinux_old vmlinux_new
(Output is demangled for readability)
add/remove: 0/10 grow/shrink: 0/1 up/down: 0/-132 (-132)
Function old new delta
rust_driver_pci::SampleDriver::probe 1041 1034 -7
kernel::sync::rcu::Guard::default 9 - -9
kernel::sync::rcu::Guard::drop 9 - -9
kernel::sync::rcu::read_lock 9 - -9
kernel::sync::rcu::Guard::unlock 9 - -9
kernel::sync::rcu::Guard::new 9 - -9
__pfx__kernel::sync::rcu::Guard::default 16 - -16
__pfx__kernel::sync::rcu::Guard::drop 16 - -16
__pfx__kernel::sync::rcu::read_lock 16 - -16
__pfx__kernel::sync::rcu::Guard::unlock 16 - -16
__pfx__kernel::sync::rcu::Guard::new 16 - -16
Total: Before=23365955, After=23365823, chg -0.00%
Link: https://github.com/Rust-for-Linux/linux/issues/1145
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Charalampos Mitrodimas <charmitro@posteo.net>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
rust/kernel/sync/rcu.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs
index b51d9150ffe2..a32bef6e490b 100644
--- a/rust/kernel/sync/rcu.rs
+++ b/rust/kernel/sync/rcu.rs
@@ -17,6 +17,7 @@
impl Guard {
/// Acquires the RCU read side lock and returns a guard.
+ #[inline]
pub fn new() -> Self {
// SAFETY: An FFI call with no additional requirements.
unsafe { bindings::rcu_read_lock() };
@@ -25,16 +26,19 @@ pub fn new() -> Self {
}
/// Explicitly releases the RCU read side lock.
+ #[inline]
pub fn unlock(self) {}
}
impl Default for Guard {
+ #[inline]
fn default() -> Self {
Self::new()
}
}
impl Drop for Guard {
+ #[inline]
fn drop(&mut self) {
// SAFETY: By the type invariants, the RCU read side is locked, so it is ok to unlock it.
unsafe { bindings::rcu_read_unlock() };
@@ -42,6 +46,7 @@ fn drop(&mut self) {
}
/// Acquires the RCU read side lock.
+#[inline]
pub fn read_lock() -> Guard {
Guard::new()
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-21 20:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 2:26 [PATCH v2] rust: sync: rcu: Mark Guard methods as inline I Hsin Cheng
2025-03-21 20:40 ` Joel Fernandes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).