Re: [PATCH v8 08/30] mm: recognize PMD swap entries in the softleaf layer
From: Zi Yan
Date: Wed Oct 07 2026 - 22:07:14 EST
On Fri Oct 2, 2026 at 5:52 AM EDT, Usama Arif wrote:
> Reclaim splits a PMD-mapped anonymous THP into PTE-level swap entries
> before unmapping it, so an ordinary swap entry has never had to appear in a
> PMD. Prepare for installing one there instead: the softleaf layer is where
> every consumer decodes non-present PMDs.
>
> Accept swap entries as valid PMD softleaves and add pmd_is_swap_entry().
> A swap entry carries no PFN, so make pmd_softleaf_to_folio() warn and
> return NULL rather than interpret a swap offset as a page frame number.
>
> Unlike migration and device-private entries, a PMD swap entry can also
> carry the swap-exclusive marker, which softleaf_from_pmd() has to strip
> before decoding. Strip all three overlays unconditionally while we are
> here: each clear is a plain bit clear, so testing first only buys a branch.
>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Reviewed-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
> ---
> include/linux/leafops.h | 40 ++++++++++++++++++++++++++++------------
> include/linux/pgtable.h | 17 +++++++++++++++++
> 2 files changed, 45 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/leafops.h b/include/linux/leafops.h
> index 7c13c58a5e218..ce176c78cefd4 100644
> --- a/include/linux/leafops.h
> +++ b/include/linux/leafops.h
> @@ -98,10 +98,9 @@ static inline softleaf_t softleaf_from_pmd(pmd_t pmd)
> if (pmd_present(pmd) || pmd_none(pmd))
> return softleaf_mk_none();
>
> - if (pmd_swp_soft_dirty(pmd))
> - pmd = pmd_swp_clear_soft_dirty(pmd);
> - if (pmd_swp_uffd(pmd))
> - pmd = pmd_swp_clear_uffd(pmd);
> + pmd = pmd_swp_clear_soft_dirty(pmd);
> + pmd = pmd_swp_clear_uffd(pmd);
> + pmd = pmd_swp_clear_exclusive(pmd);
I notice there is pte_swp_clear_flags() and wonder if we want
pmd_swp_clear_flags() to match it.
> arch_entry = __pmd_to_swp_entry(pmd);
>
> /* Temporary until swp_entry_t eliminated. */
> @@ -634,18 +633,29 @@ static inline bool pmd_is_migration_entry(pmd_t pmd)
> */
> static inline bool softleaf_is_valid_pmd_entry(softleaf_t entry)
> {
> - /* Only device private, migration entries valid for PMD. */
> return softleaf_is_device_private(entry) ||
> - softleaf_is_migration(entry);
> + softleaf_is_migration(entry) ||
> + softleaf_is_swap(entry);
Using softleaf_is_swap() here makes softleaf_is_valid_pmd_entry() return
false positive when pmd swap entry is not possible at the moment. Adding
it only after pmd swap entry is possible can close the gap. But the
whole series should be applied together, so it should be fine.
Otherwise, LGTM.
Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
--
Best Regards,
Yan, Zi