Re: [PATCH v2 02/12] mm, swap: clean up swapon process and locking
From: Kairui Song
Date: Sun Feb 01 2026 - 21:32:22 EST
On Thu, Jan 29, 2026 at 4:36 PM YoungJun Park <youngjun.park@xxxxxxx> wrote:
>
> On Wed, Jan 28, 2026 at 05:28:26PM +0800, Kairui Song wrote:
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > Slightly clean up the swapon process. Add comments about what swap_lock
> > protects, introduce and rename helpers that wrap swap_map and
> > cluster_info setup, and do it outside of the swap_lock lock.
> >
> > This lock protection is not needed for swap_map and cluster_info setup
> > because all swap users must either hold the percpu ref or hold a stable
> > allocated swap entry (e.g., locking a folio in the swap cache) before
> > accessing. So before the swap device is exposed by enable_swap_info,
> > nothing would use the swap device's map or cluster.
> >
> > So we are safe to allocate and set up swap data freely first, then
> > expose the swap device and set the SWP_WRITEOK flag.
> >
> > Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
> > ---
> > mm/swapfile.c | 87 ++++++++++++++++++++++++++++++++---------------------------
> > 1 file changed, 48 insertions(+), 39 deletions(-)
> >
> > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > index 521f7713a7c3..53ce222c3aba 100644
> > --- a/mm/swapfile.c
> > +++ b/mm/swapfile.c
> > @@ -65,6 +65,13 @@ static void move_cluster(struct swap_info_struct *si,
> > struct swap_cluster_info *ci, struct list_head *list,
> > enum swap_cluster_flags new_flags);
> >
> > +/*
> > + * Protects the swap_info array, and the SWP_USED flag. swap_info contains
> > + * lazily allocated & freed swap device info struts, and SWP_USED indicates
>
> Nit.
>
> Typo: 'struts' -> 'struct'.
> Also, using 'swap_info_struct' instead of "swap device info" would be
> better??
Ack, thanks!