Skip to contentSkip to conversation

mm: always inline _compound_head() with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP=y

PATCH Applied David Hildenbrand 2 participants 2 messages Aug 20, 2024 – Aug 21, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: always inline _compound_head() with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP=y

We already force-inline page_fixed_fake_head(), page_is_fake_head() and PageTail(), however the compiler might decide that _compound_head() is not worthy to be inlined, because of page_fixed_fake_head().

The result is that, for example, PageAnonExclusive() now might involve a function call when checking PageHuge(), which performs a page_folio()->_compound_head() call. This can lead to a slight regression of the stress-ng.clone benchmark.

This is not super-urgent to fix, but always inlining _compound_head() seems like the obvious thing to do for this primitive, similar to the other ones.

This change restores the slight regression and a compilation with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP=y shows no relevant bloat [2]:

	add/remove: 15/14 grow/shrink: 79/87 up/down: 12836/-13917 (-1081)
	...
	Total: Before=32786363, After=32785282, chg -0.00%

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lore.kernel.org/all/[email protected]/

Fixes c0bff412e67b ("mm: allow anon exclusive check over hugetlb tail pages")
Cc Andrew Morton <[email protected]>
Cc Peter Xu <[email protected]>
---
 include/linux/page-flags.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/page-flags.h +1 -1
index b753d158762fc..af58b2ad854c3 100644
@@ -233,7 +233,7 @@ static __always_inline int page_is_fake_head(const struct page *page)
 	return page_fixed_fake_head(page) != page;
 }
 
-static inline unsigned long _compound_head(const struct page *page)
+static __always_inline unsigned long _compound_head(const struct page *page)
 {
 	unsigned long head = READ_ONCE(page->compound_head);
 
Signature · 1 line
2.46.0
Tested-by on v1 1/1
#1 lore raw
Quoted 38 lines · David Hildenbrand

We already force-inline page_fixed_fake_head(), page_is_fake_head() and PageTail(), however the compiler might decide that _compound_head() is not worthy to be inlined, because of page_fixed_fake_head().

The result is that, for example, PageAnonExclusive() now might involve a function call when checking PageHuge(), which performs a page_folio()->_compound_head() call. This can lead to a slight regression of the stress-ng.clone benchmark.

This is not super-urgent to fix, but always inlining _compound_head() seems like the obvious thing to do for this primitive, similar to the other ones.

This change restores the slight regression and a compilation with CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP=y shows no relevant bloat [2]:

	add/remove: 15/14 grow/shrink: 79/87 up/down: 12836/-13917 (-1081)
	...
	Total: Before=32786363, After=32785282, chg -0.00%

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lore.kernel.org/all/[email protected]/

Fixes c0bff412e67b ("mm: allow anon exclusive check over hugetlb tail pages")
Cc Andrew Morton <[email protected]>
Cc Peter Xu <[email protected]>
---
  include/linux/page-flags.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/page-flags.h +0 -0
index b753d158762fc..af58b2ad854c3 100644

include/linux/page-flags.h static __always_inline int page_is_fake_head(const struct page *page) · line 239

Quoted 8 lines
include/linux/page-flags.h +1 -1
@@ -233,7 +233,7 @@ static __always_inline int page_is_fake_head(const struct page *page)
  	return page_fixed_fake_head(page) != page;
  }
 
-static inline unsigned long _compound_head(const struct page *page)
+static __always_inline unsigned long _compound_head(const struct page *page)
  {
  	unsigned long head = READ_ONCE(page->compound_head);
 

Regards
Yin, Fengwei