Re: [PATCH] mm: Inline vma_needs_copy

From: David Hildenbrand
Date: Wed Jun 18 2025 - 06:11:21 EST


On 18.06.25 11:39, Vlastimil Babka wrote:
On 6/18/25 3:42 AM, Yunshui Jiang wrote:
From: jiangyunshui <jiangyunshui@xxxxxxxxxx>

Since commit bcd51a3c679d ("hugetlb: lazy page table copies
in fork()"), the logic about judging whether to copy
page table inside func copy_page_range has been extracted
into a separate func vma_needs_copy. While this change
improves code readability, it also incurs more function call
overhead, especially where fork() were frequently called.

Inline func vma_needs_copy to optimize the copy_page_range
performance. Given that func vma_needs_copy is only called
by copy_page_range, inlining it would not cause unacceptable
code bloat.

I'm surprised the compiler doesn't inline it already, if there's a
single caller. In fact, mine (gcc-14.3 on x86) already does.

Same here

gcc (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)

So I wonder to which extent should we force override wrong compiler
heuristics?

I think only where we (a) really know better (b) it's crucial for performance and (c) modern compilers don't do the right thing.

Maybe just inline instead of __always_inline would be OK? Is
that enough of a hint for your compiler?

I would do the same thing (inline as a hint), but some people apparently recently argued that newer compiler mostly ignore it either way. At least that's what I recall.

--
Cheers,

David / dhildenb