Skip to content

Commit f45c836

Browse files
KunWuChanriteshharjani
authored andcommitted
rust: file: optimize rust symbol generation for FileDescriptorReservation
When build the kernel using the llvm-18.1.3-rust-1.85.0-x86_64 with ARCH=arm64, the following symbols are generated: $ nm vmlinux | grep ' _R'.*FileDescriptorReservation | rustfilt ... T <kernel::fs::file::FileDescriptorReservation>::fd_install ... T <kernel::fs::file::FileDescriptorReservation>::get_unused_fd_flags ... T <kernel::fs::file::FileDescriptorReservation as core::ops::drop::Drop>::drop These Rust symbols are trivial wrappers around the C functions fd_install, put_unused_fd and put_task_struct. It doesn't make sense to go through a trivial wrapper for these functions, so mark them inline. Link: Rust-for-Linux#1145 Suggested-by: Alice Ryhl <[email protected]> Co-developed-by: Grace Deng <[email protected]> Signed-off-by: Grace Deng <[email protected]> Signed-off-by: Kunwu Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Alice Ryhl <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 225eeac commit f45c836

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rust/kernel/fs/file.rs

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ pub struct FileDescriptorReservation {
392392

393393
impl FileDescriptorReservation {
394394
/// Creates a new file descriptor reservation.
395+
#[inline]
395396
pub fn get_unused_fd_flags(flags: u32) -> Result<Self> {
396397
// SAFETY: FFI call, there are no safety requirements on `flags`.
397398
let fd: i32 = unsafe { bindings::get_unused_fd_flags(flags) };
@@ -405,6 +406,7 @@ impl FileDescriptorReservation {
405406
}
406407

407408
/// Returns the file descriptor number that was reserved.
409+
#[inline]
408410
pub fn reserved_fd(&self) -> u32 {
409411
self.fd
410412
}
@@ -413,6 +415,7 @@ impl FileDescriptorReservation {
413415
///
414416
/// The previously reserved file descriptor is bound to `file`. This method consumes the
415417
/// [`FileDescriptorReservation`], so it will not be usable after this call.
418+
#[inline]
416419
pub fn fd_install(self, file: ARef<File>) {
417420
// SAFETY: `self.fd` was previously returned by `get_unused_fd_flags`. We have not yet used
418421
// the fd, so it is still valid, and `current` still refers to the same task, as this type
@@ -433,6 +436,7 @@ impl FileDescriptorReservation {
433436
}
434437

435438
impl Drop for FileDescriptorReservation {
439+
#[inline]
436440
fn drop(&mut self) {
437441
// SAFETY: By the type invariants of this type, `self.fd` was previously returned by
438442
// `get_unused_fd_flags`. We have not yet used the fd, so it is still valid, and `current`

0 commit comments

Comments
 (0)