Re: [PATCH v8 08/30] mm: recognize PMD swap entries in the softleaf layer

From: Usama Arif

Date: Wed Nov 04 2026 - 11:45:09 EST


On Wed, 07 Oct 2026 22:06:57 -0400 "Zi Yan" <ziy@xxxxxxxxxx> wrote:

> 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.

Added pmd_swp_clear_flags() alongside pte_swp_clear_flags() and used
it in softleaf_from_pmd() for the next revision.

>
> > 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.
>

The predicate accepts the new encoding before the producer is enabled,
but no PMD swap entry can be installed at that point. Reclaim still
uses TTU_SPLIT_HUGE_PMD until the final swap-out patch. I kept the
ordering so each consumer is ready before entries can be produced.
As you said, there is no reachable intermediate PMD swap entry to mishandle.

> Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>
>

Thanks for the reviews!

> --
> Best Regards,
> Yan, Zi
>
>