Re: [PATCH 3/3] mm/hugetlb: Refactor __unmap_hugepage_range() to take folio instead of page

From: Muchun Song
Date: Thu Apr 17 2025 - 23:04:56 EST




> On Apr 18, 2025, at 00:34, Fan Ni <nifan.cxl@xxxxxxxxx> wrote:
>
> On Thu, Apr 17, 2025 at 12:21:55PM -0400, Sidhartha Kumar wrote:
>> On 4/17/25 11:43 AM, nifan.cxl@xxxxxxxxx wrote:
>>> From: Fan Ni <fan.ni@xxxxxxxxxxx>
>>>
>>> The function __unmap_hugepage_range() has two kinds of users:
>>> 1) unmap_hugepage_range(), which passes in the head page of a folio.
>>> Since unmap_hugepage_range() already takes folio and there are no other
>>> uses of the folio struct in the function, it is natural for
>>> __unmap_hugepage_range() to take folio also.
>>> 2) All other uses, which pass in NULL pointer.
>>>
>>> In both cases, we can pass in folio. Refactor __unmap_hugepage_range() to
>>> take folio.
>>>
>>> Signed-off-by: Fan Ni <fan.ni@xxxxxxxxxxx>
>>> ---
>>>
>>> Question: If the change in the patch makes sense, should we try to convert all
>>> "page" uses in __unmap_hugepage_range() to folio?
>>>
>>
>> For this to be correct, we have to ensure that the pte in:
>>
>> page = pte_page(pte);
>>
>> only refers to the pte of a head page. pte comes from:
>>
>> pte = huge_ptep_get(mm, address, ptep);
>>
>> and in the for loop above:
>>
>> for (; address < end; address += sz)
>>
>> address is incremented by the huge page size so I think address here only
>> points to head pages of hugetlb folios and it would make sense to convert
>> page to folio here.
>>
>
> Thanks Sidhartha for reviewing the series. I have similar understanding and
> wanted to get confirmation from experts in this area.

I think your understanding is right. BTW, you forgot to update definition of
__unmap_hugepage_range() under !CONFIG_HUGETLB_PAGE case.

>
> Thanks.
> Fan