Re: [PATCH v2 2/5] mm/rmap: Add try_to_unmap_hugetlb_one
From: David Hildenbrand (Arm)
Date: Mon Jul 13 2026 - 06:35:03 EST
On 7/10/26 15:16, Dev Jain wrote:
>
>
> On 10/07/26 11:29 am, Dev Jain wrote:
>> Simplify try_to_unmap_one() by separating the hugetlb parts into
>> try_to_unmap_hugetlb_one().
>>
>> To understand the correctness of the refactoring, the following points
>> are noted:
>>
>> 1. try_to_unmap() is called for hugetlb folios only when they are
>> hwpoisoned.
>>
>> 2. A hugetlb VMA cannot be mlocked.
>>
>> 3. page_vma_mapped_walk() returns at most one hugetlb mapping in a VMA,
>> and that mapping points at the head PFN.
>>
>> 4. We won't ever process a softleaf entry that encodes a hugetlb folio;
>> hugetlb folios are never swapped out, migration entries will be
>> skipped (PVMW_MIGRATION not passed), and device-exclusive does not
>> work for hugetlb.
>>
>> 5. The hwpoison entry is constructed from the poisoned folio, just as in
>> the pre-refactor code. Any previous uffd-wp state is deliberately not
>> preserved for the hwpoison entry.
>>
>> 6. TTU_HWPOISON is always present; for it to not be present, either the
>> folio has to be in swapcache, or mapping_can_writeback() is true (see
>> unmap_poisoned_folio), none of which is true for hugetlb folios.
>>
>> 7. Hugetlb uses separate counters from normal rss counters, therefore
>> update_highwater_rss() need not be called.
>>
>> While at it:
>>
>> - Change VM_BUG_* to VM_WARN_*.
>>
>> - Do not declare variables which are only used once.
>>
>> - Constify some variables.
>>
>> - Add some more VM_WARN_* to assert some invariants.
>>
>> Except the above 4 points, no functional change intended.
>>
>> Suggested-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>> Signed-off-by: Dev Jain <dev.jain@xxxxxxx>
>> ---
>
> Andrew, could you squash the following diff:
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index cf02b315a2ead..b61051b879c4c 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2229,8 +2229,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> update_hiwater_rss(mm);
>
> /*
> - * With TTU_HWPOISON, we only expect small folios or hugetlb
> - * folios here for now.
> + * With TTU_HWPOISON, we only expect small folios here.
> */
> if (folio_test_hwpoison(folio) && (flags & TTU_HWPOISON)) {
> pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
Note that the comment likely fits into a single line now.
--
Cheers,
David