Re: [PATCH v5 10/11] mm: install PMD swap entries on swap-out

From: Matthew Wilcox

Date: Thu Jul 23 2026 - 15:29:11 EST


On Wed, Jul 22, 2026 at 08:19:41AM -0700, Usama Arif wrote:
> +++ b/mm/rmap.c
> @@ -2282,6 +2282,25 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> goto walk_abort;
> }
>
> +#ifdef CONFIG_THP_SWAP
> + /*
> + * If the folio is in the swap cache and we're not
> + * asked to split, install a PMD-level swap entry.
> + */
> + if (!(flags & TTU_SPLIT_HUGE_PMD) &&
> + folio_test_anon(folio) &&
> + folio_test_swapcache(folio)) {
> + if (set_pmd_swap_entry(&pvmw, folio))
> + goto walk_abort;
> +
> + add_mm_counter(mm, MM_ANONPAGES,
> + -HPAGE_PMD_NR);
> + add_mm_counter(mm, MM_SWAPENTS,
> + HPAGE_PMD_NR);
> + goto walk_done;
> + }
> +#endif
> +
> if (flags & TTU_SPLIT_HUGE_PMD) {
> /*
> * We temporarily have to drop the PTL and

This makes me sad. It feels like we're bolting more complexity onto
try_to_unmap() instead of removing TTU_SPLIT_HUGE_PMD entirely.

Ideally we'd just cope with folios of whatever size (including
PMD and PUD mapped folios) and only handle hugetlb weirdness when we
absolutely have to. Similarly, we could split PUDs to PMDs and
PMDs to PTEs when we need to, without the caller specifying
TTU_SPLIT_anything.

Is there a reason we can't do that?