Re: [PATCH v4 10/12] mm/rmap: refactor anon folio unmap in try_to_unmap_one
From: David Hildenbrand (Arm)
Date: Tue Jun 16 2026 - 10:29:11 EST
On 5/26/26 08:36, Dev Jain wrote:
> Refactor anonymous folio unmap to ttu_anon_folio.
Given that the !folio_test_swapbacked() case remains in the caller, should we
make it clearer and call it
ttu_anon_swapbacked_folio()
Or alternatively, factor complete anon folio handling out (incl. lazyfree handling)?
>
> No functional change intended.
>
> Signed-off-by: Dev Jain <dev.jain@xxxxxxx>
> ---
> mm/rmap.c | 116 ++++++++++++++++++++++++++++++++----------------------
> 1 file changed, 68 insertions(+), 48 deletions(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index c0e385882f562..b1639bad8e27f 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2136,6 +2136,70 @@ static inline bool ttu_lazyfree_folio(struct vm_area_struct *vma,
> return true;
> }
>
> +static inline void set_swp_pte_at(struct mm_struct *mm, unsigned long address,
> + pte_t *ptep, swp_entry_t entry, pte_t pteval, bool anon_exclusive)
> +{
> + pte_t swp_pte = swp_entry_to_pte(entry);
> +
> + if (anon_exclusive)
> + swp_pte = pte_swp_mkexclusive(swp_pte);
> +
> + if (likely(pte_present(pteval))) {
> + if (pte_soft_dirty(pteval))
> + swp_pte = pte_swp_mksoft_dirty(swp_pte);
> + if (pte_uffd_wp(pteval))
> + swp_pte = pte_swp_mkuffd_wp(swp_pte);
> + } else {
> + /* Device-exclusive entry */
> + if (pte_swp_soft_dirty(pteval))
> + swp_pte = pte_swp_mksoft_dirty(swp_pte);
> + if (pte_swp_uffd_wp(pteval))
> + swp_pte = pte_swp_mkuffd_wp(swp_pte);
> + }
> +
> + set_pte_at(mm, address, ptep, swp_pte);
> +}
> +
> +static inline bool ttu_anon_folio(struct vm_area_struct *vma, struct folio *folio,
> + struct page *subpage, unsigned long address, pte_t *ptep,
> + pte_t pteval)
> +{
> + bool anon_exclusive = folio_test_anon(folio) && PageAnonExclusive(subpage);
"subpage" ;)
Can be const.
[...]
> } else {
> /*
> * This is a locked file-backed folio,
Happy to see that function shrink a bit ...
--
Cheers,
David