From nobody Mon Feb 9 12:24:21 2026 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 D1AF82EE617 for ; Sun, 25 Jan 2026 17:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769363896; cv=none; b=lWKhFjItev6LQd8+d6mHVDQJXOAIWrnk+Z1qEA7Tapws+FSkYAaD1pU00+WbX+Q2+6H4HEseAmPyWdAsxg0o6GD4kBX8xDIt0yjM6mvHgF/bDG7xLs118mqI3TSj8kIyhKZj+6n4e7Dvbz7P82o6k1KZkCo5DlRf7voLhqhIqL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769363896; c=relaxed/simple; bh=7vhr/Y5/qe1bdq79grBj7yWIKvJOSaKIgfx4h5h9r3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TDhLqCg5mC/KuTGEmTB/+dfqu58QAxSBVVvYeis8VeLrLoOLHurFQPXeiHiIi9b8kdRk9hqIhQdZTDImGcSnCCYKccC6/Bl/u3Y3/XOY8PFX7p4X8A5VeCTUiki8JWyq0doW1UQzEcaKMZx2NqlIoZ4H6yX47796Ju9lFxlCz+M= 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=GQMQ8BfA; arc=none smtp.client-ip=209.85.216.51 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="GQMQ8BfA" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-3530715386cso3393357a91.2 for ; Sun, 25 Jan 2026 09:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769363894; x=1769968694; 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=GQMQ8BfAS3CxywFIljY5/tukKRpNXqjLoKVE98lBmkJEjUIm1QGsSAcCAm0/xarHaM rCuX30qzDc6VCEfwOvks4RFh3DdJu9zew/bEkPpslPmlzgL5kb+Jeb09zxisJi4pCcDD S6jdkzsScUrSnDR4WG4FBQnNLdVV5HRHo13zt16McsubHY+WXmfRtlEPAfHr4Wcnzklf Iu3q3aGM2B6LHVPvoNRW+V191L0bkJR14u3h6mUZTQS/Ti7vCa+QjS4IA6c4tIQPJcgk 8lKDy2f24lBEm1BFc+LgdeKtZeEnNNGARHH7CzK7LFk0mA6ziWGBbSmxYOb05C3nVFwp V5og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769363894; x=1769968694; 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=OtJsgAla14Iq3R+hHKcJo/VtTrZH97l+9ns0KfhvaViP7D8S1kFx8Z+9tRqvyHe+fr GG56np0yUi1SoT8iQrZrG4KqUKmmrhQxMVRUI1ZdbNmaOO70FtCn5TjJkpi3mgkePkqs 6cN8IOOraLPVOoQNlKkTMtzzZd1WAZ1Hrej5LCK5Ngp+wCOi/ByIfPeb1HqIjuY497QZ VYJFX5dpvkdIG4i+xPNPGI37YBcIvvaRI7ydb0VkafFFeu6UsS0LXr9qTIc9kkinTwiA usla7G2vXXC+I/AbREonM7xNtb+hDu6Kg77pUg7Bq3X4ofxrSWtrP2j6G2ZmL/SgSqOf pfUg== X-Forwarded-Encrypted: i=1; AJvYcCVyHXRwvnLiuTnD//+07IqpeurS490FNo/cl3/1LOo29xNjcisp8wwoK9sWHPJ9HNahM2UsW8GqTUsE+B0=@vger.kernel.org X-Gm-Message-State: AOJu0YwAzQyvS0NcptCUKCx7mkP+eN3YNMpygaLWE1azBCA2oSlZOl9m rbZu6H8QkCQ0cL2RarJFFs5S1glgDYybxVkG0E5VuGwQds1nC9UWrvFE X-Gm-Gg: AZuq6aKye8JSNsYDuq/UtIOrl6fDgaaUFZ5iheDZvWNakcaErvML0xnCTgEs8m7cI7a hoPVobTAxxTulWlbEffonWuHBiNeZ5lWdfP+U6pUzO3/U0f7T2RfdCKkFdp66Bcc9d18LbcQTBG PkWoUqQVlKDky+BsM1xBvSo6cH00BZQbEoLfCuHLcsl5H2JW/4Lp9kgDVvNklfb9lSLbQ5R+iWF N/bBNOVfhm6NtnEVYtVleAKhPDRTUkAmDw/rB324nRdisz19OEt9+ITzc4O0RmVTjZTG6Ks5/J6 pvbTxQLlz+4DSvidy809zWcB84WDB5yBTy2Bp5YdQCQ1bTDt/grHk2Jv64Dp5DIuZKwzdLtb9ue QGWuRGeEk4pbGQUxKaPBbKSMFk6ea8MHRubefpuEFdQ/4DCazbSBeXZaJn5jhGqMjRkVhe40L4T tUH/SJXZRjwKhprRhS6Y26advTOjM+Nn7KkOQu7rK6KVIedx+OPpB24pHffSw= X-Received: by 2002:a17:90b:2fc8:b0:352:ccae:fe65 with SMTP id 98e67ed59e1d1-353c40b3244mr1764884a91.4.1769363894105; Sun, 25 Jan 2026 09:58:14 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8231876e718sm7405963b3a.62.2026.01.25.09.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 09:58:13 -0800 (PST) From: Kairui Song Date: Mon, 26 Jan 2026 01:57:26 +0800 Subject: [PATCH 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: <20260126-swap-table-p3-v1-3-a74155fab9b0@tencent.com> References: <20260126-swap-table-p3-v1-0-a74155fab9b0@tencent.com> In-Reply-To: <20260126-swap-table-p3-v1-0-a74155fab9b0@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Johannes Weiner , David Hildenbrand , Lorenzo Stoakes , linux-kernel@vger.kernel.org, Chris Li , Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769363877; l=4474; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=VcHfIq9fX/OfsYjH1rKwFGMkjPLRnW2PTE0+Zr1fpH8=; b=BCLvnz8yeXU8dUoomn0Bh/gnIRxlBMSPd7NlZBxGfV/XLaOAi1CaL+XqpeFh8CyCoD+yyMUm2 e04jECMZ8s1DzLOPcw3DRmjDGdjqiRXh9V//ESPOpcaJUiIFnIOlqjY 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