NewswireScienceStartupsTechnology

Linux 7.0 to Boost Rust & LTO Kernel Build Performance

▼ Summary

– Alice Ryhl of Google is improving the Linux kernel to allow C helper functions to be inlined into Rust code when using Link-Time Optimization (LTO) builds.
– This requires adding a “__rust_helper” annotation to Rust helpers because LLVM’s LTO currently prevents C inlining due to differing code generation options.
– During LTO builds, “__always_inline” will be applied to these helpers, with a specific exception to avoid issues when running the bindgen tool.
– A 46-patch series implements this change, which subsystem maintainers can merge independently, with some already queued for the Linux 6.20~7.0 cycle.
– Initial patches have been accepted into the VFS subsystem’s development branch, and the full series’ integration timeline for the next kernel cycle remains to be seen.

The upcoming Linux 7.0 kernel cycle is set to deliver a significant performance boost for builds that utilize both Rust and Link-Time Optimization (LTO). This improvement stems from work by Alice Ryhl at Google, who has developed patches enabling the inlining of C helper functions into Rust code during LTO builds. Previously, this inlining was blocked due to subtle differences in how LLVM handles code generation units, but the new approach resolves the issue. At least some of these performance-enhancing patches are already queued for integration in the Linux 6.20 to 7.0 development window.

The core technical challenge involved the fact that C helpers could not be inlined into Rust when using LTO because the LLVM compiler detected slightly different options on the respective code generation units. The solution introduces a new `rusthelper` annotation that must be applied to every relevant Rust helper function within the kernel source. To ensure proper inlining during an LTO build, the `alwaysinline` attribute will be automatically added to these helpers. A specific exception is made when the `bindgen` tool is running, to avoid a known issue where it ignores functions marked as inline.

Implementing this change across the entire kernel codebase is a substantial undertaking, represented by a series of 46 patches. These modifications do not need to be merged all at once; subsystem maintainers can adopt them independently. Notably, the VFS (Virtual File System) subsystem has already begun integrating these changes via its `vfs-7.0.rust` Git branch. While the full patch series may take time to be fully upstreamed, the foundational wiring for the `rust_helper` behavior is expected to land in the next kernel cycle.

This advancement is particularly meaningful for developers and organizations leveraging the kernel’s Rust support while seeking maximum performance through LTO builds. Link-Time Optimization, when used with the LLVM/Clang toolchain, has demonstrated meaningful performance benefits for compiled Linux kernels in recent benchmarks. By removing the barrier to inlining between C and Rust components, this work ensures that LTO can deliver its full potential in increasingly heterogeneous kernel environments, paving the way for more efficient and performant systems.

(Source: Phoronix)

Topics

linux kernel 95% rust integration 90% link-time optimization 88% c helpers 85% code inlining 82% llvm/clang 80% kernel patches 78% performance optimization 75% kernel development 72% git branches 68%