From: Karim Manaouil <kmanaouil.dev@gmail.com>
To: Shivank Garg <shivankg@amd.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Rik van Riel <riel@surriel.com>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>, Harry Yoo <harry@kernel.org>,
Jann Horn <jannh@google.com>, Lance Yang <lance.yang@linux.dev>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Frank van der Linden <fvdl@google.com>,
Kinsey Ho <kinseyho@google.com>, Wei Xu <weixugc@google.com>,
Bharata B Rao <bharata@amd.com>,
David Rientjes <rientjes@google.com>, Dev Jain <dev.jain@arm.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/7] mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte()
Date: Wed, 19 Aug 2026 12:24:19 +0100 [thread overview]
Message-ID: <20260819112419.n4fkhvbxxfhsyhun@wrangler> (raw)
In-Reply-To: <20260813-migrate-rmap-batch-v2-3-3c5424c555c7@amd.com>
Hi Shivank,
On Thu, Aug 13, 2026 at 04:23:14AM +0000, Shivank Garg wrote:
> remove_migration_pte() interleaves hugetlb handling with the regular
> folio path. Move it into a dedicated callback selected by
> remove_migration_ptes(), leaving the generic callback focused on regular
> folios ahead of PTE batching.
>
> With hugetlb folios routed separately, simplify the PMD mapping check to
> a one-time warning.
>
> Signed-off-by: Shivank Garg <shivankg@amd.com>
> ---
> mm/migrate.c | 97 +++++++++++++++++++++++++++++++++++++++---------------------
> 1 file changed, 63 insertions(+), 34 deletions(-)
>
> diff --git a/mm/migrate.c b/mm/migrate.c
> index a3362cc9ef66..ee1b8a55a2a4 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -375,6 +375,57 @@ static pte_t migration_entry_to_pte(struct folio *folio, struct page *new,
> return pte;
> }
>
> +/*
> + * Restore a potential migration pte to a working pte entry for hugetlb folios.
> + */
> +#ifdef CONFIG_HUGETLB_PAGE
> +static bool remove_migration_pte_hugetlb(struct folio *folio,
> + struct vm_area_struct *vma, unsigned long addr, void *arg)
> +{
> + struct rmap_walk_arg *rmap_walk_arg = arg;
> + DEFINE_FOLIO_VMA_WALK(pvmw, rmap_walk_arg->folio, vma, addr, PVMW_SYNC | PVMW_MIGRATION);
> + struct hstate *h = hstate_vma(vma);
> + unsigned int shift = huge_page_shift(h);
> + unsigned long psize = huge_page_size(h);
> + struct page *new = folio_page(folio, 0);
> + rmap_t rmap_flags = RMAP_NONE;
> + pte_t old_pte, pte;
> + softleaf_t entry;
> +
> + /* There is only a single mapping in a VMA. */
I don't think this comment is necessary. page_vma_mapped_walk() clearly
explains what happens with HugeTLB entries.
> + if (!page_vma_mapped_walk(&pvmw))
> + return true;
> +
> + old_pte = huge_ptep_get(vma->vm_mm, pvmw.address, pvmw.pte);
> + entry = softleaf_from_pte(old_pte);
> + folio_get(folio);
> + pte = migration_entry_to_pte(folio, new, entry, old_pte, vma, &rmap_flags);
> + pte = arch_make_huge_pte(pte, shift, vma->vm_flags);
> + if (folio_test_anon(folio))
> + hugetlb_add_anon_rmap(folio, vma, pvmw.address, rmap_flags);
> + else
> + hugetlb_add_file_rmap(folio);
> + set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte, psize);
I know nothing in HugeTLB, but can't they be mapped as 4KiB entries? In
which case we have to use
while (page_vma_mapped_walk(&pvmw)) {
...
}
It seems like it's not the case from my little investigation, but
I'll keep it here just to be sure.
> + if (READ_ONCE(vma->vm_flags) & VM_LOCKED)
> + mlock_drain_local();
> +
> + trace_remove_migration_pte(pvmw.address, pte_val(pte), compound_order(new));
> +
> + /* No need to invalidate - it was non-present before */
> + update_mmu_cache(vma, pvmw.address, pvmw.pte);
> + page_vma_mapped_walk_done(&pvmw);
> +
> + return true;
> +}
> +#else
> +static bool remove_migration_pte_hugetlb(struct folio *folio,
> + struct vm_area_struct *vma, unsigned long addr, void *arg)
> +{
> + return false;
> +}
> +#endif /* CONFIG_HUGETLB_PAGE */
> +
> /*
> * Restore a potential migration pte to a working pte entry
> */
> @@ -395,20 +446,14 @@ static bool remove_migration_pte(struct folio *folio,
> #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES
> /* PMD-mapped THP migration entry */
> if (!pvmw.pte) {
> - VM_BUG_ON_FOLIO(folio_test_hugetlb(folio) ||
> - !folio_test_pmd_mappable(folio), folio);
> + VM_WARN_ON_ONCE_FOLIO(!folio_test_pmd_mappable(folio), folio);
> remove_migration_pmd(&pvmw, folio);
> continue;
> }
> #endif
> - if (folio_test_hugetlb(folio))
> - old_pte = huge_ptep_get(vma->vm_mm, pvmw.address,
> - pvmw.pte);
> - else
> - old_pte = ptep_get(pvmw.pte);
> -
> + old_pte = ptep_get(pvmw.pte);
> entry = softleaf_from_pte(old_pte);
> - if (folio_test_large(folio) && !folio_test_hugetlb(folio))
> + if (folio_test_large(folio))
> idx = softleaf_to_pfn(entry) - pvmw.pfn;
>
> if (rmap_walk_arg->map_unused_to_zeropage &&
> @@ -434,30 +479,12 @@ static bool remove_migration_pte(struct folio *folio,
> pte = pte_swp_mkuffd(pte);
> }
>
> -#ifdef CONFIG_HUGETLB_PAGE
> - if (folio_test_hugetlb(folio)) {
> - struct hstate *h = hstate_vma(vma);
> - unsigned int shift = huge_page_shift(h);
> - unsigned long psize = huge_page_size(h);
> -
> - pte = arch_make_huge_pte(pte, shift, vma->vm_flags);
> - if (folio_test_anon(folio))
> - hugetlb_add_anon_rmap(folio, vma, pvmw.address,
> - rmap_flags);
> - else
> - hugetlb_add_file_rmap(folio);
> - set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte,
> - psize);
> - } else
> -#endif
> - {
> - if (folio_test_anon(folio))
> - folio_add_anon_rmap_pte(folio, new, vma,
> - pvmw.address, rmap_flags);
> - else
> - folio_add_file_rmap_pte(folio, new, vma);
> - set_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte);
> - }
> + if (folio_test_anon(folio))
> + folio_add_anon_rmap_pte(folio, new, vma,
> + pvmw.address, rmap_flags);
> + else
> + folio_add_file_rmap_pte(folio, new, vma);
> + set_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte);
> if (READ_ONCE(vma->vm_flags) & VM_LOCKED)
> mlock_drain_local();
>
> @@ -484,7 +511,9 @@ void remove_migration_ptes(struct folio *src, struct folio *dst,
> };
>
> struct rmap_walk_control rwc = {
> - .rmap_one = remove_migration_pte,
> + .rmap_one = folio_test_hugetlb(src) ?
> + remove_migration_pte_hugetlb :
> + remove_migration_pte,
> .arg = &rmap_walk_arg,
> };
>
>
> --
> 2.43.0
>
--
~karim
next prev parent reply other threads:[~2026-08-19 11:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 4:23 [PATCH v2 0/7] mm: batch rmap walks during large folio migration Shivank Garg
2026-08-13 4:23 ` [PATCH v2 1/7] mm: factor out generic PTE batch detection from swap_pte_batch() Shivank Garg
2026-08-13 9:57 ` David Hildenbrand (Arm)
2026-08-14 8:00 ` Garg, Shivank
2026-08-16 7:48 ` Garg, Shivank
2026-08-13 4:23 ` [PATCH v2 2/7] mm/migrate: factor out migration PTE construction Shivank Garg
2026-08-13 4:23 ` [PATCH v2 3/7] mm/migrate: split remove_migration_pte_hugetlb() out of remove_migration_pte() Shivank Garg
2026-08-19 11:24 ` Karim Manaouil [this message]
2026-08-19 17:49 ` Garg, Shivank
2026-08-13 4:23 ` [PATCH v2 4/7] mm/migrate: batch the restore-side migration rmap walk Shivank Garg
2026-08-13 4:23 ` [PATCH v2 5/7] mm/rmap: factor out migration PTE construction Shivank Garg
2026-08-13 4:23 ` [PATCH v2 6/7] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one() Shivank Garg
2026-08-13 4:23 ` [PATCH v2 7/7] mm/rmap: batch the unmap of large folios in try_to_migrate_one() Shivank Garg
2026-08-17 9:14 ` Lance Yang
2026-08-18 8:55 ` Miaohe Lin
2026-08-18 9:20 ` Lance Yang
2026-08-19 9:05 ` Miaohe Lin
2026-08-19 9:42 ` Huang, Ying
2026-08-19 9:57 ` Lance Yang
2026-08-19 10:09 ` Garg, Shivank
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260819112419.n4fkhvbxxfhsyhun@wrangler \
--to=kmanaouil.dev@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bharata@amd.com \
--cc=byungchul@sk.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=fvdl@google.com \
--cc=gourry@gourry.net \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kinseyho@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=rakie.kim@sk.com \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=shivankg@amd.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox