Re: [PATCH v2 04/12] mm: hugetlb_vmemmap: generalize vmemmap page allocation
From: Muchun Song
Date: Mon Nov 02 2026 - 08:16:15 EST
> On Nov 2, 2026, at 18:18, Mike Rapoport <rppt@xxxxxxxxxx> wrote:
>
> Hi Muchun,
Hi,
It's my email client's fault. Let me email it again.
>
>> Vmemmap page allocation is currently tied to restoring a virtual range
>> and assumes an empty destination list. These constraints prevent it from
>> being reused when pages are requested independently of a vmemmap range or
>> appended to an existing list.
>>
>> Generalize the allocator and give it an all-or-nothing list contract so
>> the restore and optimization paths can share the same allocation policy.
>> This also allows HVO head-page allocation to fail gracefully under memory
>> pressure without triggering the OOM killer.
>>
>> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
>> Reviewed-by: Lance Yang <lance.yang@xxxxxxxxx>
>> Reviewed-by: Qi Zheng <qi.zheng@xxxxxxxxx>
>> ---
>> v2:
>> - Collect Reviewed-by from Lance Yang and Qi Zheng
>> ---
>> mm/hugetlb_vmemmap.c | 39 ++++++++++++++++++---------------------
>> 1 file changed, 18 insertions(+), 21 deletions(-)
>>
>> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
>> index 0e5b2b182d1bf..4b20a8efc0678 100644
>> --- a/mm/hugetlb_vmemmap.c
>> +++ b/mm/hugetlb_vmemmap.c
>> @@ -334,28 +334,26 @@ static int vmemmap_remap_free(unsigned long start, unsigned long end,
>> return ret;
>> }
>>
>> -static int alloc_vmemmap_page_list(unsigned long start, unsigned long end,
>> - struct list_head *list)
>> +static int alloc_vmemmap_page_list(struct list_head *head, unsigned int nr_pages,
>> + int nid)
>
> Please indent with two tabs, like David likes :)
> Applies throughout the series.
Sure. Should we update scripts/checkpatch.pl in the future for MM,
since this script seems to favor the alignment approach?
>
>> {
>> - gfp_t gfp_mask = GFP_KERNEL | __GFP_RETRY_MAYFAIL;
>> - unsigned long nr_pages = (end - start) >> PAGE_SHIFT;
>> - int nid = page_to_nid((struct page *)start);
>> - struct page *page, *next;
>> - int i;
>> + LIST_HEAD(local);
>
> Can we use a better name here please? E.g new_pages?
Yahs, make sense.
>
>>
>> - for (i = 0; i < nr_pages; i++) {
>> - page = alloc_pages_node(nid, gfp_mask, 0);
>> - if (!page)
>> - goto out;
>> - list_add(&page->lru, list);
>> + for (unsigned int i = 0; i < nr_pages; i++) {
>> + struct page *page;
>> +
>> + page = alloc_pages_node(nid, GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
>> + if (!page) {
>
> I think goto err_do_cleanup is cleaner than ad-hok cleanups
I’ll use goto style, either is OK for me.
>
>> + memmap_pages_add(i);
>
> This is confusing. Updating counters only to use
> free_vmemmap_page_list() seems worse choice than walking the list and
> __free_page().
I think the memmap accounting should be done right after each successful
allocation — that way, using free_vmemmap_page_list() becomes more natural
and simple.
Somthing like:
diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index c04f53f708d2..cab9ec14873d 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -207,14 +207,13 @@ static int alloc_vmemmap_page_list(struct list_head *head, unsigned int nr_pages
page = alloc_pages_node(nid, GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
if (!page) {
- memmap_pages_add(i);
free_vmemmap_page_list(&local);
return -ENOMEM;
}
+ memmap_pages_add(1);
list_add(&page->lru, &local);
}
list_splice(&local, head);
- memmap_pages_add(nr_pages);
return 0;
}
Thanks for your review, Mike.
Muchun
>
> --
> Sincerely yours,
> Mike.