From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1D7F606A322 for ; Fri, 4 Dec 2026 22:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JpaQQicM Received: by kanga.kvack.org (Postfix) id 5525B6B05C6; Fri, 4 Dec 2026 17:09:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5030B6B05C7; Fri, 4 Dec 2026 17:09:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37CDD6B05C8; Fri, 4 Dec 2026 17:09:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A4B9B6B05C6 for ; Fri, 4 Dec 2026 17:09:39 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3B8E2C059B for ; Fri, 4 Dec 2026 22:09:39 +0000 (UTC) X-FDA: 85507693278.21.40504E6 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf21.hostedemail.com (Postfix) with ESMTP id 7F2BF1C0012 for ; Fri, 4 Dec 2026 22:09:37 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=JpaQQicM; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796422177; b=RAO+goL6JEokoMkNbuc7ulbraTS+77HJp+l7FMxiCIJGQD+cck4pwo6MWWajAxLWMPX0e5 t0UXZyACA3++ATvlfCXzJnoxhzOYjqQ8SRpAXH0OZE98MS9Hq9rzyDLtanP/wSIwrjF0Fk Vzu/oc5k3EVfjINnsXWRByhtXZGYJD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796422177; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YIJxDw1AQia+DkETDPi+rbOncVD/pmOQC1OVJVAZ9C8=; b=5FIs+QJivVwKabn/6agDmWkZTTWMdyJMwRPqlVgGUVRaTqaXdYUhrKjoqIVgIAxD4kRley ZUcA/QjTDuiOOJW7nNHxaxYieLy6UusXcrCjMavsAxoE6FE9xX6rzXaQUC9hVftzipNHa5 SyuHiEbAyXShR+dvuDvnBhf8BNuUftM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=JpaQQicM; spf=pass (imf21.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 50129450C9; Fri, 4 Dec 2026 22:09:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E40D71F00A06; Fri, 4 Dec 2026 22:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422177; bh=YIJxDw1AQia+DkETDPi+rbOncVD/pmOQC1OVJVAZ9C8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JpaQQicMbkWp8Jidpy5gouMwSMS/znQLwbQUWROrwSWSHR+a55MiiBKgCQxGKV6Cj /ac2luPLE62OE9PtYOyvU3fDa0X6Sjzc6ozoM+9bXU1l5g5F0UKO/cQv9SE+VSLfY+ RWo2QHqCUHNNTkV7Xgl8udIQ6PUkoTeSxvVOHqe8F5V+eJuCJWIN8F25OfS777nmBu Njviv5NCumeGGMEztH+JlWtA5kw8b31UJnXIx86SwvugCmlyFYMfB0XbhE6pK/iNHu LxCveBI33vUJSWL9JgL4T2ofAVtc0B19ptgLDdRQGKegSh81wDH3e40zWkQJGBea6I plnd4U4242ygA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 17/20] mm/swap: drop direct physical swapcache handling Reply-To: sashiko-reviews@lists.linux.dev To: "Nhat Pham" , linux-mm@kvack.org Cc: "Andrew Morton" , "Chris Li" , "Kairui Song" , "Kemeng Shi" , "Baoquan He" , "Barry Song" , "Youngjun Park" , "Johannes Weiner" , "Yosry Ahmed" , "Chengming Zhou" , "Qi Zheng" , "Shakeel Butt" , "Axel Rasmussen" , "Yuanchu Xie" , "Wei Xu" , "Baolin Wang" , "Michal Hocko" , "David Hildenbrand" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Hugh Dickins" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" , "Roman Gushchin" , "Muchun Song" , "Arnd Bergmann" , "Karl Mehltretter" , "Dapeng Mi" , "Marco Elver" , "Ethan Nelson-Moore" , =?utf-8?b?Qm9yaXNsYXYgUGV0a292IChBTUQp?= , "Jeff Layton" , "Tejun Heo" , =?utf-8?b?TWljaGFsIEtvdXRuw70=?= In-Reply-To: <20261203220010.1302207-18-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> <20261203220010.1302207-18-nphamcs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:09:35 +0000 X-Stat-Signature: 4ueym5yhuu4sazsew53o68h1x5m7xusk X-Rspam-User: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Queue-Id: 7F2BF1C0012 X-Rspamd-Server: rspam01 X-HE-Tag: 1796422177-932880 X-HE-Meta: U2FsdGVkX19sYZXmvmylvRcfbdlu5IwBR/3NG7UBDj+Zdo8Wh9UawQ5MMLWrPtyoe7kf4sXmFA7vlYmrH7eSLgtIziNB1SuiVQK88zL6jdmG0gW+cPRI12jjFShhX+mJ4szQsa+V1vxMggQMfGDXDndXbkwE9N94cRlZ6vhu7BtOchgkNUJ79xxTWW8CWLc6gXyFWn03lwH8kZMIPuLemU3Cw5xmEDadjMNd+wUTddEGAzv/0wxhzxZj1P7IdG/Kl0zLDpjNxILlczrs/R5D2cet+mroqGp0NOczQIBZLCVqikrbDQJrq8XLZKvEkPBpTjnP6j+iJBMtQS3tQb4qO2RaExbaeLnojWMxpn7XzpY+kmG80DPstLpOGKTajqc0nj+GZ1vZU02mubIqKS0GivkS4S2qZL52Mx1sM5ZL7ETPlBS7J2BVUk9K0BnYUlkixrZb7wQUr4klYaXCrzOZY2JNYSIfMWzM38jxhxED5G7IlAkON+u6xV5YNW1BmOgnJPpxlLZp7vFpG8EhzGLqWstmFVj7+7VBdWHr0A3F/My5ZM94ATJPWT6+2Q25RnLsmmK0VzVLzGPG3ZCd3xtVjXFKefROGR/kCjsAIi1iyaPPIBKb+BKUBHeWvUSJicfq21kPHN9nFqiy48BaHf5bwJGa5gc34SJU7zDxIPn2A+lZur89FaJNSg+zsgfoVXAuJmxV/kIbDFQ23kj8ySTKgWWptoK6ODW7ny0Uvsf0FzscxNO+oVaEpa3spKwiZXuWBGFZU+GY4z9GGCeoJ+5HvmUB17iAHyVHgHgoj+6VN3UwlH+grOTDTJYpQX1NuL+VQ8O2FMNnNxnqQR4obgDsILRAGGZCmMx28ZQ01LSHN7tDLlvhu17LkoA+E9w/1YEVC7n1iBX2CyhOxsvq3+uMVqLUg5LIiFzgh3ifmGJuNvlk3Jbj6twNUe4bpUNRTilHRAoqrHI34o8ksLiU/K6 rqtrT/K3 P6KkuOcRMPM8OB2RWCW0cbvAe+jOr6AvMTWR5HFIFnD6JMOclFTiT09ZiC+G3kTev9ctRHpqP95XbQaQxR402MP5MGCJifPlLG3+oxCPBpvzoPFSlhIg+mMYP6llq2p6ZAIuv45xCUYZuNrSr4lKFr57hDGLKV9rnSA6ygQf9l7rNmhp7mv26tgWhBgwvBQjwZTfuEBJxwjM/O5Z9JKUMI/QwUSfzwjuOJuN+qqBk5vt3oWndqoUoWGOgc6eYZiHrQolAkfKpSYbnmLyBEwJAh7aFXJt/LBARb8zv690cT2ywi0ILLC/TNEnbrrulF9VtHU73XzJ58wijFrS/UxToJWEelqydDMdcDtV3mum8kffBWDIdqR4dPP72ke/xRU1HP+7s/cK8mvIkMCR4W5JTMbCTZZFTqi5IuJBjOPKbzprUTBVKpm1MWcmXgA0hBpEx77sF95omCHV2SeGALYzHQgMTgAXjRJcZ+v0uw/NfUJQrZR0Fh6vJ1wKL1oEWl1vnv78PweLZqWZ43XnoWoeiY3i8tyJiE+rHyT/8I829yWIdAyosD83jKYxzvZ8ck+yGEzJpS5bIX7ag14tEOPbYJL3j91UnSppSJVamNfqDpdb8AGnja3ZYDtOG9mbsfO2Xzb5w6iLtSHnZWL3pqKgACaOyLiNQAp1fkSs0o1pYaGVlv6QoEPZ+Yt/EJbsiYS1mol/CCe9pFlOuY0Kohn34w4kzTJb2BUnzXoEpWqC/OVXRWLkRsz1b8KgaLJtKQftCZK+0jhPZ8lQy6CTfzzJzyEPPhatEFVYahGYXM2bZSUqwVj4hvek5yVyBPUJL6PSy7GCO Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] mm/swap: repeated cluster spinlocks and XArray lookups per swap-in fault - [Medium] mm: zswap swap-in faults run unnecessary mTHP PTE and cluster scans - [Medium] mm/swap: swapoff disables readahead, plugging, and large shmem swap-in -- commit 3f2d2334395a7ef2f69d9d945528dc972a0fe190 Author: Nhat Pham mm/swap: drop direct physical swapcache handling This commit removes the direct physical swapcache paths across swap-in, writeout, swapoff, zswap, and memcg accounting so ordinary swapcache folios and swap PTEs always go through virtual swap slots. Physical slots are now used only for reverse mappings and hibernation reservations. [ ... ] > diff --git a/mm/memory.c b/mm/memory.c > index ae9d5e69622f9..ef443d569419b 100644 > --- a/mm/memory.c > +++ b/mm/memory.c [ ... ] > @@ -4919,25 +4917,6 @@ static unsigned long thp_swapin_suitable_orders(st= ruct swap_info_struct *si, > =20 > entry =3D softleaf_from_pte(vmf->orig_pte); > =20 > - /* > - * A large swapped out folio could be partially or fully in zswap. We > - * lack handling for such cases, so fallback to swapping in order-0 > - * folio. > - * > - * Vswap entries are checked later, under the cluster lock in > - * __swap_cache_add_check(). > - */ > - if (!is_vswap_entry(entry) && !zswap_never_enabled()) > - return 0; > - > - /* > - * Neighbouring slots of a swap file can lie in two extents, and a folio > - * is read with one bio. The flag is set in swapon() and stays, so the > - * race is benign. > - */ > - if (!is_vswap_entry(entry) && !data_race(si->flags & SWP_BLKDEV)) > - return 0; > - > /* > * Get a list of all the (large) orders below PMD_ORDER that are enabled > * and suitable for swapping THP. [ ... ] > @@ -5114,10 +5092,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > if (!folio) { > /* Swapin bypasses readahead for SWP_SYNCHRONOUS_IO devices and zswap = */ > if (swap_entry_synchronous(si, entry) || > - (is_vswap_entry(entry) && > - swap_entry_backend_has_flag(si, entry, SWP_SYNCHRONOUS_IO))) > + swap_entry_backend_has_flag(entry, SWP_SYNCHRONOUS_IO)) > folio =3D swapin_sync(entry, GFP_HIGHUSER_MOVABLE, > - thp_swapin_suitable_orders(si, vmf) | BIT(0), > + thp_swapin_suitable_orders(vmf) | BIT(0), > vmf, NULL, 0); > else > folio =3D swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf); [Severity: Medium] Does do_swap_page() now run mTHP PTE and cluster scans on every zswap swap-= in fault when mTHP orders are enabled? With the !zswap_never_enabled() check removed from thp_swapin_suitable_orders(), a fault where swap_entry_synchronous() matched via zswap still takes the page table lock to scan neighboring PTEs and pass= es a multi-order mask to swapin_sync(). __swap_cache_alloc_folio() then itera= tes through each non-zero order, taking swap_cluster_lock() and scanning all 1 << order vtable slots in __vswap_check_backing() only to get -EBUSY for VSWAP_ZSWAP and increment MTHP_STAT_SWPIN_FALLBACK before falling back to order 0. Passing BIT(0) directly when zswap matched in do_swap_page() would avoid the extra lock contention and false fallback counts. [ ... ] > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 72652a2099e9d..8f38737d8aa60 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -3484,15 +3391,10 @@ static int unuse_pte_range(struct vm_area_struct = *vma, pmd_t *pmd, > .pmd =3D pmd, > }; > =20 > - if (is_vswap_entry(entry)) { > - folio =3D swapin_sync(entry, GFP_HIGHUSER_MOVABLE, > - BIT(0), &vmf, NULL, 0); > - if (IS_ERR(folio)) > - folio =3D NULL; > - } else { > - folio =3D swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, > - &vmf); > - } > + folio =3D swapin_sync(entry, GFP_HIGHUSER_MOVABLE, BIT(0), > + &vmf, NULL, 0); > + if (IS_ERR(folio)) > + folio =3D NULL; > } [Severity: Medium] Does switching swapoff unconditionally to swapin_sync() serialize all swapo= ff I/O to unplugged, queue-depth-1 4 KiB reads? Previously unuse_pte_range() called swapin_readahead() with block plugging and readahead, while swapin_sync() submits a single order-0 BIO immediately and the caller waits on folio_lock() before moving to the next PTE. shmem_swapin_folio() has the same regression when swapoff_type >=3D 0, bypassing shmem_swapin_cluster() and forcing order 0 so large shmem swap entries are also split via shmem_split_large_entry(). On asynchronous swap devices (HDDs, SSDs, NVMe), this can severely degrade swapoff throughput and latency. [ ... ] > diff --git a/mm/vswap.h b/mm/vswap.h > index c02aa8f6da579..f3a55414c6b71 100644 > --- a/mm/vswap.h > +++ b/mm/vswap.h > @@ -341,8 +341,7 @@ static inline int vswap_check_backing(swp_entry_t ent= ry, int nr, > * range of physical swap slots. > * @folio: a swap-cache resident folio > * > - * Return: %true if @folio->swap is not a vswap entry, or if these vswap > - * entries are backed by a contiguous range of physical slots. > + * Return: %true if the folio has a contiguous range of physical slots. > */ > static inline bool folio_phys_swap_backed(struct folio *folio) > { > @@ -350,9 +349,8 @@ static inline bool folio_phys_swap_backed(struct foli= o *folio) > int nr =3D folio_nr_pages(folio); > enum vswap_backing_type type; > =20 > - return !is_vswap_entry(entry) || > - (vswap_check_backing(entry, nr, &type) =3D=3D nr && > - type =3D=3D VSWAP_SWAPFILE); > + return vswap_check_backing(entry, nr, &type) =3D=3D nr && > + type =3D=3D VSWAP_SWAPFILE; > } > =20 > static inline int vswap_cluster_alloc_vtable(struct swap_cluster_info_dy= namic *ci_dyn, > @@ -403,22 +401,18 @@ static inline bool folio_phys_swap_backed(struct fo= lio *folio) > =20 > /* > * Test a per-backend swap flag (SWP_SYNCHRONOUS_IO, SWP_STABLE_WRITES, = ...) > - * for @entry. For a vswap entry the property belongs to the current > + * for the virtual @entry. The property belongs to the current > * physical backing rather than vswap_si itself; resolve to the backing > * and test there. Returns false for zswap/zero/unbacked vswap entries > * as they don't have a backing bdev. > */ > -static inline bool swap_entry_backend_has_flag(struct swap_info_struct *= si, > - swp_entry_t entry, > +static inline bool swap_entry_backend_has_flag(swp_entry_t entry, > unsigned long flag) > { > struct swap_info_struct *phys_si; > swp_entry_t phys; > bool has_flag; > =20 > - if (!swap_is_vswap(si)) > - return data_race(si->flags & flag); > - > phys =3D vswap_to_phys(entry); > if (!phys.val) > return false; [Severity: High] Can dropping the lockless fast paths here add several virtual cluster spinlock roundtrips to every swap-in fault? With all ordinary swap entries now virtual, a single swap-in miss in do_swap_page() calls vswap_lock_cluster() (an XArray lookup plus ci->lock acquire/release) repeatedly on the same slot: - swap_entry_synchronous() -> zswap_is_present(), which checks is_vswap_entry() before zswap_never_enabled() and takes ci->lock even when zswap was never enabled; - swap_entry_backend_has_flag(entry, SWP_SYNCHRONOUS_IO) on the next line, plus get_swap_device()/put_swap_device() on the backing device; - swap_read_folio() via vswap_to_phys(), even for zero-mapped or zswap folios; - should_try_to_free_swap(), which runs on both hits and misses and locks t= he cluster twice back-to-back in folio_phys_swap_backed() and swap_entry_backend_has_flag(folio->swap, SWP_SYNCHRONOUS_IO) while holding the folio lock. On fast NVMe or zram swap devices, this serializes concurrent faults within the same swap cluster. Coalescing the backing lookup in do_swap_page() and should_try_to_free_swap(), and checking zswap_never_enabled() first in zswap_is_present(), would eliminate most of these redundant lock roundtrips. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203220010.1302= 207-1-nphamcs@gmail.com?part=3D17