Re: [PATCH v2 0/3] Inline helpers into Rust without full LTO

From: Andreas Hindborg

Date: Tue Mar 17 2026 - 04:26:04 EST


Alice Ryhl <aliceryhl@xxxxxxxxxx> writes:

> Currently the only way for Rust code to call a static inline function is
> to go through a helper in rust/helpers/. This introduces performance
> costs due to additional function calls and also clutters backtraces and
> flame graphs with helper symbols.
>
> To get rid of these helper symbols, provide functionality to inline
> helpers into Rust using llvm-link. This option complements full LTO, by
> being much cheaper and avoiding incompatibility with BTF.
>
> I ran a microbenchmark showing the benefit of this. All the benchmark
> does is call refcount_inc() in a loop. This was chosen since refcounting
> is quite hot in Binder. The results are that Rust spends 6.35 ns per
> call vs 5.73 ns per call in C. When enabling this option, the two
> languages become equally fast, and disassembly confirms the exact same
> machine code is used (in particular there is no call to
> rust_helper_refcount_inc). Benchmarking Binder also results in an
> improvement from this change.
>
> This patch is complementary to:
> https://lore.kernel.org/all/20251202-define-rust-helper-v1-0-a2e13cbc17a6@xxxxxxxxxx/
>
> Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>


Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

Tested with the rust null block driver patch series [1]. I did a
few functional verification tests and a set of performance tests.

For the rnull driver, enabling helper inlining with this patch gives an
average speedup of 2% over the set of 120 workloads that we publish on
[2].

Best regards,
Andreas Hindborg

[1] https://lore.kernel.org/rust-for-linux/20260216-rnull-v6-19-rc5-send-v1-0-de9a7af4b469@xxxxxxxxxx/
[2] https://rust-for-linux.com/null-block-driver