* [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code
@ 2026-11-24 11:05 Muchun Song
2026-11-24 11:05 ` [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message Muchun Song
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
Hi,
This is based on the mm-new branch at commit 87cdbd9bd631.
HugeTLB vmemmap optimization has evolved over time, leaving obsolete
and duplicated logic spread across the implementation. This makes the
code harder to follow and obscures the contract shared by HugeTLB and
the generic vmemmap optimization helpers.
Simplify the code around that common contract and align the HVO
implementation with its current behavior.
The first five patches simplify the HugeTLB-specific implementation.
The final patch centralizes the support condition shared by HVO and the
generic compound-page helpers.
Muchun Song (6):
mm/hugetlb_vmemmap: remove the vmemmap savings boot message
mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers
mm/hugetlb_vmemmap: drop the redundant hstate argument
mm/hugetlb_vmemmap: open-code free_vmemmap_page()
mm/hugetlb_vmemmap: drop obsolete restore refcount warning
mm/vmemmap-optimization: centralize the vmemmap optimization support
check
include/linux/hugetlb.h | 2 +-
include/linux/page-flags.h | 10 +--
include/linux/vmemmap-optimization.h | 14 +---
mm/hugetlb.c | 14 ++--
mm/hugetlb_vmemmap.c | 96 +++++++++-------------------
mm/hugetlb_vmemmap.h | 45 ++++---------
6 files changed, 58 insertions(+), 123 deletions(-)
base-commit: 87cdbd9bd63174de47ba16555bfe9800a8f3da07
--
2.54.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
2026-11-24 11:16 ` sashiko-bot
2026-11-24 11:05 ` [PATCH 2/6] mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers Muchun Song
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
The boot message reports the potential vmemmap savings for each HugeTLB
page size. It is a static estimate and does not indicate whether HVO is
enabled or how much vmemmap memory is actually in use.
Users can query vm.hugetlb_optimize_vmemmap for the HVO enable policy
and inspect nr_memmap_pages and nr_memmap_boot_pages in /proc/vmstat
for the actual vmemmap usage.
Remove the boot message and hugetlb_vmemmap_optimizable_size(), which is
only used to calculate the reported estimate.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
include/linux/hugetlb.h | 2 +-
mm/hugetlb.c | 2 --
mm/hugetlb_vmemmap.h | 27 ++++-----------------------
3 files changed, 5 insertions(+), 26 deletions(-)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 0d5414392d87..b5b877ed5b92 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -812,7 +812,7 @@ static inline unsigned long huge_page_mask(struct hstate *h)
return h->mask;
}
-static inline unsigned int huge_page_order(struct hstate *h)
+static inline unsigned int huge_page_order(const struct hstate *h)
{
return h->order;
}
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index d0e66fb30622..0eddb8cee1eb 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -3720,8 +3720,6 @@ static void __init report_hugepages(void)
string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, sizeof(buf));
pr_info("registered %s page size, pre-allocated %ld pages\n",
buf, h->nr_huge_pages);
- pr_info("%d KiB vmemmap can be freed for a %s page\n",
- hugetlb_vmemmap_optimizable_size(h) / SZ_1K, buf);
}
}
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index 8b28063d78cc..b7781baa2ce0 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -33,23 +33,6 @@ static inline void hugetlb_vmemmap_write_unlock(void)
up_write(&vmemmap_remap_rwsem);
}
-static inline unsigned int hugetlb_vmemmap_size(const struct hstate *h)
-{
- return pages_per_huge_page(h) * sizeof(struct page);
-}
-
-/*
- * Return how many vmemmap size associated with a HugeTLB page that can be
- * optimized and can be freed to the buddy allocator.
- */
-static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
-{
- int size = hugetlb_vmemmap_size(h) - VMEMMAP_OPTIMIZATION_SIZE;
-
- if (!is_power_of_2(sizeof(struct page)))
- return 0;
- return size > 0 ? size : 0;
-}
#else
static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
{
@@ -80,11 +63,6 @@ static inline void hugetlb_vmemmap_write_unlock(void)
{
}
-static inline unsigned int hugetlb_vmemmap_optimizable_size(const struct hstate *h)
-{
- return 0;
-}
-
static inline void hugetlb_vmemmap_optimize_bootmem_page(unsigned long pfn, unsigned int order)
{
}
@@ -95,6 +73,9 @@ DEFINE_LOCK_GUARD_0(vmemmap_remap,
static inline bool hugetlb_vmemmap_optimizable(const struct hstate *h)
{
- return hugetlb_vmemmap_optimizable_size(h) != 0;
+ if (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP))
+ return false;
+
+ return vmemmap_optimizable_order(huge_page_order(h));
}
#endif /* _LINUX_HUGETLB_VMEMMAP_H */
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/6] mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
2026-11-24 11:05 ` [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
2026-11-24 11:05 ` [PATCH 3/6] mm/hugetlb_vmemmap: drop the redundant hstate argument Muchun Song
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
vmemmap_should_optimize_folio() combines the global HVO policy,
per-hstate eligibility, and the already-optimized state. The latter two
do not need to gate the normal flow: generic folio and section helpers
check order eligibility, while optimization entry points only receive
freshly initialized folios. Thus, only the global enable policy must be
checked at every entry point.
Fold the global enable check into each caller. Retain the per-hstate
check in hugetlb_vmemmap_optimize_folios() only as an optimization, so
an ineligible hstate is rejected before iterating the entire folio
list.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/hugetlb_vmemmap.c | 38 ++++++++++----------------------------
1 file changed, 10 insertions(+), 28 deletions(-)
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 09b9fd83c198..71aa340cce55 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -488,21 +488,6 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
return ret;
}
-/* Return true iff a HugeTLB whose vmemmap should and can be optimized. */
-static bool vmemmap_should_optimize_folio(const struct hstate *h, struct folio *folio)
-{
- if (folio_test_hugetlb_vmemmap_optimized(folio))
- return false;
-
- if (!READ_ONCE(vmemmap_optimize_enabled))
- return false;
-
- if (!hugetlb_vmemmap_optimizable(h))
- return false;
-
- return true;
-}
-
static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
struct folio *folio,
struct list_head *vmemmap_pages,
@@ -512,9 +497,6 @@ static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio);
- if (!vmemmap_should_optimize_folio(h, folio))
- return 0;
-
/*
* Very Subtle
* If VMEMMAP_DEFER_TLB_FLUSH is set, TLB flushing is not performed
@@ -548,32 +530,32 @@ void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)
{
LIST_HEAD(vmemmap_pages);
+ if (!READ_ONCE(vmemmap_optimize_enabled))
+ return;
+
guard(rwsem_read)(&vmemmap_remap_rwsem);
__hugetlb_vmemmap_optimize_folio(h, folio, &vmemmap_pages, 0);
free_vmemmap_page_list(&vmemmap_pages);
}
-static int hugetlb_vmemmap_pteify_folio(const struct hstate *h, struct folio *folio,
- unsigned long flags)
-{
- if (!vmemmap_should_optimize_folio(h, folio))
- return 0;
-
- return vmemmap_pteify_folio(folio, flags);
-}
-
void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list)
{
struct folio *folio;
LIST_HEAD(vmemmap_pages);
unsigned long flags = VMEMMAP_DEFER_TLB_FLUSH;
+ if (!READ_ONCE(vmemmap_optimize_enabled))
+ return;
+
+ if (!hugetlb_vmemmap_optimizable(h))
+ return;
+
if (list_empty(folio_list))
return;
down_write(&vmemmap_remap_rwsem);
list_for_each_entry(folio, folio_list, lru) {
- int ret = hugetlb_vmemmap_pteify_folio(h, folio, flags);
+ int ret = vmemmap_pteify_folio(folio, flags);
/*
* Splitting the PMD requires allocating a page, thus let's fail
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/6] mm/hugetlb_vmemmap: drop the redundant hstate argument
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
2026-11-24 11:05 ` [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message Muchun Song
2026-11-24 11:05 ` [PATCH 2/6] mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
2026-11-24 11:05 ` [PATCH 4/6] mm/hugetlb_vmemmap: open-code free_vmemmap_page() Muchun Song
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
The single-folio optimize path and the single- and multi-folio restore
paths derive the vmemmap range, order, and NUMA node directly from each
folio. Their hstate argument is therefore no longer used.
Remove it from those paths and their internal helpers. Update the
callers accordingly.
Keep the hstate argument in the bulk optimize path so an ineligible
hstate can be rejected before iterating and pteifying the folio list.
No functional change intended.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/hugetlb.c | 12 ++++++------
mm/hugetlb_vmemmap.c | 28 +++++++++++-----------------
mm/hugetlb_vmemmap.h | 18 ++++++++----------
3 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 0eddb8cee1eb..0475ee595406 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1519,7 +1519,7 @@ static void __update_and_free_hugetlb_folio(struct hstate *h,
* is no longer identified as a hugetlb page. hugetlb_vmemmap_restore_folio
* can only be passed hugetlb pages and will BUG otherwise.
*/
- if (clear_flag && hugetlb_vmemmap_restore_folio(h, folio)) {
+ if (clear_flag && hugetlb_vmemmap_restore_folio(folio)) {
spin_lock_irq(&hugetlb_lock);
/*
* If we cannot allocate vmemmap pages, just refuse to free the
@@ -1671,7 +1671,7 @@ static void bulk_vmemmap_restore_error(struct hstate *h,
* be freed without restoring vmemmap.
*/
if (folio_test_hugetlb(folio)) {
- if (hugetlb_vmemmap_restore_folio(h, folio)) {
+ if (hugetlb_vmemmap_restore_folio(folio)) {
spin_lock_irq(&hugetlb_lock);
add_hugetlb_folio(h, folio, true);
spin_unlock_irq(&hugetlb_lock);
@@ -1701,7 +1701,7 @@ static void update_and_free_pages_bulk(struct hstate *h,
* in an effort to make forward progress.
*/
retry:
- ret = hugetlb_vmemmap_restore_folios(h, folio_list, &non_hvo_folios);
+ ret = hugetlb_vmemmap_restore_folios(folio_list, &non_hvo_folios);
if (ret < 0) {
bulk_vmemmap_restore_error(h, folio_list, &non_hvo_folios);
goto retry;
@@ -1948,7 +1948,7 @@ static struct folio *alloc_fresh_hugetlb_folio(struct hstate *h,
folio = only_alloc_fresh_hugetlb_folio(h, gfp_mask, nid, nmask, NULL);
if (folio)
- hugetlb_vmemmap_optimize_folio(h, folio);
+ hugetlb_vmemmap_optimize_folio(folio);
return folio;
}
@@ -2117,7 +2117,7 @@ int dissolve_free_hugetlb_folio(struct folio *folio)
* non-vmemmap optimized hugetlb folios.
*/
if (folio_test_hugetlb(folio)) {
- rc = hugetlb_vmemmap_restore_folio(h, folio);
+ rc = hugetlb_vmemmap_restore_folio(folio);
if (rc) {
spin_lock_irq(&hugetlb_lock);
add_hugetlb_folio(h, folio, adjust_surplus);
@@ -3981,7 +3981,7 @@ static long demote_free_hugetlb_folios(struct hstate *src, struct hstate *dst,
LIST_HEAD(dst_list);
LIST_HEAD(ret_list);
- rc = hugetlb_vmemmap_restore_folios(src, src_list, &ret_list);
+ rc = hugetlb_vmemmap_restore_folios(src_list, &ret_list);
list_splice_init(&ret_list, src_list);
/*
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 71aa340cce55..4ed2db189f59 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -414,8 +414,7 @@ static int __init hugetlb_vmemmap_optimize_param(char *buf)
}
early_param("hugetlb_free_vmemmap", hugetlb_vmemmap_optimize_param);
-static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,
- struct folio *folio, unsigned long flags)
+static int __hugetlb_vmemmap_restore_folio(struct folio *folio, unsigned long flags)
{
int ret;
@@ -436,20 +435,18 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,
* hugetlb_vmemmap_restore_folio - restore previously optimized (by
* hugetlb_vmemmap_optimize_folio()) vmemmap pages which
* will be reallocated and remapped.
- * @h: struct hstate.
* @folio: the folio whose vmemmap pages will be restored.
*
* Return: %0 if @folio's vmemmap pages have been reallocated and remapped,
* negative error code otherwise.
*/
-int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
+int hugetlb_vmemmap_restore_folio(struct folio *folio)
{
- return __hugetlb_vmemmap_restore_folio(h, folio, 0);
+ return __hugetlb_vmemmap_restore_folio(folio, 0);
}
/**
* hugetlb_vmemmap_restore_folios - restore vmemmap for every folio on the list.
- * @h: hstate.
* @folio_list: list of folios.
* @non_hvo_folios: Output list of folios for which vmemmap exists.
*
@@ -460,9 +457,8 @@ int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
* encountered. The folio that experienced the error and all
* non-processed folios will remain on folio_list.
*/
-long hugetlb_vmemmap_restore_folios(const struct hstate *h,
- struct list_head *folio_list,
- struct list_head *non_hvo_folios)
+long hugetlb_vmemmap_restore_folios(struct list_head *folio_list,
+ struct list_head *non_hvo_folios)
{
struct folio *folio, *t_folio;
long restored = 0;
@@ -471,7 +467,7 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
list_for_each_entry_safe(folio, t_folio, folio_list, lru) {
if (folio_test_hugetlb_vmemmap_optimized(folio)) {
- ret = __hugetlb_vmemmap_restore_folio(h, folio, flags);
+ ret = __hugetlb_vmemmap_restore_folio(folio, flags);
if (ret)
break;
restored++;
@@ -488,8 +484,7 @@ long hugetlb_vmemmap_restore_folios(const struct hstate *h,
return ret;
}
-static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
- struct folio *folio,
+static int __hugetlb_vmemmap_optimize_folio(struct folio *folio,
struct list_head *vmemmap_pages,
unsigned long flags)
{
@@ -518,7 +513,6 @@ static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
/**
* hugetlb_vmemmap_optimize_folio - optimize @folio's vmemmap pages.
- * @h: struct hstate.
* @folio: the folio whose vmemmap pages will be optimized.
*
* This function only tries to optimize @folio's vmemmap pages and does not
@@ -526,7 +520,7 @@ static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,
* can use folio_test_hugetlb_vmemmap_optimized(@folio) to detect if @folio's
* vmemmap pages have been optimized.
*/
-void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)
+void hugetlb_vmemmap_optimize_folio(struct folio *folio)
{
LIST_HEAD(vmemmap_pages);
@@ -534,7 +528,7 @@ void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)
return;
guard(rwsem_read)(&vmemmap_remap_rwsem);
- __hugetlb_vmemmap_optimize_folio(h, folio, &vmemmap_pages, 0);
+ __hugetlb_vmemmap_optimize_folio(folio, &vmemmap_pages, 0);
free_vmemmap_page_list(&vmemmap_pages);
}
@@ -573,7 +567,7 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l
list_for_each_entry(folio, folio_list, lru) {
int ret;
- ret = __hugetlb_vmemmap_optimize_folio(h, folio, &vmemmap_pages, flags);
+ ret = __hugetlb_vmemmap_optimize_folio(folio, &vmemmap_pages, flags);
/*
* Pages to be freed may have been accumulated. If we
@@ -587,7 +581,7 @@ void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_l
flush_tlb_all();
free_vmemmap_page_list(&vmemmap_pages);
INIT_LIST_HEAD(&vmemmap_pages);
- __hugetlb_vmemmap_optimize_folio(h, folio, &vmemmap_pages, flags);
+ __hugetlb_vmemmap_optimize_folio(folio, &vmemmap_pages, flags);
}
}
diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h
index b7781baa2ce0..c75faf3e5510 100644
--- a/mm/hugetlb_vmemmap.h
+++ b/mm/hugetlb_vmemmap.h
@@ -15,11 +15,10 @@
#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
extern struct rw_semaphore vmemmap_remap_rwsem;
-int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio);
-long hugetlb_vmemmap_restore_folios(const struct hstate *h,
- struct list_head *folio_list,
- struct list_head *non_hvo_folios);
-void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio);
+int hugetlb_vmemmap_restore_folio(struct folio *folio);
+long hugetlb_vmemmap_restore_folios(struct list_head *folio_list,
+ struct list_head *non_hvo_folios);
+void hugetlb_vmemmap_optimize_folio(struct folio *folio);
void hugetlb_vmemmap_optimize_folios(struct hstate *h, struct list_head *folio_list);
void hugetlb_vmemmap_optimize_bootmem_page(unsigned long pfn, unsigned int order);
@@ -34,20 +33,19 @@ static inline void hugetlb_vmemmap_write_unlock(void)
}
#else
-static inline int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
+static inline int hugetlb_vmemmap_restore_folio(struct folio *folio)
{
return 0;
}
-static inline long hugetlb_vmemmap_restore_folios(const struct hstate *h,
- struct list_head *folio_list,
- struct list_head *non_hvo_folios)
+static inline long hugetlb_vmemmap_restore_folios(struct list_head *folio_list,
+ struct list_head *non_hvo_folios)
{
list_splice_init(folio_list, non_hvo_folios);
return 0;
}
-static inline void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)
+static inline void hugetlb_vmemmap_optimize_folio(struct folio *folio)
{
}
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/6] mm/hugetlb_vmemmap: open-code free_vmemmap_page()
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
` (2 preceding siblings ...)
2026-11-24 11:05 ` [PATCH 3/6] mm/hugetlb_vmemmap: drop the redundant hstate argument Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
2026-11-24 11:05 ` [PATCH 5/6] mm/hugetlb_vmemmap: drop obsolete restore refcount warning Muchun Song
2026-11-24 11:05 ` [PATCH 6/6] mm/vmemmap-optimization: centralize the vmemmap optimization support check Muchun Song
5 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
free_vmemmap_page() has a single caller. Open-code it in
free_vmemmap_page_list() and remove the helper.
No functional change.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/hugetlb_vmemmap.c | 29 +++++++++--------------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 4ed2db189f59..7ede6b6fb4eb 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -172,30 +172,19 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end,
return 0;
}
-/*
- * Free a vmemmap page. A vmemmap page can be allocated from the memblock
- * allocator or buddy allocator. If the PG_reserved flag is set, it means
- * that it allocated from the memblock allocator, just free it via the
- * free_reserved_page(). Otherwise, use __free_page().
- */
-static inline void free_vmemmap_page(struct page *page)
-{
- if (PageReserved(page)) {
- memmap_boot_pages_add(-1);
- free_reserved_page(page);
- } else {
- memmap_pages_add(-1);
- __free_page(page);
- }
-}
-
-/* Free a list of the vmemmap pages */
static void free_vmemmap_page_list(struct list_head *list)
{
struct page *page, *next;
- list_for_each_entry_safe(page, next, list, lru)
- free_vmemmap_page(page);
+ list_for_each_entry_safe(page, next, list, lru) {
+ if (PageReserved(page)) {
+ memmap_boot_pages_add(-1);
+ free_reserved_page(page);
+ } else {
+ memmap_pages_add(-1);
+ __free_page(page);
+ }
+ }
}
static int alloc_vmemmap_page_list(struct list_head *head,
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/6] mm/hugetlb_vmemmap: drop obsolete restore refcount warning
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
` (3 preceding siblings ...)
2026-11-24 11:05 ` [PATCH 4/6] mm/hugetlb_vmemmap: open-code free_vmemmap_page() Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
2026-11-24 11:05 ` [PATCH 6/6] mm/vmemmap-optimization: centralize the vmemmap optimization support check Muchun Song
5 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
Commit bd225530a4c7 ("mm/hugetlb_vmemmap: fix race with speculative
PFN walkers") added this warning alongside RCU protection that
serialized page_ref_add_unless() against HVO remapping. The zero head
refcount was part of that protocol while the vmemmap was folded or
unfolded.
That RCU protection was later removed by commit 32c440d67e6c ("mm:
drop fake head checks") and commit 01b1d0ffb6f7 ("hugetlb: remove
VMEMMAP_SYNCHRONIZE_RCU"). Commit 0120a603afad
("mm/hugetlb_vmemmap: map the shared tail page writable") now handles
the original race by allowing a late cmpxchg to fail safely against
the zero refcount on the shared tail page.
The head folio refcount no longer participates in this protection.
Drop the stale warning from the restore path.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
mm/hugetlb_vmemmap.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 7ede6b6fb4eb..d52e9d16d102 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -408,7 +408,6 @@ static int __hugetlb_vmemmap_restore_folio(struct folio *folio, unsigned long fl
int ret;
VM_WARN_ON_ONCE_FOLIO(!folio_test_hugetlb(folio), folio);
- VM_WARN_ON_ONCE_FOLIO(folio_ref_count(folio), folio);
if (!folio_test_hugetlb_vmemmap_optimized(folio))
return 0;
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/6] mm/vmemmap-optimization: centralize the vmemmap optimization support check
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
` (4 preceding siblings ...)
2026-11-24 11:05 ` [PATCH 5/6] mm/hugetlb_vmemmap: drop obsolete restore refcount warning Muchun Song
@ 2026-11-24 11:05 ` Muchun Song
5 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:05 UTC (permalink / raw)
To: Oscar Salvador, Mike Rapoport, David Hildenbrand, Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm, Muchun Song
Whether vmemmap optimization is supported depends on both the configuration
and struct page having a power-of-two size. Open-coding this condition
in several places makes the support contract easy to duplicate.
Express this contract once in vmemmap_optimization_supported(). Make the
existing checks use it.
No functional change intended.
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
include/linux/page-flags.h | 10 ++++++----
include/linux/vmemmap-optimization.h | 14 +++-----------
2 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index b0ddc652e76c..6133966ba292 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -193,6 +193,11 @@ enum pageflags {
#define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1)
#ifndef __GENERATING_BOUNDS_H
+static __always_inline bool vmemmap_optimization_supported(void)
+{
+ return IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION) &&
+ is_power_of_2(sizeof(struct page));
+}
/*
* For tail pages, if the size of struct page is power-of-2 ->compound_info
@@ -210,10 +215,7 @@ static __always_inline bool compound_info_has_mask(void)
* but it requires validating that struct pages are naturally aligned
* for all orders up to the MAX_FOLIO_ORDER, which can be tricky.
*/
- if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION))
- return false;
-
- return is_power_of_2(sizeof(struct page));
+ return vmemmap_optimization_supported();
}
static __always_inline unsigned long _compound_head(const struct page *page)
diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h
index 985a37dfcab7..0ae8a96a0874 100644
--- a/include/linux/vmemmap-optimization.h
+++ b/include/linux/vmemmap-optimization.h
@@ -21,9 +21,7 @@
* HVO which is only active if the size of struct page is a power of 2.
*/
#define MAX_FOLIO_VMEMMAP_ALIGN \
- (IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION) && \
- is_power_of_2(sizeof(struct page)) ? \
- MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)
+ (vmemmap_optimization_supported() ? MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0)
/* The number of retained vmemmap pages with HVO enabled. */
#define VMEMMAP_OPTIMIZATION_PAGES 1
@@ -33,10 +31,7 @@
static inline bool vmemmap_optimizable_order(unsigned int order)
{
- if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION))
- return false;
-
- if (!is_power_of_2(sizeof(struct page)))
+ if (!vmemmap_optimization_supported())
return false;
return order >= VMEMMAP_OPTIMIZATION_MIN_ORDER;
@@ -115,10 +110,7 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order
{
const unsigned long nr_pages = 1UL << order;
- if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION))
- return false;
-
- if (!is_power_of_2(sizeof(struct page)))
+ if (!vmemmap_optimization_supported())
return false;
return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES;
--
2.54.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message
2026-11-24 11:05 ` [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message Muchun Song
@ 2026-11-24 11:16 ` sashiko-bot
2026-11-24 11:18 ` Muchun Song
0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-11-24 11:16 UTC (permalink / raw)
To: Muchun Song, Oscar Salvador, Mike Rapoport, David Hildenbrand,
Andrew Morton
Cc: Muchun Song, Lance Yang, Qi Zheng, linux-mm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: missing const in !CONFIG_HUGETLB_PAGE huge_page_order()
stub
--
commit 852c6ee3c3138346a4a6991f35b8658e23f3cb65
Author: Muchun Song <muchun.song@linux.dev>
mm/hugetlb_vmemmap: remove the vmemmap savings boot message
This commit removes the boot message reporting potential HugeTLB vmemmap
savings along with hugetlb_vmemmap_optimizable_size(), and updates
hugetlb_vmemmap_optimizable() to check vmemmap_optimizable_order() via
huge_page_order().
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 0d5414392d870..b5b877ed5b92c 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -812,7 +812,7 @@ static inline unsigned long huge_page_mask(struct hstate *h)
> return h->mask;
> }
>
> -static inline unsigned int huge_page_order(struct hstate *h)
> +static inline unsigned int huge_page_order(const struct hstate *h)
> {
> return h->order;
> }
[Severity: Medium]
Should the !CONFIG_HUGETLB_PAGE stub of huge_page_order() in
include/linux/hugetlb.h also take a const struct hstate *h?
hugetlb_vmemmap_optimizable(const struct hstate *h) is defined outside
#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP and now passes h to
huge_page_order(h) behind an IS_ENABLED() check. When a file such as
mm/memory-failure.c includes mm/hugetlb_vmemmap.h with
CONFIG_MEMORY_FAILURE=y and CONFIG_HUGETLB_PAGE=n, calling the non-const
stub triggers a -Wdiscarded-qualifiers warning (or build failure with
CONFIG_WERROR=y).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124110530.3004071-1-songmuchun@bytedance.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message
2026-11-24 11:16 ` sashiko-bot
@ 2026-11-24 11:18 ` Muchun Song
0 siblings, 0 replies; 9+ messages in thread
From: Muchun Song @ 2026-11-24 11:18 UTC (permalink / raw)
To: sashiko-reviews
Cc: Muchun Song, Muchun Song, Oscar Salvador, Mike Rapoport,
David Hildenbrand, Andrew Morton, Lance Yang, Qi Zheng, linux-mm
> On Nov 24, 2026, at 19:16, sashiko-bot@kernel.org wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] mm: missing const in !CONFIG_HUGETLB_PAGE huge_page_order()
> stub
> --
>
> commit 852c6ee3c3138346a4a6991f35b8658e23f3cb65
> Author: Muchun Song <muchun.song@linux.dev>
>
> mm/hugetlb_vmemmap: remove the vmemmap savings boot message
>
> This commit removes the boot message reporting potential HugeTLB vmemmap
> savings along with hugetlb_vmemmap_optimizable_size(), and updates
> hugetlb_vmemmap_optimizable() to check vmemmap_optimizable_order() via
> huge_page_order().
>
>> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
>> index 0d5414392d870..b5b877ed5b92c 100644
>> --- a/include/linux/hugetlb.h
>> +++ b/include/linux/hugetlb.h
>> @@ -812,7 +812,7 @@ static inline unsigned long huge_page_mask(struct hstate *h)
>> return h->mask;
>> }
>>
>> -static inline unsigned int huge_page_order(struct hstate *h)
>> +static inline unsigned int huge_page_order(const struct hstate *h)
>> {
>> return h->order;
>> }
>
> [Severity: Medium]
> Should the !CONFIG_HUGETLB_PAGE stub of huge_page_order() in
> include/linux/hugetlb.h also take a const struct hstate *h?
Yes, and easy to fix.
>
> hugetlb_vmemmap_optimizable(const struct hstate *h) is defined outside
> #ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP and now passes h to
> huge_page_order(h) behind an IS_ENABLED() check. When a file such as
> mm/memory-failure.c includes mm/hugetlb_vmemmap.h with
> CONFIG_MEMORY_FAILURE=y and CONFIG_HUGETLB_PAGE=n, calling the non-const
> stub triggers a -Wdiscarded-qualifiers warning (or build failure with
> CONFIG_WERROR=y).
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261124110530.3004071-1-songmuchun@bytedance.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-24 11:18 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:05 [PATCH 0/6] mm: Simplify HugeTLB vmemmap optimization code Muchun Song
2026-11-24 11:05 ` [PATCH 1/6] mm/hugetlb_vmemmap: remove the vmemmap savings boot message Muchun Song
2026-11-24 11:16 ` sashiko-bot
2026-11-24 11:18 ` Muchun Song
2026-11-24 11:05 ` [PATCH 2/6] mm/hugetlb_vmemmap: fold vmemmap_should_optimize() into its callers Muchun Song
2026-11-24 11:05 ` [PATCH 3/6] mm/hugetlb_vmemmap: drop the redundant hstate argument Muchun Song
2026-11-24 11:05 ` [PATCH 4/6] mm/hugetlb_vmemmap: open-code free_vmemmap_page() Muchun Song
2026-11-24 11:05 ` [PATCH 5/6] mm/hugetlb_vmemmap: drop obsolete restore refcount warning Muchun Song
2026-11-24 11:05 ` [PATCH 6/6] mm/vmemmap-optimization: centralize the vmemmap optimization support check Muchun Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox