Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

I Hsin Cheng and committed by
Joel Fernandes
9520371e da6b8559

+5
+5
rust/kernel/sync/rcu.rs
··· 17 17 18 18 impl Guard { 19 19 /// Acquires the RCU read side lock and returns a guard. 20 + #[inline] 20 21 pub fn new() -> Self { 21 22 // SAFETY: An FFI call with no additional requirements. 22 23 unsafe { bindings::rcu_read_lock() }; ··· 26 25 } 27 26 28 27 /// Explicitly releases the RCU read side lock. 28 + #[inline] 29 29 pub fn unlock(self) {} 30 30 } 31 31 32 32 impl Default for Guard { 33 + #[inline] 33 34 fn default() -> Self { 34 35 Self::new() 35 36 } 36 37 } 37 38 38 39 impl Drop for Guard { 40 + #[inline] 39 41 fn drop(&mut self) { 40 42 // SAFETY: By the type invariants, the RCU read side is locked, so it is ok to unlock it. 41 43 unsafe { bindings::rcu_read_unlock() }; ··· 46 42 } 47 43 48 44 /// Acquires the RCU read side lock. 45 + #[inline] 49 46 pub fn read_lock() -> Guard { 50 47 Guard::new() 51 48 }