Re: [PATCH v6 04/12] mm: handle PMD swap entries in fork path
From: Kiryl Shutsemau
Date: Wed Aug 19 2026 - 11:46:27 EST
On Tue, Aug 18, 2026 at 06:09:45AM -0700, Usama Arif wrote:
> Teach copy_huge_pmd()/copy_huge_non_present_pmd() about swap entries,
> mirroring copy_nonpresent_pte().
>
> swap_dup_entry_direct() gains a nr parameter (and is renamed to
> swap_dup_entries_direct()) so it can duplicate a contiguous range of
> swap slots in one call, matching the existing
> swap_put_entries_direct(entry, nr) API. Existing callers pass 1.
...
> @@ -3955,7 +3967,7 @@ int swap_dup_entry_direct(swp_entry_t entry)
> */
> VM_WARN_ON_ONCE(!swap_entry_swapped(si, entry));
>
> - return swap_dup_entries_cluster(si, swp_offset(entry), 1);
> + return swap_dup_entries_cluster(si, swp_offset(entry), nr);
> }
swap_put_entries_direct() bounds end_offset against si->max and walks the
range cluster by cluster. Here nr goes straight into the cluster helper,
which does ci_end = offset % SWAPFILE_CLUSTER + nr and indexes up to
ci_end - 1. __swap_table_get() VM_WARN_ON_ONCE()s on off >=
SWAPFILE_CLUSTER, but still reads table[off].
So is the range required to sit inside one cluster? I assume it works out
because a PMD swap entry is cluster-aligned and SWAPFILE_CLUSTER ==
HPAGE_PMD_NR, but I don't see it stated anywhere.
--
Kiryl Shutsemau / Kirill A. Shutemov