Re: [PATCH v2 3/3] rust: alloc: make `ReallocFunc::call` inline

From: Boqun Feng
Date: Mon Jan 06 2025 - 12:42:52 EST


On Sun, Jan 05, 2025 at 07:40:06PM +0000, Gary Guo wrote:
> This function can be called with different function pointers when
> different allocator (e.g. Kmalloc, Vmalloc, KVmalloc), however since
> this function is not polymorphic, only one instance is generated,
> and function pointers are used. Given that this function is called
> for any Rust-side allocation/deallocation, performance matters a lot,
> so making this function inlineable.
>
> This is discovered when doing helper inlining work, since it's discovered
> that even with helpers inlined, rust_helper_ symbols are still present
> in final vmlinux binary, and it turns out this function is inhibiting
> the inlining, and introducing indirect function calls.
>
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>

Reviewed-by: Boqun Feng <boqun.feng@xxxxxxxxx>

This should go in even without the first 2 patches, right?

Regards,
Boqun

> ---
> rust/kernel/alloc/allocator.rs | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/rust/kernel/alloc/allocator.rs b/rust/kernel/alloc/allocator.rs
> index 439985e29fbc..aa2dfa9dca4c 100644
> --- a/rust/kernel/alloc/allocator.rs
> +++ b/rust/kernel/alloc/allocator.rs
> @@ -80,6 +80,7 @@ impl ReallocFunc {
> /// This method has the same guarantees as `Allocator::realloc`. Additionally
> /// - it accepts any pointer to a valid memory allocation allocated by this function.
> /// - memory allocated by this function remains valid until it is passed to this function.
> + #[inline]
> unsafe fn call(
> &self,
> ptr: Option<NonNull<u8>>,
> --
> 2.47.0
>