Re: [PATCH v8 11/30] mm: split PMD swap entries into PTE swap entries

From: Zi Yan

Date: Thu Oct 08 2026 - 22:19:51 EST


On Fri Oct 2, 2026 at 5:52 AM EDT, Usama Arif wrote:
> Once a PMD can hold a swap entry, everything that splits a PMD - mprotect()
> or munmap() over part of the range, MADV_FREE, a pagewalk with no PMD
> handler - has to be able to split that entry too. A swap PMD already passes
> the pmd_is_valid_softleaf() gate, so without this it reaches
> __split_huge_pmd_locked() and falls through to the present-PMD path, which
> pmdp_invalidate()s it and calls pmd_page() on a non-present entry.
>
> No reference counting is needed: a swap entry pins no folio, and swap_map
> is already one per slot, so the PTEs simply take over what the PMD held.
>
> The migration-only entry point cannot reach the new branch:
> page_vma_mapped_walk() never hands back a swap PMD, and
> __split_huge_pmd_locked() already asserts that to_migration_entries
> implies a present or device-private PMD.
>
> Test the pre-split old_pmd rather than re-reading *pmd in the trailing
> folio_remove_rmap_pmd() gate, so every entry-type test in the function
> interrogates the same snapshot. That part is cosmetic: pmdp_invalidate()
> leaves the PMD present as far as software is concerned.
>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> mm/huge_memory.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
LGTM.

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

--
Best Regards,
Yan, Zi