[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aXsb7tBiG8mZ57NJ@yjaykim-PowerEdge-T330>
Date: Thu, 29 Jan 2026 17:35:58 +0900
From: YoungJun Park <youngjun.park@....com>
To: Kairui Song <ryncsn@...il.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Kemeng Shi <shikemeng@...weicloud.com>,
Nhat Pham <nphamcs@...il.com>, Baoquan He <bhe@...hat.com>,
Barry Song <baohua@...nel.org>,
Johannes Weiner <hannes@...xchg.org>,
David Hildenbrand <david@...nel.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
linux-kernel@...r.kernel.org, Chris Li <chrisl@...nel.org>,
Kairui Song <kasong@...cent.com>
Subject: Re: [PATCH v2 02/12] mm, swap: clean up swapon process and locking
On Wed, Jan 28, 2026 at 05:28:26PM +0800, Kairui Song wrote:
> From: Kairui Song <kasong@...cent.com>
>
> 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@...cent.com>
> ---
> 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??
Thanks
Youngjun Park
Powered by blists - more mailing lists