From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 BC476313E17 for ; Sun, 16 Nov 2025 18:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763316840; cv=none; b=VSvxsermWP2n8wNSUScpsqyEx2cst8VEAMQ1hm9TYSxurE0R98EWNb1AnR4syXxuI13lOYJObKAu01J28Lv2SV61ec/iKbHO2n6DkqPXAdoK9FedUpA4yP+AUputckDIcXOC/i+rdCxfjHDxdi+ElHjPPdSob/m7Y0LfJAg74Vo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763316840; c=relaxed/simple; bh=XbS0tFsv8/xWNIqQNOr/F6UE6kMBWlBkXH/XzW/L3SY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o46jnf3Y5wMGwdpx7PuGRoahfYbXsGIMgiaFKQXyPdk/mCOFFwjv13AFF2yef6O6WXwJL6XQSYC8xJdyYxCOA/jjUI4O8dW6Qap9FmaEGZSyepDqP+6mE7/aWFbl7nyTcZUDMR7ko3PLqX8bQs1xHeGu4pSuDYYncz8by0MzUbY= 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=BhQ5VKZF; arc=none smtp.client-ip=209.85.222.178 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="BhQ5VKZF" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-8b2dcdde65bso166818485a.0 for ; Sun, 16 Nov 2025 10:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763316837; x=1763921637; 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=l3dUwhm6vJwFmY+aM3r1lF+lFC/h0oyHUqDU3K2sKVY=; b=BhQ5VKZFmApQ3dwM0cYpfazv3ct0fETzS26GeWNZ5SjeRS3fKk11Q6yRnXuI0t0Dwp 2Ivsm9SKVyuhOUpnltPCrdomxgCx1seuzxJ4fqSQ1niDRl0q8MaC97VcjSTHaFRyXjxe HfDt7xY/BNpuLiVyGkohu+2fAbwGyEUfAnFeUe2L4pqr2ZIMJO5NUDfsAgG2uaBmnvv2 bmXqJNF2xpUYFPibG4WRQ8+2BsRi9H8qEPcuaFeu2+WIqlJPEYgnrawNaZMnsjbRMJhE eiUHFcI3F8WvgESId28OPK7cc2VpMf2NMgARODxG0OTFxZSk+0jFYX03NHQ9sSPRyam3 1CTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763316837; x=1763921637; 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=l3dUwhm6vJwFmY+aM3r1lF+lFC/h0oyHUqDU3K2sKVY=; b=ue7aWIREzsnYltAz+ridm3CdvPMPBWfCB+7rIV1kUd9r5Jdy5x1ESJdkJaNcmsMXkG 8qTBnPR+u/WsvEH/3hGoWdT0JHbAX+Gu9jV80mMoynr7AJOOrS4ZfwWdp2myowqlZnJq acIeFfDOTZs+FDP6qj+6fpAMM8RpaEoFNNkSDVxZUgYseCAmX3SFuGME0F6Rs2zvXvQU dpNQirMYMYel2fuZi3j/s4uys6T3vohpXgb08U3pcbK+KNl7cZy0Tz72x2ppBqs7IugM c3F3i0XvtV2i5F+f0hO841Z5WEo+9BhLXYX+uegDNB6dbwOH0vcR2bSqujnlnqmyO/Nn JqPg== X-Forwarded-Encrypted: i=1; AJvYcCW/k/kJrfYDsFYyk53xnhU5XfFbcXkUK92UJFBG7EOAWw2NS11Wn7Pt9oJEQm4UTtaMWyrc1c59n8Evhts=@vger.kernel.org X-Gm-Message-State: AOJu0YwZpCIJt6KRDouMc+KliBJ2/OMPo7Pdd7nlBEOqytJFdp6etenS OpC7tZ7gN6Toe1Jl7848mQUCOCsyUbYeNIfUtDh3Uqc5sxK/W6h2qgVB X-Gm-Gg: ASbGncugoqbzcHCM4YrQvbTBVnR0JAMcN7Ln3rVgLOfROKErX/D1CX6YJ0gOM4OTSRi gnIKNDDM/I8hCoBfQgC+Eg3csNHzD+q+YEGWyZg9LaVlc+8ZXOk6jn1MIv9S9fEC7SDvafEAnjd fAVBkfvVVXYNgOM+zulTLMia4IH3U1XX/mAE9QQe5wBpj8hJXvcNztgMcdPqBFE2RSIfOF5zJtV O6Wc3AlkvSM70IGgc7H/04faWed3x4vhMjrXCBMbz396+vNBnJKv9euX0bhd+0OwGHEx63Tshb2 XI3Weynk6/cPPM7FnX+iegmBuKsJBAsTHDyImp7Q/UGYdywdCdePvaGOUa0uQQGNgXoLb4OiQgx d6/FX8DelBuQeInHGG4LktkBZGvy+NFHuxTn2cc+nn7Ky/1gyhe6Jsk4FhsPLKJvHvIckWaZbbX UXBWkaWzcXFvRwdr5OrgWEm59MjcOCm3QZh7h7uslTVTWSBXF9zym1 X-Google-Smtp-Source: AGHT+IE5n95/jOZaqH4x67JUv8UQnRKg5lwvfYjLFJV9mV5OL1WJP0KweIGTqnY/yCheVO7FE1+xmg== X-Received: by 2002:a05:620a:c4d:b0:8a6:e160:9b1e with SMTP id af79cd13be357-8b2c3140755mr1286884785a.17.1763316837681; Sun, 16 Nov 2025 10:13:57 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8b2e089b436sm305447785a.45.2025.11.16.10.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Nov 2025 10:13:57 -0800 (PST) From: Kairui Song Date: Mon, 17 Nov 2025 02:12:00 +0800 Subject: [PATCH v2 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: 7bit Message-Id: <20251117-swap-table-p2-v2-19-37730e6ea6d5@tencent.com> References: <20251117-swap-table-p2-v2-0-37730e6ea6d5@tencent.com> In-Reply-To: <20251117-swap-table-p2-v2-0-37730e6ea6d5@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=1763316712; l=2873; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=6T04beX0GGSCB6YCwUEk5OpfcEwSjNbZ+ToNclWdUX0=; b=W7OVts4nsc79qmFvrVhRBOzy1wzll6Cu6AwgKE4FYlSsHvfwyr19xOLzvrv8SW2ZApDX3ulPj /7Xl7gJPxlKAFEOScR31zfxy/G8ZEp3OBR22N7sSKJg6Po0A9p1H19S 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_try_reclaim_swap and swp_swapcount. folio_free_swap already holds the folio lock, and the folio is in swap cache, _swap_info_get is redundant. For swp_swapcount, it can just use get_swap_device instead. It only wants to check the swap count, both are fine except 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 | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 1bb568728b85..057b927603c0 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1578,35 +1578,6 @@ void folio_put_swap(struct folio *folio, struct page *subpage) swap_put_entries_cluster(si, swp_offset(entry), nr_pages, false); } -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 = swap_entry_to_info(entry); - if (!si) - goto bad_nofile; - if (data_race(!(si->flags & SWP_USED))) - goto bad_device; - offset = swp_offset(entry); - if (offset >= si->max) - goto bad_offset; - return si; - -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) @@ -1765,7 +1736,7 @@ int swp_swapcount(swp_entry_t entry) pgoff_t offset; unsigned char *map; - si = _swap_info_get(entry); + si = get_swap_device(entry); if (!si) return 0; @@ -1795,6 +1766,7 @@ int swp_swapcount(swp_entry_t entry) } while (tmp_count & COUNT_CONTINUED); out: swap_cluster_unlock(ci); + put_swap_device(si); return count; } @@ -1829,11 +1801,12 @@ static bool swap_page_trans_huge_swapped(struct swap_info_struct *si, static bool folio_swapped(struct folio *folio) { swp_entry_t entry = folio->swap; - struct swap_info_struct *si = _swap_info_get(entry); + struct swap_info_struct *si; - if (!si) - return false; + VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio); + VM_WARN_ON_ONCE_FOLIO(!folio_test_swapcache(folio), folio); + si = __swap_entry_to_info(entry); if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio))) return swap_entry_swapped(si, swp_offset(entry)); -- 2.51.2