[PATCH 0/6] mm: preparatory patches for PMD level swap entries
From: Usama Arif
Date: Tue Jun 30 2026 - 12:46:07 EST
This is the preparatory part of the PMD page table swapin work. The
full PMD swap entry series has been split into two parts:
1. this preparatory series, which contains the first 6 patches. Zi [1]
and Lance [2] suggested to separate this out from the core series.
2. the PMD swap entry core series, which depends on this one. I will
send this once the preparatory series is merged in mm-new as v3
as the combined is currently at v2 [1].
I have not marked this prep series as v3, as its not really adding
support for PMD swap entries.
This series does not introduce PMD swap entries and does not install any
new page-table entry type. It only cleans up existing PMD softleaf
helpers and call sites so the follow-up PMD swap entry series can be
smaller and easier to review.
It should be safe to merge independently. The patches are either helper
additions, refactors of existing open-coded logic, defensive checks that
preserve current migration/device-private behavior, or a mechanical
rename of the PMD softleaf Kconfig gate. The follow-up series depends
on these helpers, but this series does not depend on the follow-up
series.
Patch breakdown:
1. mm: add softleaf_to_pmd() and convert existing callers
Add the PMD counterpart to softleaf_to_pte() and convert existing
swp_entry_to_pmd() users that are constructing PMD softleaf
entries.
2. mm: extract mm_prepare_for_swap_entries() helper
Hoist the "register mm with swapoff" double-checked-locking
pattern out of try_to_unmap_one() and copy_nonpresent_pte() so
future PMD-level users do not need another open-coded copy.
3. fs/proc: use softleaf_has_pfn() in pagemap PMD walker
Avoid assuming every non-present PMD softleaf entry encodes a PFN.
Existing migration/device-private behavior is preserved.
4. mm/huge_memory: move softleaf_to_folio() inside migration branch
Keep the folio lookup in change_non_present_huge_pmd() scoped to
the migration-entry branch that actually needs it.
5. mm/migrate_device: move softleaf_to_folio() inside device-private
branch
Apply the same ordering cleanup to migrate_vma_collect_pmd(): only
derive a folio after confirming the PMD entry is device-private.
6. mm: rename ARCH_ENABLE_THP_MIGRATION to ARCH_SUPPORTS_PMD_SOFTLEAF
Rename the architecture gate to describe what it actually enables:
PMD softleaf entries. Migration remains the only current user in
this series; the follow-up series adds PMD swap entries.
The patches are based on akpm/mm-new as of 29 June
(git hash: 15654b0268cd65b4e673510c0377774e61b86397)
[1] https://lore.kernel.org/all/6E99CC4E-A026-4DE3-8A5A-34216771F521@xxxxxxxxxx/
[2] https://lore.kernel.org/all/b08cafbb-a4b7-4609-84ae-dbb2cfcfc8be@xxxxxxxxx/#t
[3] https://lore.kernel.org/all/20260602142537.198755-1-usama.arif@xxxxxxxxx/
Usama Arif (6):
mm: add softleaf_to_pmd() and convert existing callers
mm: extract mm_prepare_for_swap_entries() helper
fs/proc: use softleaf_has_pfn() in pagemap PMD walker
mm/huge_memory: move softleaf_to_folio() inside migration branch
mm/migrate_device: move softleaf_to_folio() inside device-private
branch
mm: rename ARCH_ENABLE_THP_MIGRATION to ARCH_SUPPORTS_PMD_SOFTLEAF
arch/arm64/Kconfig | 2 +-
arch/arm64/include/asm/pgtable.h | 4 +--
arch/loongarch/Kconfig | 2 +-
arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +-
arch/powerpc/platforms/Kconfig.cputype | 2 +-
arch/riscv/Kconfig | 2 +-
arch/riscv/include/asm/pgtable.h | 8 +++---
arch/s390/Kconfig | 2 +-
arch/s390/include/asm/pgtable.h | 2 +-
arch/x86/Kconfig | 2 +-
arch/x86/include/asm/pgtable.h | 2 +-
fs/proc/task_mmu.c | 3 ++-
include/linux/huge_mm.h | 2 +-
include/linux/leafops.h | 28 +++++++++++++++++---
include/linux/pgtable.h | 2 +-
include/linux/swapops.h | 6 ++---
mm/Kconfig | 2 +-
mm/debug_vm_pgtable.c | 12 ++++-----
mm/hmm.c | 4 +--
mm/huge_memory.c | 17 ++++++------
mm/internal.h | 13 +++++++++
mm/memory.c | 9 +------
mm/migrate.c | 4 +--
mm/migrate_device.c | 19 +++++++------
mm/rmap.c | 9 ++-----
25 files changed, 93 insertions(+), 67 deletions(-)
--
2.53.0-Meta