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

From: Usama Arif

Date: Fri Jul 24 2026 - 06:42:25 EST




On 23/07/2026 20:16, Matthew Wilcox wrote:
> 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?

I will prototype what the code would look like without TTU_SPLIT_HUGE_PMD
and get back to you on this. Looking at the code right now, I feel like I
would be shifting complexity, but let me try and do something about this.