Skip to content

Commit 05d7ab2

Browse files
vax-rintel-lab-lkp
authored andcommitted
rust: sync: rcu: Mark Guard methods as inline
Currenyly 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 100 bytes. $ ./scripts/bloat-o-meter vmlinux_old vmlinux_new add/remove: 0/8 grow/shrink: 0/0 up/down: 0/-100 (-100) Function old new delta _RNvXs_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB4_5GuardNtNtCsdaXADs8PRFB_4core7default7Default7default 9 - -9 _RNvXs0_NtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB5_5GuardNtNtNtCsdaXADs8PRFB_4core3ops4drop4Drop4drop 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__RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard6unlock 16 - -16 __pfx__RNvMNtNtCsaYBeKL739Xz_6kernel4sync3rcuNtB2_5Guard3new 16 - -16 Total: Before=23385830, After=23385730, chg -0.00% Link: Rust-for-Linux#1145 Signed-off-by: I Hsin Cheng <[email protected]>
1 parent 69aa487 commit 05d7ab2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rust/kernel/sync/rcu.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Guard(NotThreadSafe);
1717

1818
impl Guard {
1919
/// Acquires the RCU read side lock and returns a guard.
20+
#[inline]
2021
pub fn new() -> Self {
2122
// SAFETY: An FFI call with no additional requirements.
2223
unsafe { bindings::rcu_read_lock() };
@@ -25,16 +26,19 @@ impl Guard {
2526
}
2627

2728
/// Explicitly releases the RCU read side lock.
29+
#[inline]
2830
pub fn unlock(self) {}
2931
}
3032

3133
impl Default for Guard {
34+
#[inline]
3235
fn default() -> Self {
3336
Self::new()
3437
}
3538
}
3639

3740
impl Drop for Guard {
41+
#[inline]
3842
fn drop(&mut self) {
3943
// SAFETY: By the type invariants, the RCU read side is locked, so it is ok to unlock it.
4044
unsafe { bindings::rcu_read_unlock() };

0 commit comments

Comments
 (0)