From nobody Tue Dec 2 01:06:32 2025 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 636882D9EE8 for ; Mon, 24 Nov 2025 19:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764011834; cv=none; b=JOSSPY2D+ugSgCQI/Q1K4fV0hpo0e9hKLE7M3YQDEBJFbBhl3JfjWxeaaJlwAI3+22Y/D2aZnM30coXH0Ys/NZb03R0Oy25w9C2WV87WvW17XhHya8/RyDZotJag9qxjafAtWEaAufWG+UkFsG0aR0c2hqbPhvZTzFV8JlSdODQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764011834; c=relaxed/simple; bh=NuOXeDU6kBPbCkYEU1LXrj0BxPy9HLvcKFDjBH49Wzg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kmvAfkbJFjR9Dkio6YSsFFwCeeOJzktM/L69ioCTOrGdKCoWr6ETDV5q6HTJqxggF5MJuUJcKsk34YPlMqEl8yozKy7BqmgWMVzLTkhJjNsDhwTJNHdhzXA5ZwH+oSaeWB4J6GoKOY6uZ/vZ3NMwOIpFwCFFYatP5clWDOMlcp4= 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=KKhVcW0h; arc=none smtp.client-ip=209.85.210.181 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="KKhVcW0h" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7bf0ad0cb87so4510822b3a.2 for ; Mon, 24 Nov 2025 11:17:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764011832; x=1764616632; 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=ipXeMGLwUS00AgxE4fTHfgEHnRGf4+zO4yZv4QMX+tY=; b=KKhVcW0hN+NAcLBCM3Pr78sbsT/aAqmUOvVd6x4vTW8iAfj8f9xsLIkTiGKFMTzRML 85dk3lD4OcfDTRIp2dan6RVcsjxiozh5iuKZ4QfLSmXq/PfMFHnfyXI+f1kqT15LD7rD Ajnkc5s+g0gJwGZjABnCcbbdplQB8i5K5J3VBiI+FaiIZTZ1hsuwkpSojRvSLyv+fZrg N2QAlpj3+bdIrPRbp77hJISJtz5fhTExvW9gjn5GTJVqyR07doD5HQarBZwEzZwcaBHC UPO0NWSkLF9sbNFJ9mqqVUuuAWEizH1fCn3W9CjDVIBSwFJegLaVtrt8LwKYLG/uAddY /8Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764011832; x=1764616632; 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=ipXeMGLwUS00AgxE4fTHfgEHnRGf4+zO4yZv4QMX+tY=; b=dg7rR52jSZgcoK2alp8OzyMG5l2mvOAgv2pDHvA6HjYeqaK+nUl0J5ZLaYml37H0d6 uWvOC+gf7kgCF6m3ev2TQ2ksueXWHsvmbERAxNCAKNVACHYOTKE4EUEo+zCSWoDI8v0V Kjt4iMCcAFg9Al+A/MoDY31UWloH0frORyZB0wvk2uXwCQmrfBwidv6kdeqNzMqzKmgN z3eC/WNiVFeszGC+zyCG/XuFZ5CyZrRGI9V3r3r0k4Cx7mHjUj6NysLyXRQSS19Zcobt jqfgo3wPRobQz3BJ3hZ9VDQWWSWJ/LVk3m2f+optRU+vkRQMlgTRPeLnFkJUOY8/1VyE UIeA== X-Forwarded-Encrypted: i=1; AJvYcCXBu31TiEYZA5DW6o65iL5SimFz/KhzhSFFRMk8wi+h5nA1Af+SU9AS5G3tZuqyyL07EHYSkdfEaZiCA4A=@vger.kernel.org X-Gm-Message-State: AOJu0Yy02i37mrB84esD/he5LL7Fh4RX5iZPU3Nk/rjv2Pbupfv/+c44 3JxGVLBs/YIHtq76ok4tChYZ4RxdApIryCQn+TFKexZomBBuiHauApIM X-Gm-Gg: ASbGncsaTyVIQ5hVlqbDg2C6s1jswG5AfnpOFhiTXc1UDgHW1QpUdCUJWIwoDuQmDIT SlDEWPUw1XwejM3VAAGKN9+rqya5Qp4qmi0dDSgb7+PrC+tt92fZOHq7EHUmD80X0lYF1BV3REl lqYCVtY17GtI+JHA2jdkH310IoGxb54JNR3xS9IgkHm2oao30yd89nw+DTyudAul9T0xjFRF9X1 CV8T0J6p/ihAtijjfiR5oW5NVf1Pm1BQ/Qqcao6kU+Klr7HLyYf9JVIZxwsclWNEOQIRMd39t/e D176z+B84+atWBB6xvkMvKh/T9lqO/yqyiDuiyc7Gel5vjUyeZ5fD6Ecd6CNEAMpmdiE/fyXXsA Bj52eZNq4RzXSKBdMULfqLfoTHLWwF4UQl36by4Gkj/OTlj7MJbewCmD48aLG32z5XNgsX1jE+J 6iG7vJnNITILHt7GG5fsGqqGpqWtxZ4LZIhdSWNngRJfTEXzbs X-Google-Smtp-Source: AGHT+IF9pmdrLRfwkVSrwzmwVH/8sR8ttEwuXPdu0FQKbT2rnRW0P3S5L6s9lD9AjOwFibcZl8+83Q== X-Received: by 2002:a05:6a20:9189:b0:334:a180:b7ac with SMTP id adf61e73a8af0-36150f05e9bmr13653593637.39.1764011832539; Mon, 24 Nov 2025 11:17:12 -0800 (PST) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bd75def75ffsm14327479a12.3.2025.11.24.11.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Nov 2025 11:17:11 -0800 (PST) From: Kairui Song Date: Tue, 25 Nov 2025 03:14:02 +0800 Subject: [PATCH v3 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: <20251125-swap-table-p2-v3-19-33f54f707a5c@tencent.com> References: <20251125-swap-table-p2-v3-0-33f54f707a5c@tencent.com> In-Reply-To: <20251125-swap-table-p2-v3-0-33f54f707a5c@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=1764011730; l=3397; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=C+wGETtNWjFBAIszWBWUQ0AB6Ts3cedoLdPlGNc1qko=; b=xAXi8hRLR0CKEwSihjhMaupTrBszmAPy2MMlSOA+zsn3GBmo/KsQJzG0X12L1V0ywNHH1JQIZ wj0EI+ZhtflA+uAjgX35RDPXjkdyoeyNrh1egeU6J4HBvuZNzMCHHRh 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 eea904dc08d9..feb57e040ef1 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 @@ -1588,41 +1586,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) @@ -1781,7 +1744,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 @@ -1811,6 +1774,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 @@ -1845,11 +1809,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