From nobody Tue Feb 10 01:19:31 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 4A2B03491C4 for ; Wed, 28 Jan 2026 09:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769592644; cv=none; b=QiA/zz+UUL8lNZNicSnheCPH3ZIFbiZN4uMBtb7Mg9lgrZ3rRS6Xv5/e73T7XgNoewyvogaIhufLfE8u6f5zCBhsoiNp+Bt6qupV2U3whpc5FsNgQilg4UwaMqjNTf5TbTUDofzgqAiHxKx7na3bGJ2+rfyEaXEpY619pufjpzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769592644; c=relaxed/simple; bh=7vhr/Y5/qe1bdq79grBj7yWIKvJOSaKIgfx4h5h9r3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rOiCfT07nvGgv9anRnQJUUH0co+u7s2ov4/Km2y8I8p/FuPQKyQSNbHTQKJPXyz9ayTHE68CYjphp7GdyeTZ3+usET8DUx/f4r2m6ymTXNr1k7YuwVAhW1+zBWqAzc+/uiM2ZcWwoyIcg9+6qvDZPDSAEJEZ9uXu0L6KmCozlnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eJbd6Ma6; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eJbd6Ma6" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-34f2a0c4574so5379373a91.1 for ; Wed, 28 Jan 2026 01:30:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769592642; x=1770197442; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/oxuyrcl+senacpl825Pc/8hD6orLDCzNPV1cvMYSnM=; b=eJbd6Ma6EmCVRIiA2Bhj8eOD1utq/7Trb6lxtMexOPgqRr4BEeu3F7aiIc/hewlrvU 68FOKuR0ei+1T5TXsDPX43pvTgafwQI1HofrOqjOFlMkASX9PzbSGErCY09G4/vEr+D1 jwTPIS4NmC6JSW88dm9GOOEpF+dh3jTfGkRVH27fDths+aogRVcOW1Dx2iRDv/oeXD57 fMG6Pc5U4rQdDMMBl4LMRT9qUnqztBJrOf70x46IWv3BawyyEzTUzgbE/xQ4P77NOoBQ jpQE9qHXOiBrDFOGEvrUaBXYIxTJ6qo40ix8FEKmiLkXkxqIT3nWsgr+3dLk9HZImgPq qrdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769592642; x=1770197442; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=/oxuyrcl+senacpl825Pc/8hD6orLDCzNPV1cvMYSnM=; b=WZQocdC+L15h6fnaSKdFCrqrmT1jmnG/4E66xDy3TiGiFVpUMFwuWGRYFYVORTLu6y C7MZSsPX29V1WNSrLi9YP+ChAU7maIYSu+IGNELD0t1dHG5tNR3Gh5BSC8F2xd48V89r bUJb8U6i72D4+ZLdsGt1rPkgF6Qtb6sKOLjugmInn1vIg6e6BYJhmGKLya01MZalgr15 Xcnvi+5AMyXJzYTcuO8giEgGeoUAcL8HlQrxKGCnhAgcA4y63AEQJOYwhhYgoTt+AdfW /w8b150m2FMsXuZ2a7xSffLY9ZjaSv+K5iITPbdd2M7EePaJBzhcbaDt/hxg2yMwn+M6 L/FQ== X-Forwarded-Encrypted: i=1; AJvYcCWBqpH5tVD7tp4KU7EViXd6VaHxt9L8/XtdFzuZCtFxvmvPYUULsZsQJg5nue4nRWZLLIfHgcgcpxQAxhw=@vger.kernel.org X-Gm-Message-State: AOJu0YzqY9lv196G3aCJHHmsvZ1TGiC1A/gpeOWn/tO9vqw37axleYL8 xaSrUaKWbzfBuYpvOi84/5P8C2PkGopLbCQ60m29VC0dFPFz1GnPaGCxvl80zpJWSzE= X-Gm-Gg: AZuq6aKg7cRgTXc6sS95uDq9O7zaByahLcCehSZg35zU6YxqeVW9LcyDScCeg6Vi9TJ l7Cj/qaEkHtYJETe3AMS02I4TFCQhwJ1n+DuAJM1veb4a86K3P+Y5Zaif/TtioHYv0/EI6pNARI VuQOpNduRzb32Z8rpMZDMrP7KnP7hAqm8olvRxU8a3k1SlzIo47UAhIK0kwbNIUyTBNAMx//DBE G4A/YQe3wlpZga+ZrWYElkCAbRK9VDzGMFznxXIO4FBOdJx+d1gJ42uTv9cCI19qenMKaY3HZyM gWDow+XLSXgGzAteMqbZX8SN3tNarJHGyPEIcVzqsVZFfti4dHcrgsnNdZ2b0Px8ArlAsKUFSOi TZE0Q2pUH7GvYp7nxCZqu7p/M1jhxpvm1rN3XnQMUZZOI8ni4YzxU7gVmETRL+Itb/Yjh7mSvJG gkzZH7bfWMIb2Z+s5LIUIeCrxkv/GaEv05/re8KHLi0H9G4swMLj92BZv81lYogI0dZl9t X-Received: by 2002:a17:90b:4e90:b0:353:41e:1f51 with SMTP id 98e67ed59e1d1-353fedb0be5mr3633981a91.32.1769592642506; Wed, 28 Jan 2026 01:30:42 -0800 (PST) Received: from [127.0.0.1] ([43.132.141.21]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3540f3eca6dsm1872235a91.15.2026.01.28.01.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 01:30:41 -0800 (PST) From: Kairui Song Date: Wed, 28 Jan 2026 17:28:27 +0800 Subject: [PATCH v2 03/12] mm, swap: remove redundant arguments and locking for enabling a device 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-Transfer-Encoding: quoted-printable Message-Id: <20260128-swap-table-p3-v2-3-fe0b67ef0215@tencent.com> References: <20260128-swap-table-p3-v2-0-fe0b67ef0215@tencent.com> In-Reply-To: <20260128-swap-table-p3-v2-0-fe0b67ef0215@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Johannes Weiner , David Hildenbrand , Lorenzo Stoakes , Youngjun Park , linux-kernel@vger.kernel.org, Chris Li , Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769592628; l=4474; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=VcHfIq9fX/OfsYjH1rKwFGMkjPLRnW2PTE0+Zr1fpH8=; b=CQrft73Ff5GcHeRS8vzyEB/f+sEs/xHE/r5jDb4Ns083oBkMezObNd7E2wwq5X9CTKIjbkW0B eKFr8GD68ifBUl+KzxNsh+DrqCCW9DQzGcIPm6yThuqN5PlAbYBA+YZ X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= From: Kairui Song There is no need to repeatedly pass zero map and priority values. zeromap is similar to cluster info and swap_map, which are only used once the swap device is exposed. And the prio values are currently read only once set, and only used for the list insertion upon expose or swap info display. Signed-off-by: Kairui Song --- mm/swapfile.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 53ce222c3aba..80bf0ea098f6 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2652,19 +2652,6 @@ static int setup_swap_extents(struct swap_info_struc= t *sis, return generic_swapfile_activate(sis, swap_file, span); } =20 -static void setup_swap_info(struct swap_info_struct *si, int prio, - unsigned long *zeromap) -{ - si->prio =3D prio; - /* - * the plist prio is negated because plist ordering is - * low-to-high, while swap ordering is high-to-low - */ - si->list.prio =3D -si->prio; - si->avail_list.prio =3D -si->prio; - si->zeromap =3D zeromap; -} - static void _enable_swap_info(struct swap_info_struct *si) { atomic_long_add(si->pages, &nr_swap_pages); @@ -2678,17 +2665,12 @@ static void _enable_swap_info(struct swap_info_stru= ct *si) add_to_avail_list(si, true); } =20 -static void enable_swap_info(struct swap_info_struct *si, int prio, - unsigned long *zeromap) +/* + * Called after the swap device is ready, resurrect its percpu ref, it's n= ow + * safe to reference it. Add it to the list to expose it to the allocator. + */ +static void enable_swap_info(struct swap_info_struct *si) { - spin_lock(&swap_lock); - spin_lock(&si->lock); - setup_swap_info(si, prio, zeromap); - spin_unlock(&si->lock); - spin_unlock(&swap_lock); - /* - * Finished initializing swap device, now it's safe to reference it. - */ percpu_ref_resurrect(&si->users); spin_lock(&swap_lock); spin_lock(&si->lock); @@ -2701,7 +2683,6 @@ static void reinsert_swap_info(struct swap_info_struc= t *si) { spin_lock(&swap_lock); spin_lock(&si->lock); - setup_swap_info(si, si->prio, si->zeromap); _enable_swap_info(si); spin_unlock(&si->lock); spin_unlock(&swap_lock); @@ -3354,7 +3335,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) int nr_extents; sector_t span; unsigned long maxpages; - unsigned long *zeromap =3D NULL; struct folio *folio =3D NULL; struct inode *inode =3D NULL; bool inced_nr_rotate_swap =3D false; @@ -3470,9 +3450,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) * Use kvmalloc_array instead of bitmap_zalloc as the allocation order mi= ght * be above MAX_PAGE_ORDER incase of a large swap file. */ - zeromap =3D kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(long), - GFP_KERNEL | __GFP_ZERO); - if (!zeromap) { + si->zeromap =3D kvmalloc_array(BITS_TO_LONGS(maxpages), sizeof(long), + GFP_KERNEL | __GFP_ZERO); + if (!si->zeromap) { error =3D -ENOMEM; goto bad_swap_unlock_inode; } @@ -3541,10 +3521,17 @@ SYSCALL_DEFINE2(swapon, const char __user *, specia= lfile, int, swap_flags) if (swap_flags & SWAP_FLAG_PREFER) prio =3D swap_flags & SWAP_FLAG_PRIO_MASK; =20 + /* + * The plist prio is negated because plist ordering is + * low-to-high, while swap ordering is high-to-low + */ + si->prio =3D prio; + si->list.prio =3D -si->prio; + si->avail_list.prio =3D -si->prio; si->swap_file =3D swap_file; =20 /* Sets SWP_WRITEOK, resurrect the percpu ref, expose the swap device */ - enable_swap_info(si, prio, zeromap); + enable_swap_info(si); =20 pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s= %s%s\n", K(si->pages), name->name, si->prio, nr_extents, @@ -3574,6 +3561,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) si->swap_map =3D NULL; free_swap_cluster_info(si->cluster_info, si->max); si->cluster_info =3D NULL; + kvfree(si->zeromap); + si->zeromap =3D NULL; /* * Clear the SWP_USED flag after all resources are freed so * alloc_swap_info can reuse this si safely. @@ -3581,7 +3570,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialf= ile, int, swap_flags) spin_lock(&swap_lock); si->flags =3D 0; spin_unlock(&swap_lock); - kvfree(zeromap); if (inced_nr_rotate_swap) atomic_dec(&nr_rotate_swap); if (swap_file) --=20 2.52.0