From nobody Tue Dec 16 13:21:43 2025 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 F20AC34EF12 for ; Thu, 4 Dec 2025 19:31:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764876668; cv=none; b=FP/HIcBw+BeyNt19DNg7vWEnWH7UqdsPZX9yx54vgylM1HbwSJfTUF3N0JIv98YPu4I2TJeVeyegTFP19/vZF3rhkqMxNzC+lKDkvxDgUxP0AXPUbEJHrN+82lR0aJWzf9he2aWNTCNXfiL2XDTxIG4HXUGtrxuQaVF1zHyDS68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764876668; c=relaxed/simple; bh=ZNrDIOvCVsDS0380qZ6vhztkRDw4nDreckVx6O6xHyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AvC4O1edQrjUELAz3PJOa9w/vcWIivToZMILk9JOj8YSk6CHIkQ/uOpAlE5vLunIm9swxe0+6iHcwF2rK4748vWRxg8sLTv9VigbV9n2NmcfEGZaS3m6fJi81gv4WR+QE2cmG4q0S6EJ5uIW+aZpmezrZ72tmcwy64vggbZs5Zk= 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=KwOrCeqS; arc=none smtp.client-ip=209.85.216.49 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="KwOrCeqS" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3436cbb723fso976375a91.2 for ; Thu, 04 Dec 2025 11:31:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764876666; x=1765481466; 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=LIMoyBwJn7av90qkAfxn/q6wIjiZW7ZSAh6MwAXyokE=; b=KwOrCeqSXRQao9EqTToAmJhCoG4Q7uXfK/odZbru5zA3U5bS7UbTRYRomuoC2hF3RL ukph+O2Gh8D/hzI8OhZJdgT3Q2JsOvZ55FDe7Tcy+DEQdhJnGoUkdHi5j6naqgiw01tF MMe19lKIHuggvDGLLMAJLGTGYX98suekuwcrdYBPLIajZI+jPw1seuSsmwuZkxFXrF9W 0/6uDLRWA+xlA97cmL9D5nW+k/2apKkmJEDf9CiWPhKRSu06ak9NicSdFxHZ4u6CW9JK d+zSjVlpfwOQ09B2zauZ0cIEb92NMNH7tOiapaWbW8YIQNMcPxrmAT1uB8WAqOf6XUXw P/dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764876666; x=1765481466; 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=LIMoyBwJn7av90qkAfxn/q6wIjiZW7ZSAh6MwAXyokE=; b=EbbwX0RQ8QqBUxifryKWdvqOrLTxyHOGuxhB7to0y5Saf4LGrQUBEBQEEUdPJ6qpOh /LVZXDTtuDBjORxa4uyjZEUlKxUv75mA+RQVDaXvDhzh3cDGdjSG2IpAEucIhLKloKlu NcDfJiGd3BXvS0r4cvVlpIHaNd/lU7OJlD5mvdKsw8gMWh8Ocmo9nvQ2J0zpbk4x2YXg UNYXtnJXJisEBgdabQaBxNlQWZHyYA26EhtLaSdQI9PgWsXVw5r9/VSTzExcyAFkVgQE uMv+M9ozEKRFluqN0nLKYPZYiSiKgR+jBRuWFAdCzJ1ArZ2NsFaCJtAltP0ZNIIuuSae HGXQ== X-Forwarded-Encrypted: i=1; AJvYcCX712CxKiucn7fS/nwSXzGP7QqN1wiLm1N6JahIDUql80l6qWzM77NsaMWewz7mfqnY2lOoA4BykH6jpyE=@vger.kernel.org X-Gm-Message-State: AOJu0YyjY9SvkVijlcI3zq/+I1p+pYR+Ws2JpbplnsdYuUiOsriSfb+q POuIOEz1M+xxQf8CwWyvVbiQ15aIpQPPtF7apo4ULCzrMgiOmZHL+YUI X-Gm-Gg: ASbGncsDq2SabA61arI97uQv4oZjpEX1hrBAnXduRL8LHH3MmQ/Lwed9YEZjuW/hHdl 2kzoYXR7Mf3S5CqTwmoDwZnlPns9RpxdNJH6gdmO+cTHVl9NUSIE7ifW0oRbwcN+GDU9LnFCgG2 9sStqsQIAZDj2nqUP4NM8y75CZvFeeCsZ450mY+utpNP1y9cSqlPuqsKCLf3IZd95bI0Cw4uiET 0v2t6hFvl5x+jAQ1XAKJW65vaQVlxMiMdkUyf2eemU3VSZu8EN892fIN1umOFIfTxUK7RrQIZjW JvOShBHxzZYkydPceoRHEeuPgGnhbMlNlfbtyYm6qD9CwHkZ63uawBgSVZ/KL9z1xsP4e6VLYvG TnrMQ244COHOXly+/lYfYZ8OXK4VNSPQEmsEA0eqqqizcCUigNfBWFZaf61hwJ2jF3Ndh3SZl1n pb3MbVPa9MuENgF54+Jtaj2m2ukC70QaUbUqWZeSOBwc8rlPIJ2UrGFXpSts0= X-Google-Smtp-Source: AGHT+IHc7nv/4V6WzRg5ybDSnfl1DlbA+tXjIOJmCku4lUOrp+NzASqiXTTHgcTYv3FBrgDA7wq+wg== X-Received: by 2002:a17:90b:4b82:b0:336:bfce:3b48 with SMTP id 98e67ed59e1d1-34947dabcbbmr3753351a91.9.1764876666104; Thu, 04 Dec 2025 11:31:06 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf686b3b5a9sm2552926a12.9.2025.12.04.11.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 11:31:05 -0800 (PST) From: Kairui Song Date: Fri, 05 Dec 2025 03:29:27 +0800 Subject: [PATCH v4 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: <20251205-swap-table-p2-v4-19-cb7e28a26a40@tencent.com> References: <20251205-swap-table-p2-v4-0-cb7e28a26a40@tencent.com> In-Reply-To: <20251205-swap-table-p2-v4-0-cb7e28a26a40@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=1764876574; l=3397; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=Hx+6RnEV6CvOtID5C4mncKak3zAk83r8RmTaFWHQlOY=; b=KjUWPjf/oIz3MVxWSNNjn0n/F6ra+PBZg3ElsA0eu14B/aoaT73yAjmo6sF/TjF54R4crzumu indUS8L6+RJDdd6gxn9Behlg073fv1wDi9pSKEpUf282zsXcF1vZqEZ 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 50ed2d7f5b85..ce2a34858fa1 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) @@ -1793,7 +1756,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 @@ -1823,6 +1786,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 @@ -1857,11 +1821,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, swp_offset(entry)); =20 --=20 2.52.0