Re: [PATCHv3 09/15] mm/hugetlb: Refactor code around vmemmap_walk

From: Kiryl Shutsemau

Date: Mon Jan 19 2026 - 10:26:44 EST


On Mon, Jan 19, 2026 at 06:04:32PM +0800, Muchun Song wrote:
> > @@ -415,29 +377,27 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end,
> > * to remap.
> > * @end: end address of the vmemmap virtual address range that we want to
> > * remap.
> > - * @reuse: reuse address.
> > * @flags: modifications to vmemmap_remap_walk flags
> > *
> > * Return: %0 on success, negative error code otherwise.
> > */
> > static int vmemmap_remap_alloc(unsigned long start, unsigned long end,
> > - unsigned long reuse, unsigned long flags)
> > + unsigned long flags)
> > {
> > LIST_HEAD(vmemmap_pages);
> > struct vmemmap_remap_walk walk = {
> > .remap_pte = vmemmap_restore_pte,
> > - .reuse_addr = reuse,
> > + .vmemmap_start = start,
> > .vmemmap_pages = &vmemmap_pages,
> > .flags = flags,
> > };
> > - /* See the comment in the vmemmap_remap_free(). */
> > - BUG_ON(start - reuse != PAGE_SIZE);
> > + start += HUGETLB_VMEMMAP_RESERVE_SIZE;
>
> From the @start comment above this function, we can see that the @start
> address is the starting address for the remap operation we want to perform.
> However, the modification here does not conform to the semantics here.
> Therefore, I suggest letting the caller __hugetlb_vmemmap_restore_folio()
> pass the correct parameters itself.
>
> The reason we previously used the reuse address here is that the
> initialization of ->reuse_page was inside vmemmap_pte_entry. Now,
> ->reuse_page has been removed in your patch.

Fair enough.

> > @@ -466,18 +425,16 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,
> > if (flags & VMEMMAP_SYNCHRONIZE_RCU)
> > synchronize_rcu();
> > + vmemmap_start = (unsigned long)folio;
>
> (unsigned long)&folio->page?The folio is the metadata for contiguous pages,
> while the page is our optimization target. Although their values are the
> same now, their semantics are different.

Okay.

--
Kiryl Shutsemau / Kirill A. Shutemov