From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-113.mta1.migadu.com [95.215.58.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6A6543B6EC for ; Thu, 27 Aug 2026 09:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787823942; cv=none; b=CPwyTMPFXCLiDDAtgZp56ZiDS4oyUyzRoQmRWIJ2zinZma0NzkJ2gxdUyawgjo2CIBav9HHQ41Xu4ty7q40w6XQAJVHyItjh13ka4aSt4dc1SL+vlTfPSSeJo8Z1cR0Wv03KDjqtjbXBC+RwNWWKLy21aIeGvxevXTQgwfAPjpI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787823942; c=relaxed/simple; bh=TdBLta3jsQfZ+8oQA1X4kLX/S8e1/V16CljY0SjdKtc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-type; b=gqzdHys1mW+xWYQuvA3dOJyzW3xT75+yh3FnYtodSkwsbgd8mRsgc0QKLKce75CA0RVQGY/Uu6qMo1GblX18XdfJnItV7vZbMHSGUh/xipRRa4rmYeh64VJUdABiZLSrOkVEQkVNav2qyIt993SyKQv+5fgp2xsyN2KJxf3LDkI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=95.215.58.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta12.migadu.com with ESMTPS id 18403291e118a5e7; Thu, 27 Aug 2026 09:45:35 +0000 X-Mizu-Trace-ID: 18403291e118a5e7 X-Migadu-Flow: FLOW_OUT From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, hannes@cmpxchg.org, yosry@kernel.org, shikemeng@huaweicloud.com, chengming.zhou@linux.dev, baoquan.he@linux.dev, david@kernel.org, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH 04/16] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Date: Thu, 27 Aug 2026 17:44:54 +0800 Message-ID: <20260827094509.1016740-5-hebaoquan@kylinos.cn> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260827094509.1016740-1-hebaoquan@kylinos.cn> References: <20260827094509.1016740-1-hebaoquan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-type: text/plain Content-Transfer-Encoding: 8bit Change free_swap_cluster_info() to accept struct swap_info_struct* instead of (cluster_info, maxpages) directly. Extract cluster_info and maxpages from si inside the function. Also clean up swapoff: remove the snapshot locals (maxpages/cluster_info) and move the p->max/p->cluster_info clearing after free_swap_cluster_info(). This is a preparatory refactoring, no functional change. The new signature will allow the xswap path (added in the next patch) to access si->flags and call xswap_unmap_clusters() from within free_swap_cluster_info(). Signed-off-by: Baoquan He --- mm/swapfile.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 5aa1ffb97df8..cd7e889f073d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3054,14 +3054,17 @@ static void wait_for_allocation(struct swap_info_struct *si) } } -static void free_swap_cluster_info(struct swap_cluster_info *cluster_info, - unsigned long maxpages) +static void free_swap_cluster_info(struct swap_info_struct *si) { + struct swap_cluster_info *cluster_info = si->cluster_info; + unsigned long maxpages = si->max; struct swap_cluster_info *ci; - int i, nr_clusters = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); + int i, nr_clusters; if (!cluster_info) return; + + nr_clusters = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); for (i = 0; i < nr_clusters; i++) { ci = cluster_info + i; /* Cluster with bad marks count will have a remaining table */ @@ -3100,11 +3103,9 @@ static void flush_percpu_swap_cluster(struct swap_info_struct *si) SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) { struct swap_info_struct *p = NULL; - struct swap_cluster_info *cluster_info; struct file *swap_file, *victim; struct address_space *mapping; struct inode *inode; - unsigned int maxpages; int err, found = 0; if (!capable(CAP_SYS_ADMIN)) @@ -3196,10 +3197,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) swap_file = p->swap_file; p->swap_file = NULL; - maxpages = p->max; - cluster_info = p->cluster_info; - p->max = 0; - p->cluster_info = NULL; spin_unlock(&p->lock); spin_unlock(&swap_lock); arch_swap_invalidate_area(p->type); @@ -3207,7 +3204,9 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) mutex_unlock(&swapon_mutex); kfree(p->global_cluster); p->global_cluster = NULL; - free_swap_cluster_info(cluster_info, maxpages); + free_swap_cluster_info(p); + p->max = 0; + p->cluster_info = NULL; inode = mapping->host; @@ -3574,6 +3573,8 @@ static int setup_swap_clusters_info(struct swap_info_struct *si, if (!cluster_info) goto err; + si->cluster_info = cluster_info; + for (i = 0; i < nr_clusters; i++) spin_lock_init(&cluster_info[i].lock); @@ -3637,7 +3638,7 @@ static int setup_swap_clusters_info(struct swap_info_struct *si, si->cluster_info = cluster_info; return 0; err: - free_swap_cluster_info(cluster_info, maxpages); + free_swap_cluster_info(si); return err; } @@ -3856,7 +3857,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) si->global_cluster = NULL; inode = NULL; destroy_swap_extents(si, swap_file); - free_swap_cluster_info(si->cluster_info, si->max); + free_swap_cluster_info(si); si->cluster_info = NULL; /* * Clear the SWP_USED flag after all resources are freed so -- 2.54.0