Re: [v2 02/16] mm: extract mm_prepare_for_swap_entries() helper

From: Zi Yan

Date: Sat Jun 13 2026 - 14:53:52 EST


On 2 Jun 2026, at 10:24, Usama Arif wrote:

> When a swap entry is installed in a page table, the mm must be added
> to init_mm.mmlist so that swapoff can find and unuse its swap entries.
> This double-checked locking pattern is currently open-coded in
> try_to_unmap_one() and copy_nonpresent_pte().
>
> Move it into mm_prepare_for_swap_entries() in mm/internal.h and convert
> both callers so it can be reused by upcoming PMD-level swap entry code
> paths that also need to register the mm with swapoff.
>
> copy_nonpresent_pte() previously inserted into &src_mm->mmlist rather
> than &init_mm.mmlist, but the insertion point is irrelevant, mmlist
> is a circular list and swapoff walks it entirely from init_mm.mmlist,
> so only membership matters, not position.
>
> Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
> Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
> ---
> mm/internal.h | 13 +++++++++++++
> mm/memory.c | 9 +--------
> mm/rmap.c | 7 +------
> 3 files changed, 15 insertions(+), 14 deletions(-)
>

LGTM.

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

--
Best Regards,
Yan, Zi