Re: [PATCH v5 05/19] mm/swap: change the swapon lock into a percpu rwsem

From: Lian Wang

Date: Sat Nov 28 2026 - 02:40:29 EST


On Thu, 26 Nov 2026 10:03:25 -0800 Chris Li <chrisl@xxxxxxxxxx> wrote:

> This seems to describe a lock protocol change. Very naive question:
> Where is the matching code for that? I can only see the spinlock to
> precpu_rwsem change. Does this description belong to some later
> patches or state facts already existing in the current patches where
> there is no additional code change for it?

That's an existing rule, not a new protocol in this patch. On swapoff,
del_from_avail_list(si, true) already clears SWP_WRITEOK, sets the
off-list bit and unlinks the device under swap_avail_lock. What
changes here is the outer topology lock: readers such as si_swapinfo()
take the read side of swapon_rwsem, and topology updates take the
write side. It isn't until 11/19 that swap_alloc_entry() holds the
read side across device selection and cluster allocation. I'll make
that distinction in the commit message.

> I wonder if there is a way to forward declare it so we don't need to
> move the definition.

No new declaration is needed. I'll leave swap_info[], total_swap_pages
and nr_swap_pages where they were and just update the relevant lock
comments.

Thanks,
Lian