From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Shivank Garg <shivankg@amd.com>,
Andrew Morton <akpm@linux-foundation.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>,
Joanne Koong <joannelkoong@gmail.com>
Cc: Karim Manaouil <kmanaouil.dev@gmail.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>,
Usama Arif <usama.arif@linux.dev>,
Miaohe Lin <linmiaohe@huawei.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one()
Date: Tue, 1 Dec 2026 12:03:19 +0100 [thread overview]
Message-ID: <d9be1276-f380-4413-a27c-076072d2b2f7@kernel.org> (raw)
In-Reply-To: <20261126-migrate-rmap-batch-v3-2-4112998fb472@amd.com>
On 11/26/26 10:53, Shivank Garg wrote:
> try_to_migrate_one() interleaves hugetlb special handling through the
> regular PTE/PMD migration path with folio_test_hugetlb() checks
> scattered across the walk. Simplify this by moving hugetlb handling
> into its own rmap_one callback, try_to_migrate_hugetlb_one().
>
> Few minor changes:
> - Since hugetlb uses separate counters, update_hiwater_rss() is not
> needed for hugetlb path. Also, use huge_pte_dirty instead of pte_dirty
> - No PVMW_SYNC flag is needed for hugetlb
> - hugetlb folio has single mapping per VMA, so no loop is needed.
> - Convert VM_BUG_ON to VM_WARN_ON_ONCE and not use irrelevant WARN check.
>
> Signed-off-by: Shivank Garg <shivankg@amd.com>
> ---
> mm/rmap.c | 251 +++++++++++++++++++++++++++++++++++---------------------------
> 1 file changed, 144 insertions(+), 107 deletions(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 304581856d67..fe87df06fa06 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2553,6 +2553,138 @@ static pte_t make_migration_pte(struct page *page, pte_t pteval,
> return swp_pte;
> }
>
> +/*
> + * Replace the hugetlb page table mapping for folio with migration entries.
> + *
> + * @arg: enum ttu_flags will be passed to this argument.
> + */
> +static bool try_to_migrate_hugetlb_one(struct folio *folio,
> + struct vm_area_struct *vma, unsigned long address, void *arg)
> +{
> + const unsigned long hsz = huge_page_size(hstate_vma(vma));
> + DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
> + enum ttu_flags flags = (enum ttu_flags)(long)arg;
> + bool anon_exclusive, writable, ret = true;
> + bool anon = folio_test_anon(folio);
> + struct mm_struct *mm = vma->vm_mm;
> + struct mmu_notifier_range range;
> + unsigned long pfn;
> + struct page *page;
> + pte_t pteval;
> +
> + range.end = vma_address_end(&pvmw);
> + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm,
> + address, range.end);
> + /* If sharing is possible, start and end will be adjusted accordingly. */
> + adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end);
> + mmu_notifier_invalidate_range_start(&range);
> +
> + /* There is only a single mapping in a VMA. */
> + if (!page_vma_mapped_walk(&pvmw))
> + goto range_end;
> +
> + address = pvmw.address;
> + pteval = huge_ptep_get(mm, address, pvmw.pte);
> + if (likely(pte_present(pteval)))
> + pfn = pte_pfn(pteval);
> + else
> + pfn = softleaf_to_pfn(softleaf_from_pte(pteval));
Do we have such a case for hugetlb?
> +
> + page = folio_page(folio, pfn - folio_pfn(folio));
How can we ever not be at the head page.
Likely, most of this sould be very similar to what we have in
try_to_unmap_poisoned_hugetlb_one().
Which raises the question if we can unify some stuff there instead? It's *a lot*
of code duplication.
Just need to teach try_to_unmap_poisoned_hugetlb_one() to insert migration
entries when asked.
Sounds reasonable?
--
Cheers,
David
next prev parent reply other threads:[~2026-12-01 11:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:53 [PATCH v3 0/3] mm/rmap: batch the unmap of large folios during migration Shivank Garg
2026-11-26 9:53 ` [PATCH v3 1/3] mm/rmap: factor out migration PTE construction Shivank Garg
2026-12-01 10:56 ` David Hildenbrand (Arm)
2026-11-26 9:53 ` [PATCH v3 2/3] mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one() Shivank Garg
2026-12-01 11:03 ` David Hildenbrand (Arm) [this message]
2026-11-26 9:53 ` [PATCH v3 3/3] mm/rmap: batch the unmap of large folios in try_to_migrate_one() Shivank Garg
2026-11-30 20:02 ` [PATCH v3 0/3] mm/rmap: batch the unmap of large folios during migration Ravi Jonnalagadda
2026-12-01 9:46 ` 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=d9be1276-f380-4413-a27c-076072d2b2f7@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bharata@amd.com \
--cc=byungchul@sk.com \
--cc=dev.jain@arm.com \
--cc=fvdl@google.com \
--cc=gourry@gourry.net \
--cc=harry@kernel.org \
--cc=jannh@google.com \
--cc=joannelkoong@gmail.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kinseyho@google.com \
--cc=kmanaouil.dev@gmail.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linmiaohe@huawei.com \
--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=usama.arif@linux.dev \
--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
all inboxes | Powered by JetHome®