[PATCH 08/12] mm: hugetlb_vmemmap: move alloc_vmemmap_page_list() next to its free helper

From: Muchun Song

Date: Tue Oct 20 2026 - 08:06:16 EST


Keep alloc_vmemmap_page_list() together with
free_vmemmap_page_list(). This also allows the folio-oriented
optimization helper introduced in a subsequent change to reuse the
allocator without a forward declaration.

No functional change intended.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
mm/hugetlb_vmemmap.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 8fac61b7d74a..89f000227d4b 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -197,6 +197,27 @@ static void free_vmemmap_page_list(struct list_head *list)
free_vmemmap_page(page);
}

+static int alloc_vmemmap_page_list(struct list_head *head, unsigned int nr_pages,
+ int nid)
+{
+ LIST_HEAD(local);
+ struct page *page;
+
+ for (unsigned int i = 0; i < nr_pages; i++) {
+ page = alloc_pages_node(nid, GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
+ if (!page) {
+ memmap_pages_add(i);
+ free_vmemmap_page_list(&local);
+ return -ENOMEM;
+ }
+ list_add(&page->lru, &local);
+ }
+ list_splice(&local, head);
+ memmap_pages_add(nr_pages);
+
+ return 0;
+}
+
static struct page *vmemmap_dup_page_from_list(const struct page *src,
struct list_head *vmemmap_pages)
{
@@ -323,27 +344,6 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end,
return ret;
}

-static int alloc_vmemmap_page_list(struct list_head *head, unsigned int nr_pages,
- int nid)
-{
- LIST_HEAD(local);
- struct page *page;
-
- for (unsigned int i = 0; i < nr_pages; i++) {
- page = alloc_pages_node(nid, GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
- if (!page) {
- memmap_pages_add(i);
- free_vmemmap_page_list(&local);
- return -ENOMEM;
- }
- list_add(&page->lru, &local);
- }
- list_splice(&local, head);
- memmap_pages_add(nr_pages);
-
- return 0;
-}
-
/**
* vmemmap_remap_alloc - remap the vmemmap virtual address range [@start, end)
* to the page which is from the @vmemmap_pages
--
2.54.0