From nobody Mon Feb 9 17:58:09 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 A07AB348875 for ; Fri, 19 Dec 2025 19:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766173551; cv=none; b=Fys5Uce7+s3CqRgyRxkjO6ohwO6TCH/tdLYDzIG17ttYq9AMGX9oFoS3m7Z/5sSK7YmKL2wnL9xyMUNQcJGL9eqwEVb/0uZ46VY/gDqdYmiNSFCoHwPhHULZFwg3sPMCdgN/AOs+4ha7ea0cH3XOHYflRMafkkb0I3AnyGGkuK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766173551; c=relaxed/simple; bh=ns0pHLHd/jEjqUYFJLjXB/fXVWjjHDPM7TpSzEpBVSw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hDEOGBQQL3hNGRkDFkPOYIt0gRWSEY5MBbYbOTUx+LUAOd3Zhf/hFNQ5oD39/GmBSFv+DNV0kaGppHKh5KoYn6zUhgjDVOrEIUI4EU/D9kaYI6ngpOcspShyiubicmFqjBEQDONVc/2cbykQyUzytVAj/C6UR2eKSCyzpYFD4xU= 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=GQgHFaLX; arc=none smtp.client-ip=209.85.214.171 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="GQgHFaLX" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2a0d0788adaso19341735ad.3 for ; Fri, 19 Dec 2025 11:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766173549; x=1766778349; 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=yhrT3dYvAHuR7z+x4zbB6DCnVKLKVvLlBLpnRsQvASs=; b=GQgHFaLXhQ0f2vFfamgbKwQwv72JWge7j+QV+yAZbZOHA9Q0Iw3SllROc0/8DGylP9 mrtDhHF1KgqDzDOh/Btf81U2UFfpGVSg8ssRA37ohPpITxbtutwrEzUN+1bfRsmlAMSW XGStVcdcrJJQ4ehT1BavIFx+lkt5/wNFxUwz1sV+igp6KzzwOJPXgcOzwo/CX2QZVq2T lOB5K0N8/lpI3Y5sEUHEhuRs0HnbsA4/xRd/ZEfqOkQ+oQavsSjzWYuSVl3q9VkFRMIZ valbaH/IXhcpPbmeTb2aOAlGTPxxvFLUhdLybPUJKPmVltW5e7FP0w1iiLkYl/CdMkXc p6Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766173549; x=1766778349; 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=yhrT3dYvAHuR7z+x4zbB6DCnVKLKVvLlBLpnRsQvASs=; b=Svj9MpQfoSFh6+YkDFp+gblk1GT3jmfJ65v1c5Tkn2BaT4RNbtjytOYny1+lWUIAHX pV1ny/3EWofJkM60wCE+R27j+oXWb9goKxa2ufCq0PlqGN/M3wMmvRrJiLw1Rf/8SQ6L z0wEhOi9d4WlH7PTvSPpLEq3/LeGgOqt8RwYrEEV3pWL8LcDg7nWbqho65+c/QaIpz2n rodgCsNZHKtx6rF/gw60zZg3MUPd8gccM55B/D1E5xeVW5vOnYV21R7CwI2t0vIW6DTi sRHP+6hPJwxwq+qmSl7MJPB6cOv9bUPkMSIokDdTSz7kx5fRhRznvfWDn9Lye9h7Ugqh /QPA== X-Forwarded-Encrypted: i=1; AJvYcCW4N6/CNy1nfNc0AYUmaM1VsNUTi/jBxbr6Sh/4/HM9WZFJWqnlpQMN816o0FflYUH7hc9w02ieHIhwkd8=@vger.kernel.org X-Gm-Message-State: AOJu0YzqsljHvBgSL3O0QghMCKmFPV6fPROxjhBvg1CiuGG0JZHpJeie RWgnRXAa1kvd+HuDB9QFOczfyc8zEeZaAH3Pfu0+b4+x+Q+AVs9vXKgE X-Gm-Gg: AY/fxX4waSZtRDa0lufWe5VRjOfGFIv0B1u22geLy+YhtbO0IZwmca1Tdxb47j7Kcqi IVLSFdOhQBpu/cwxnszDRY2lN9mSOC/3WSI76Nlp13uEKAmtvKMaWy/RAJazAlSq14LofSzUcsk 4srlyBwowZV8S6JctkY4YOIovOSktjlY7IxpV/vZGidqYxOM2hb6TJAfQeToJpRvol2a1SrXCa9 XHxnbx2hEotXxpI2JrKpI8Pt2Og9/aMkbM69OysBM/NRQlGCdHsELphK5YjerT4gZBTIFRIOY2w Dz6/Wll7MYh1Xd08X0LKhJXUV0masHLM3+BEXQOT0QmltIvdZyGrEQiXnK/TpcRU6R4MLYBu129 kMYIja4Ab1COak6NXaIJY659lJ2pjd6fpCGFHinUPFfDA1SiJ+3tpexun1fNEZg6bjFCKIcjHeF SJzHmchd2LcE+Bz1ycmHUNf46iBbTPVELaAp8iSJJo27Aw4vW1UPpBr6EIUjUNfYI= X-Google-Smtp-Source: AGHT+IHYkvMNmtufwGbQFZyaAJlBw5lJ5+Po+hUSBwaQcbyjQEel2hdkBOLfJ0tXOUXH+Tpsl9Ec0g== X-Received: by 2002:a17:903:b83:b0:2a1:388d:8ef3 with SMTP id d9443c01a7336-2a2f222bc6amr41151885ad.18.1766173548952; Fri, 19 Dec 2025 11:45:48 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d76ceesm30170985ad.91.2025.12.19.11.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 11:45:48 -0800 (PST) From: Kairui Song Date: Sat, 20 Dec 2025 03:43:48 +0800 Subject: [PATCH v5 19/19] mm, swap: remove no longer needed _swap_info_get 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: <20251220-swap-table-p2-v5-19-8862a265a033@tencent.com> References: <20251220-swap-table-p2-v5-0-8862a265a033@tencent.com> In-Reply-To: <20251220-swap-table-p2-v5-0-8862a265a033@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Baoquan He , Barry Song , Chris Li , Nhat Pham , Yosry Ahmed , David Hildenbrand , Johannes Weiner , Youngjun Park , Hugh Dickins , Baolin Wang , Ying Huang , Kemeng Shi , Lorenzo Stoakes , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1766173451; l=3385; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=pCVvSP05LttLarbkjFKj8kSFxDT7Dt4yyCzNi6fJQ+k=; b=t5W6ua32Km122SKf4fxjddcswwCKbIbefSoFS8ELA/zydvgz+HlYq42nSlpLbQZLwwNab82Mm KdT6vb8aUcJAVN1pAltmNw5XUP5FcmaVvV8kNIADb5tTgy8HN9bpgdh X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= From: Kairui Song There are now only two users of _swap_info_get after consolidating these callers, folio_free_swap and swp_swapcount. folio_free_swap already holds the folio lock, and the folio must be in the swap cache, _swap_info_get is redundant. For swp_swapcount, it should use get_swap_device instead. get_swap_device increases the device ref count, which is actually a bit safer. The only current use is smap walking, and the performance change here is tiny. And after these changes, _swap_info_get is no longer used, so we can safely remove it. Signed-off-by: Kairui Song --- mm/swapfile.c | 47 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 886f9d6d1a2c..1ee13390d910 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -83,9 +83,7 @@ bool swap_migration_ad_supported; #endif /* CONFIG_MIGRATION */ =20 static const char Bad_file[] =3D "Bad swap file entry "; -static const char Unused_file[] =3D "Unused swap file entry "; static const char Bad_offset[] =3D "Bad swap offset entry "; -static const char Unused_offset[] =3D "Unused swap offset entry "; =20 /* * all active swap_info_structs @@ -1600,41 +1598,6 @@ void folio_put_swap(struct folio *folio, struct page= *subpage) swap_put_entries_cluster(si, swp_offset(entry), nr_pages, false); } =20 -static struct swap_info_struct *_swap_info_get(swp_entry_t entry) -{ - struct swap_info_struct *si; - unsigned long offset; - - if (!entry.val) - goto out; - si =3D swap_entry_to_info(entry); - if (!si) - goto bad_nofile; - if (data_race(!(si->flags & SWP_USED))) - goto bad_device; - offset =3D swp_offset(entry); - if (offset >=3D si->max) - goto bad_offset; - if (data_race(!si->swap_map[swp_offset(entry)]) && - !swap_cache_has_folio(entry)) - goto bad_free; - return si; - -bad_free: - pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val); - goto out; -bad_offset: - pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val); - goto out; -bad_device: - pr_err("%s: %s%08lx\n", __func__, Unused_file, entry.val); - goto out; -bad_nofile: - pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val); -out: - return NULL; -} - static void swap_put_entry_locked(struct swap_info_struct *si, struct swap_cluster_info *ci, unsigned long offset) @@ -1794,7 +1757,7 @@ int swp_swapcount(swp_entry_t entry) pgoff_t offset; unsigned char *map; =20 - si =3D _swap_info_get(entry); + si =3D get_swap_device(entry); if (!si) return 0; =20 @@ -1824,6 +1787,7 @@ int swp_swapcount(swp_entry_t entry) } while (tmp_count & COUNT_CONTINUED); out: swap_cluster_unlock(ci); + put_swap_device(si); return count; } =20 @@ -1858,11 +1822,12 @@ static bool swap_page_trans_huge_swapped(struct swa= p_info_struct *si, static bool folio_swapped(struct folio *folio) { swp_entry_t entry =3D folio->swap; - struct swap_info_struct *si =3D _swap_info_get(entry); + struct swap_info_struct *si; =20 - if (!si) - return false; + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio); + VM_WARN_ON_ONCE_FOLIO(!folio_test_swapcache(folio), folio); =20 + si =3D __swap_entry_to_info(entry); if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio))) return swap_entry_swapped(si, entry); =20 --=20 2.52.0