[PATCH 12/12] mm: hugetlb_vmemmap: make vmemmap PTE conversion folio-oriented
From: Muchun Song
Date: Tue Oct 20 2026 - 08:07:29 EST
Converting a folio's vmemmap mappings from PMDs to PTEs is a per-folio
operation, but the current interface exposes a raw address range and
hardcodes deferred TLB flushing. This splits the common mechanism
across layers and couples it to the HugeTLB batching policy.
Make the folio the unit of PTE conversion and let callers select the TLB
flush policy through the folio-oriented interface. This keeps
HugeTLB-specific eligibility and batching outside the common operation.
No functional change intended.
Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
mm/hugetlb_vmemmap.c | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 2cfb88dc4fba..75ab5584abe3 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -297,20 +297,26 @@ static inline int vmemmap_restore_range(unsigned long start, unsigned long end,
}
/**
- * vmemmap_remap_split - split the vmemmap virtual address range [@start, @end)
- * backing PMDs of the directmap into PTEs
- * @start: start address of the vmemmap virtual address range that we want
- * to remap.
- * @end: end address of the vmemmap virtual address range that we want to
- * remap.
+ * vmemmap_pteify_folio - convert the vmemmap backing of a folio to PTE mappings
+ * @folio: folio whose vmemmap range should be converted to PTE mappings.
+ * @flags: vmemmap remap control flags passed to vmemmap_remap_walk.
+ *
+ * Convert mappings covering @folio's vmemmap into PTE mappings. If TLB flushing
+ * is skipped, the caller must flush TLBs after all pteify operations are complete
+ * before remapping the folio's vmemmap pages.
+ *
* Return: %0 on success, negative error code otherwise.
*/
-static int vmemmap_remap_split(unsigned long start, unsigned long end)
+static int vmemmap_pteify_folio(const struct folio *folio, unsigned long flags)
{
struct vmemmap_remap_walk walk = {
- .remap_pte = NULL,
- .flags = VMEMMAP_REMAP_NO_TLB_FLUSH,
+ .flags = flags,
};
+ unsigned long start = (unsigned long)folio_page(folio, 0);
+ unsigned long end = start + folio_vmemmap_size(folio);
+
+ if (!vmemmap_optimizable_order(folio_order(folio)))
+ return -EOPNOTSUPP;
return vmemmap_remap_range(start, end, &walk);
}
@@ -529,21 +535,13 @@ void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)
free_vmemmap_page_list(&vmemmap_pages);
}
-static int hugetlb_vmemmap_split_folio(const struct hstate *h, struct folio *folio)
+static int hugetlb_vmemmap_pteify_folio(const struct hstate *h, struct folio *folio,
+ unsigned long flags)
{
- unsigned long vmemmap_start, vmemmap_end;
-
if (!vmemmap_should_optimize_folio(h, folio))
return 0;
- vmemmap_start = (unsigned long)&folio->page;
- vmemmap_end = vmemmap_start + hugetlb_vmemmap_size(h);
-
- /*
- * Split PMDs on the vmemmap virtual address range [@vmemmap_start,
- * @vmemmap_end]
- */
- return vmemmap_remap_split(vmemmap_start, vmemmap_end);
+ return vmemmap_pteify_folio(folio, flags);
}
static void __hugetlb_vmemmap_optimize_folios(struct hstate *h,
@@ -577,7 +575,7 @@ static void __hugetlb_vmemmap_optimize_folios(struct hstate *h,
nr_to_optimize++;
- ret = hugetlb_vmemmap_split_folio(h, folio);
+ ret = hugetlb_vmemmap_pteify_folio(h, folio, flags);
/*
* Splitting the PMD requires allocating a page, thus let's fail
--
2.54.0