Re: [PATCH v2 04/12] mm: hugetlb_vmemmap: generalize vmemmap page allocation
From: Mike Rapoport
Date: Mon Nov 02 2026 - 05:21:31 EST
Hi Muchun,
> 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.
> {
> - 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?
>
> - 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
> + 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().
--
Sincerely yours,
Mike.