From: Shivank Garg <shivankg@amd.com>
To: 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>,
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>, Shivank Garg <shivankg@amd.com>
Subject: [PATCH v3 0/3] mm/rmap: batch the unmap of large folios during migration
Date: Thu, 26 Nov 2026 09:53:00 +0000 [thread overview]
Message-ID: <20261126-migrate-rmap-batch-v3-0-4112998fb472@amd.com> (raw)
Migrating a PTE-mapped large folio replaces its present PTEs with
migration entries one page at a time: try_to_migrate_one() repeats
page_vma_mapped_walk(), the PTE clear and flush, the migration entry
setup and the rmap/refcount update for every subpage (256 iterations for
a 1M folio).
This series lets try_to_migrate_one() convert a batch of consecutive PTEs
that map the same large folio in one go, mirroring what
try_to_unmap_one() already does, with some refactoring on the way.
Besides the walk overhead, batching avoids a spurious deferred split:
unmapping an anonymous mTHP one PTE at a time makes it look partially
mapped partway through, so it is queued for deferred split even though it
is about to be fully unmapped. Joanne's underused mTHP shrinker series [1]
sends every underused mTHP split through this path, which makes this a
blocker there [2].
Performance:
AMD EPYC Zen5, 2-socket system (1 node per socket), mitigations=off.
move_pages() migrating 1GB between the two nodes, mTHP of the given
size; base is mm-core/for-next + Dev's v5 [3]. Throughput in GB/s,
mean of 40 runs (2 boots, both directions):
folio base patched gain
4K 3.39±0.02 3.39±0.02 +0.1%
16K 4.65±0.02 5.12±0.04 +10.3%
64K 5.51±0.04 6.46±0.05 +17.2%
256K 5.78±0.07 7.47±0.01 +29.2%
1M 5.94±0.02 7.64±0.02 +28.6%
2M 9.09±0.03 9.08±0.03 -0.2% (PMD-mapped)
Time spent in try_to_migrate() during that move (ftrace function
profiler, mean of 6 runs):
folio base patched delta
16K 43.7 ms 28.2 ms -35%
64K 45.6 ms 20.0 ms -56%
256K 44.2 ms 8.1 ms -82%
1M 41.8 ms 7.1 ms -83%
On AMD EPYC Zen3 (refer V2 cover), the unmap-side batching gave
around +25.0% at 64K, +38.4% at 256K and +39.5% at 1M.
The restore-side batching from v2 is split out and will be posted
separately.
Applies on mm-core/for-next + Dev's "Optimize anonymous swapbacked large
folio unmapping" v5 [3].
[1] https://lore.kernel.org/linux-mm/20261103212004.1356327-1-joannelkoong@gmail.com/
[2] https://lore.kernel.org/linux-mm/20261109220958.2071687-1-joannelkoong@gmail.com/
[3] https://lore.kernel.org/linux-mm/20261123053543.295467-1-dev.jain@arm.com/
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
Changes in v3:
- try_to_migrate_one(): memory_failure() can poison a tail page without
holding the folio lock, so check PageHWPoison for every subpage in the
batch. (Lance, Miaohe, Ying)
- Split the series: this posting is only the unmap side changes. Restore
side batching will be posted separately.
- Rebase onto mm-core/for-next and Dev's series v5; adapt to
finish_folio_unmap_batch() and page_anon_exclusive_batch() changes.
- Use vma_test_any_mask() in try_to_migrate_hugetlb_one()
- Link to v2: https://lore.kernel.org/r/20260813-migrate-rmap-batch-v2-0-3c5424c555c7@amd.com
Changes in v2:
- Rebase onto mm-new, drop the borrowed folio_try_share_anon_rmap_ptes() patch
and add it as dependency on Dev's series and adapt to recent migrate/rmap changes.
- Switch to recently added batched helpers - finish_folio_unmap, set_softleaf_ptes,
and page_anon_exclusive_batch.
- Rename migration_softleaf_entry_to_pte() to migration_entry_to_pte(). (David)
- Split PTE construction from hugetlb handling into separate patch. (David)
Mirror the split in mm/rmap.c patch as well.
- Rename make_migration_swp_pte() to make_migration_pte().
- Early exit the single-entry hugetlb page_vma_mapped_walk() paths - removes
unnecessary nesting.
- Add the missing page_vma_mapped_walk_done() in remove_migration_pte_hugetlb(),
which leaked the huge-PTE lock. (syzbot ci, Sashiko)
- Fix handling of hwpoisoned subpages in the batched unmap. Read PageHWPoison()
once and skip batching when mapped page is poisoned, and use same result for
hwpoison handling. (Sashiko)
- Remove the pte_unused(pteval) handling from try_to_migrate_hugetlb_one() (Sashiko).
- Link to v1: https://lore.kernel.org/r/20260712-migrate-rmap-batch-v1-0-872a734431d1@amd.com
---
Shivank Garg (3):
mm/rmap: factor out migration PTE construction
mm/rmap: split try_to_migrate_hugetlb_one() out of try_to_migrate_one()
mm/rmap: batch the unmap of large folios in try_to_migrate_one()
mm/rmap.c | 434 +++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 277 insertions(+), 157 deletions(-)
---
base-commit: 518cbccb58e4ff8ce9d7ed609036c559dfdcf62e
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next
change-id: 20260701-migrate-rmap-batch-8ecc04de1905
prerequisite-message-id: 20261123053543.295467-1-dev.jain@arm.com
prerequisite-patch-id: 5dc23d00736b03a60a420bce56fdb59aabb57d97
prerequisite-patch-id: 87ecef5648d4102fd0ac1d2c1875aee3476635eb
prerequisite-patch-id: 43f01b72e0fdde751109e0f471c30b15d9f192ac
prerequisite-patch-id: 18bf3505aa2499f4e18446b4930e503d4085346d
prerequisite-patch-id: e79055c5dcb6fae5cb425feddec0e809959fd563
prerequisite-patch-id: 98bc99c6bc274594946d022b3998f5f1dc70012f
prerequisite-patch-id: dd35ec00b82bf235f2e41e286d16eab6a3fd1e9e
prerequisite-patch-id: d6f05c7d00e839fea93a5637b68348a1df345cc4
Best regards,
--
Shivank Garg <shivankg@amd.com>
next reply other threads:[~2026-11-26 9:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:53 Shivank Garg [this message]
2026-11-26 9:53 ` [PATCH v3 1/3] mm/rmap: factor out migration PTE construction Shivank Garg
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-11-26 9:53 ` [PATCH v3 3/3] mm/rmap: batch the unmap of large folios in try_to_migrate_one() Shivank Garg
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=20261126-migrate-rmap-batch-v3-0-4112998fb472@amd.com \
--to=shivankg@amd.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=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=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