Re: [PATCH 05/13] mm: add PMD swap entry detection support

From: Dev Jain

Date: Sat May 30 2026 - 04:06:41 EST




On 27/04/26 3:31 pm, Usama Arif wrote:
> Currently when a PMD-mapped THP is swapped out, the PMD is always split
> into 512 PTE-level swap entries. To preserve huge page information
> across swap cycles, later patches will install a single PMD-level swap
> entry instead. This patch adds the infrastructure to detect those
> entries.
>
> Teach the softleaf layer to recognise PMD swap entries:
> pmd_is_swap_entry() detects them and softleaf_is_valid_pmd_entry()
> accepts them as a valid non-present type. Clear the exclusive overlay
> bit in softleaf_from_pmd() before decoding, matching how soft_dirty and
> uffd_wp bits are already stripped.
>
> Add pmd_swp_mkexclusive(), pmd_swp_exclusive(), and
> pmd_swp_clear_exclusive() helpers to each architecture that supports
> THP migration (x86, arm64, s390, riscv, loongarch), mirroring the
> existing PTE swap exclusive helpers in each arch's pgtable.h.
>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
I realize that CONFIG_ARCH_ENABLE_THP_MIGRATION is a misnomer now. It really
means "does the architecture support PMD softleaf entries?", ut has got nothing
to do in particular with migration (I think?) because migrating a PMD THP without
splitting is always a win and no arch, despite having PMD softleaf support, will
switch off this config.

So with that in mind, probably rename this to CONFIG_ARCH_SUPPORTS_PMD_SOFTLEAF?
Because it is really confusing to see swap entry support being added only to
the arches which support thp migration.