Re: [PATCH 3/6] mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte()
From: David Hildenbrand (Arm)
Date: Tue Jul 14 2026 - 08:46:10 EST
On 7/12/26 09:38, Shivank Garg wrote:
> remove_migration_pte() interleaves the regular folio path with the
> hugetlb path via folio_test_hugetlb() and CONFIG_HUGETLB_PAGE
> special cases. Simplify this by seprating the hugetlb handling into
> remove_migration_pte_hugetlb().
>
> Factor out working-PTE construction from migration entry into
> migration_softleaf_entry_to_pte(), used by both paths.
>
> While here, convert the VM_BUG_ON_FOLIO() to VM_WARN_ON_ONCE_FOLIO().
>
> No functional change intended.
>
> Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
> ---
> mm/migrate.c | 153 ++++++++++++++++++++++++++++++++++++++---------------------
> 1 file changed, 98 insertions(+), 55 deletions(-)
>
> diff --git a/mm/migrate.c b/mm/migrate.c
> index 222c8c15f782..8a098402b8c9 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -345,6 +345,89 @@ struct rmap_walk_arg {
> bool map_unused_to_zeropage;
> };
>
> +static pte_t migration_softleaf_entry_to_pte(struct folio *folio, struct page *new,
"migration_entry" should be sufficient, right? It implies "softleaf".
> + softleaf_t entry, pte_t old_pte, struct vm_area_struct *vma,
> + rmap_t *rmap_flags)
> +{
> + pte_t pte = mk_pte(new, READ_ONCE(vma->vm_page_prot));
> +
> + if (!softleaf_is_migration_young(entry))
> + pte = pte_mkold(pte);
> + if (folio_test_dirty(folio) && softleaf_is_migration_dirty(entry))
> + pte = pte_mkdirty(pte);
> + if (pte_swp_soft_dirty(old_pte))
> + pte = pte_mksoft_dirty(pte);
> + else
> + pte = pte_clear_soft_dirty(pte);
> +
> + if (softleaf_is_migration_write(entry))
> + pte = pte_mkwrite(pte, vma);
> + else if (pte_swp_uffd(old_pte))
> + pte = pte_mkuffd(pte);
> +
> + /* See do_swap_page(): restore PAGE_NONE for RWP */
> + if (pte_swp_uffd(old_pte) && userfaultfd_rwp(vma))
> + pte = pte_modify(pte, PAGE_NONE);
> +
> + if (folio_test_anon(folio) && !softleaf_is_migration_read(entry))
> + *rmap_flags |= RMAP_EXCLUSIVE;
> +
> + return pte;
> +}
Can you move splitting that out into a separate patch? IIUC you can do that even
without messing with the hugetlb stuff.
--
Cheers,
David