Re: [PATCH v4 02/12] mm/rmap: Add try_to_unmap_hugetlb_one

From: Lance Yang

Date: Thu Jun 18 2026 - 03:45:18 EST



On Tue, Jun 09, 2026 at 04:16:47PM +0200, David Hildenbrand (Arm) wrote:
[...]
>> ---
>> mm/rmap.c | 203 ++++++++++++++++++++++++++++++++----------------------
>> 1 file changed, 121 insertions(+), 82 deletions(-)
>>
>> diff --git a/mm/rmap.c b/mm/rmap.c
>> index 430c91c8fe2ae..06ab1158d4cd1 100644
>> --- a/mm/rmap.c
>> +++ b/mm/rmap.c
>> @@ -1978,6 +1978,121 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
>> FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY);
>> }
>>
>> +static bool __try_to_unmap_hugetlb_one(struct folio *folio,
>> + struct vm_area_struct *vma, struct page_vma_mapped_walk *pvmw,
>> + struct mmu_notifier_range *range, enum ttu_flags flags)
>> +{
>> + unsigned long hsz = huge_page_size(hstate_vma(vma));
>
>Can be const.
>
>> + unsigned long address = pvmw->address;
>
>Can be const. But do we even need the temporary variable?
>
>> + struct mm_struct *mm = vma->vm_mm;
>> + struct page *subpage;
>
>a) subpages do not exist. It's just a folio page.
>b) subpages are irrelevant for hugetlb, just drop anything that deals with them.
>
>> + bool ret = true;
>> + pte_t pteval;
>> +
>
>Worth adding a comment here, why we don't need a loop.
>
>/* There is only a single mapping in a VMA. */
>
>> + if (!page_vma_mapped_walk(pvmw))
>> + return true;
>> +
>> + pteval = ptep_get(pvmw->pte);
>
>Should we now properly use huge_ptep_get()?

Right. IIUC, on s390, the hugetlb entry stored in the page table is not
in the normal PTE layout. set_huge_pte_at() stores the arch huge-entry
format there, and huge_ptep_get() is the helper that decodes it back
into a normal pte_t.

pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
{
return __rste_to_pte(pte_val(*ptep));
}

>> + VM_WARN_ON(!pte_present(pteval));
>> + subpage = folio_page(folio, pte_pfn(pteval) - folio_pfn(folio));
>
>No need for subpages.

So plain ptep_get() can feed raw huge-entry bits into pte_pfn(), and the
derived subpage can be wrong.

Cheers, Lance

[...]