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 51693606A322 for ; Fri, 4 Dec 2026 22:09:24 +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=REynhPRt Received: by kanga.kvack.org (Postfix) id DB6AB6B05B8; Fri, 4 Dec 2026 17:09:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8ECA6B05B9; Fri, 4 Dec 2026 17:09:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7D896B05BA; Fri, 4 Dec 2026 17:09:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 58E5E6B05B8 for ; Fri, 4 Dec 2026 17:09:17 -0500 (EST) Received: from smtpin23.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E48D31C3C09 for ; Fri, 4 Dec 2026 22:09:16 +0000 (UTC) X-FDA: 85507692312.23.91A7923 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf20.hostedemail.com (Postfix) with ESMTP id 377BE1C0008 for ; Fri, 4 Dec 2026 22:09:15 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=REynhPRt; spf=pass (imf20.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=1796422155; b=irL7DTysVe79ySxOa1PEaWKBKv1/I2xzxsfLbrOcRmZVEccCCp1zphxWQP1KyqZxaU4mvC yn8PGiYQ57ukhRwuByiPwIcYZpilFOMBvU2f34isdnWhbryDqMczbW6mI94ROcluCgy8Cb dFVedKOLDrrhsrhqw5kbqCxV7GjV24s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796422155; 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=Lbjb4atdbnivHjBxcL08lxUjBl8+3sIOwAXi5VH3GFY=; b=YIrMDFqDVFnG10wcphBM9wYWfDrP7XcYFDovbhlnbWnlmNdm120HM0pGYVHUK0XzBVkWcY 8aY75OTVxf04nb1dc8hhagdsd5VaDjuAY0l8DN0B2KCvtGHqZciy458ZWtbCBW0jxSmPd7 Ry5g765I9ZpsXwasiKtr76FABSkZQpI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=REynhPRt; spf=pass (imf20.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 8468E4197E; Fri, 4 Dec 2026 22:09:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A11F1F00936; Fri, 4 Dec 2026 22:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422154; bh=Lbjb4atdbnivHjBxcL08lxUjBl8+3sIOwAXi5VH3GFY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=REynhPRtv9Z6RJwSvy4Wt9pxY7rm+K6JCDv93STKxI0++EcLWeo+ATrc6yr0i/ep/ NmgX1yxiuHczzpQXKCBnPAzgBrOMHmd5hc+N2kT2O25l+Av4OXb5/btwLlw7JoidGn 6JiKeKMUk4TQxf6nowQ+v8DvTd7nBHmR8eKIENA+x2Q9I7lrkjUtGQQ2l/DnQp9Nyo FWbM3AlFb/8fuzf83V2sNy/2dekbvr3CzdiJuGvzU+GQGlCVYKSbRmPsVG04SlUwN0 794ZwoeGeGP4jVmPFP2lH0pKnZt1jQ4MjvGOU4QPsUHH/aqzCpJxRzYOPGj3lZo3hC PwlpMxF3iOTFA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 03/20] mm/swap: prepare zswap and zero storage for virtual entries 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-4-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> <20261203220010.1302207-4-nphamcs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:09:12 +0000 X-Stat-Signature: sffmmnd3cz9do8qofp1nsy97borhfx7j X-Rspam-User: X-Rspamd-Queue-Id: 377BE1C0008 X-Rspamd-Server: rspam09 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-HE-Tag: 1796422155-937903 X-HE-Meta: U2FsdGVkX18TjgqG804jYU7Z1PBJa9TnHgG+WGiBchKvwqQ+nlp+KNE0Od2R1LnUVzGo5Ze0m0+Ux0zQ7BPUeP4IjCASN+kQmukWl3ON8ma7ZrxUFtDSZYibQysImWJo37DU4nwQpr6LlETgooXbxZy/c+HPFJjqROId+altSYdi8jbJDYb4IEhBviSXkAMXsO8szINRSTJpG3/vtneBhfNCPXUP6oKsS2MesdBeuIcr9fjbDTGx4HR6sukHRO9/0s0ao+1NIjBTWyVR729/DISlu/wFI0EAqcixjMfQ67qwviiG9ScMe53lKbKM/5NzBWL18LwEID4WWYdRtA9cY7485wB2WmRpL42VRh8EzpiHmTy9MzSq/RdPMX77w2CEUkjGxQy3Ims71HLlJd3ppKXOMzZJEt961G1S+A3PDvEzzDtB4ru3o5nF+X6d28HAjDKIeC+2Yl0OLUob8rY6ZgIJYFWMVe3F91mUahXOOInuZk5v2PUMlBXr+61L0C4mjD50YIVQBv6h5MHXWBqVsDb+3rKsW5Qb2SGYISM+wQVR+NwkE8/ndiB2UAK5LMRRKO0KzGNo+DhP/B0hryIS6kFvtKVRWoGsS8G70y3gCrLxqpEQNjlXIcVovcJ103qXsj+UWXieOMXuTrF8sYnnzJ4G30jxyW7UXuBB+bJdvRNHay/5fqO0HeiKJGgpkaoJwAGt4JzplrogNxQRjB6NFKOrh30OhlJxq0LyqD1VlAwtJr1YX71DcZogAV+JBwN3ENoFGb6CuY6u21mfYRAx97si6tt4Kzq7c24/7DFFT+OJzFrgQauzBZu65oFePpOZqrrrc2ZPI4AaKIxedsibXBE3XcI9mdVq1fd4RrvKvmQI286nhvooB7FIcP8LzRR+87oVF7sIrKkdKds2meuGiLW1k5hd6TAa3LHbETtx2T6xDlS4KKtAzDWXyqyMKExLHkgYvx3Yc16MR4OP0AX 2ljKQuKq HoovfB1+fFhXjEXA7wRrocu9Np1mX1+nIQH1Tw2Cn+TWDFIjXogy/t3nsc6pDRUfSoMLkxh+kn0nbR6LUgoYuujsi/AoZQ8MgGI5Zz3uE/CaDfsDR/obWtimJFFeoJZFEs7hK/Zu7ieaEYLi5S+vwLh3n/NAi7dpjiyksyqU+bGZsL+zlEH86QtEi1qgmw5XUXMwG/l2qjCzPj72u8KI0ULojP5+uf1Ptx2YBdP8zazBQwg31XYuYfhuEc6u73bwVK6bviHei4J3LLrU8kqdwxiSBNN3AyDeJTzD2iArT8hll8tmJWo4ccnbKb7FjdcxtD+9R9zJQAyLmcgZ7tkMES0MN2DIC/N80f6v3E+synN4Yd4wXo5uUjyQ1aD5ncM9OWlA39GzMkhqrVvQxq6caoNG2inbObeNua/hQmSqprY9DwETpuQ4qYy/U7Kxgc3zzL1z9SDhWHC6aUhNizmzTo8vZrkjuxWzemAQDWlnUHf2Mhmfr+2Q/dzoLXopTV2jbPVvEszuZ7Lj6cPC14BsxIVivSK4nf1OjWn4VzdGrzeAGgCg9GuiTQx9RGxUXWxeyKqFH0vdo8XBDcv2J9dkjPg4HWFYo3Myhp8RtumD6RkGcCR6Ci/24BZM+OnwTu5xbJELuH/KBn9lit6H87Mh6s43ORuDdS3/LYvOUR9ddfbYN/ZUH/STbaj4uXXc5eHEZYCKIc+iXK3jve09GjTHkPrSCbtpthkK4hJyHIQC8R91KGFSmjLivnlfLS8vh6Z+wVHVqdm3RIwK/G60PVIulBRq2zDGTDWSQrzybkbjgXmp89PTwMhJY0PbyvoBddu0iwPgu 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 5 potential issues to consider: - [Medium] mm/swap: __vswap_release_backing() holds ci->lock across zswap_entry_free() - [Medium] mm: zswap_is_present() bypasses zswap_never_enabled() and locks per slot - [Medium] mm/swap: redundant cluster lookup and lock cycle in swap_writeout() - [Medium] mm: zswap_store() queues shrink work even when shrink_worker() bails out - [Low] mm: zswap_shrinker_scan() omits vswap writeback availability guard -- commit f00d7cee664321ec03d5feb2f3fe7858aa5f1f87 Author: Nhat Pham mm/swap: prepare zswap and zero storage for virtual entries This commit adds a per-cluster vtable to virtual swap clusters to store aligned zswap_entry pointers, retains the swap table's zero flag for zero-filled pages, and updates zswap and swapcache paths to release compressed backing through the vtable. > diff --git a/mm/page_io.c b/mm/page_io.c > index 062bfce6f0de3..9397ef83a60de 100644 > --- a/mm/page_io.c > +++ b/mm/page_io.c [ ... ] > @@ -246,6 +252,9 @@ int swap_writeout(struct swap_io_ctx *ctx, struct fol= io *folio) > */ > swap_zeromap_folio_clear(folio); > =20 > + if (is_vswap_entry(folio->swap)) > + folio_release_vswap_backing(folio); > + > if (zswap_store(folio)) { [Severity: Medium] Does this do a redundant cluster XArray lookup and ci->lock cycle on every non-zero vswap writeout? swap_zeromap_folio_clear() already looks up the cluster in si->cluster_info_pool, acquires ci->lock, clears the zero flags, and unlock= s. folio_release_vswap_backing() immediately looks up the same cluster again, reacquires ci->lock, and calls __vswap_release_backing(), which re-tests and clears those same zero flags. Combining them under one cluster lock, as swap_zeromap_folio_set() does, avoids the duplicate lookup and lock cycle. Similarly, during multi-page zswap_store(), vswap_zswap_store() repeats vswap_lock_cluster() and __vswap_release_backing() for each page even though all pages of the locked folio belong to one pinned cluster. [ ... ] > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 153e73b96a7ab..1387c8bb1e976 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -1941,6 +1950,73 @@ int folio_alloc_swap(struct folio *folio) [ ... ] > +void __vswap_release_backing(struct swap_cluster_info *ci, > + unsigned int ci_start, unsigned int nr) > +{ > + struct swap_cluster_info_dynamic *ci_dyn; > + unsigned int ci_off; > + unsigned long vt; > + > + lockdep_assert_held(&ci->lock); > + ci_dyn =3D container_of(ci, struct swap_cluster_info_dynamic, ci); > + > + for (ci_off =3D ci_start; ci_off < ci_start + nr; ci_off++) { > + vt =3D __vtable_get(ci_dyn, ci_off); > + > + switch (vtable_type(vt)) { > + case VSWAP_ZSWAP: > + zswap_entry_free(vtable_to_zswap(vt)); > + break; [Severity: Medium] Can calling zswap_entry_free() while holding ci->lock cause lock contention across the cluster? zswap_entry_free() acquires the zswap list_lru lock and zsmalloc's size_cla= ss lock (and may free zspages back to the page allocator), updates percpu_ref and memcg counters, and frees the entry to slab. On every vswap zswap swap-in via zswap_load() -> folio_release_vswap_backing(), this holds ci->lock across that teardown for all 512 slots in the cluster, whereas the physical swap path detaches the entry and frees it unlocked. Because callers such as zswap_load() and vswap_zswap_store() already hold the swapcache folio lock, they could detach the old zswap_entry under ci->lock and call zswap_entry_free() after unlocking. [ ... ] > diff --git a/mm/zswap.c b/mm/zswap.c > index 4732d2938f4ad..aab8ec782d033 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c [ ... ] > @@ -1322,6 +1342,9 @@ static unsigned long zswap_shrinker_count(struct sh= rinker *shrinker, > if (!zswap_shrinker_enabled || !mem_cgroup_zswap_writeback_enabled(memc= g)) > return 0; > =20 > + if (vswap_is_enabled()) > + return 0; > + [Severity: Low] Should zswap_shrinker_scan() also carry this vswap_is_enabled() guard? zswap_shrinker_scan() mirrors the !zswap_shrinker_enabled and !mem_cgroup_zswap_writeback_enabled() checks, but omits vswap_is_enabled(). shrinker_debugfs_scan_write() invokes scan_objects() directly without calli= ng count_objects() first, and do_shrink_slab() can invoke another scan batch after swap space is exhausted, which walks zswap_list_lru, clears entry->referenced on warm entries, rotates the LRU, and increments zswap_reject_reclaim_fail on futile writeback attempts. [ ... ] > @@ -1446,6 +1474,13 @@ static void shrink_worker(struct work_struct *w) > int ret, failures =3D 0, attempts =3D 0; > unsigned long thr; > =20 > + /* > + * When vswap is enabled, zswap entries are almost all vswap backed, > + * with no slot to write back to. > + */ > + if (vswap_is_enabled()) > + return; > + [ ... ] > @@ -1676,14 +1709,21 @@ bool zswap_store(struct folio *folio) > if (!ret && zswap_pool_reached_full) > queue_work(shrink_wq, &zswap_shrink_work); > check_old: [Severity: Medium] Will zswap_store() keep waking shrink_worker() needlessly when vswap_is_enabled() is true? Because shrink_worker() returns immediately without shrinking the pool or clearing zswap_pool_reached_full, the work item clears its pending state right away and every subsequent rejected zswap_store() under memory pressure wakes the zswap-shrink kworker again. Guarding queue_work() here with the same writeback-availability check avoids these spurious wakeups. [ ... ] > @@ -1700,8 +1740,18 @@ bool zswap_store(struct folio *folio) > bool zswap_is_present(swp_entry_t entry, unsigned int nr) > { > pgoff_t offset =3D swp_offset(entry); > - struct xarray *tree =3D swap_zswap_tree(entry); > + struct xarray *tree; > unsigned long index =3D offset; > + unsigned int i; > + > + /* Virtual entries have no native zswap tree. */ > + if (is_vswap_entry(entry)) { > + for (i =3D 0; i < nr; i++) > + if (vswap_zswap_load(swp_entry(swp_type(entry), offset + i))) > + return true; > + return false; > + } > + tree =3D swap_zswap_tree(entry); > =20 > if (zswap_never_enabled() || xa_empty(tree)) > return false; [Severity: Medium] Should the zswap_never_enabled() check stay ahead of is_vswap_entry(entry)? do_swap_page() calls swap_entry_synchronous() -> zswap_is_present(entry, 1) on every swap-cache-miss page fault. Placing is_vswap_entry() before zswap_never_enabled() makes virtual swap faults bypass the static-branch fa= st path even when zswap was never enabled, performing an RCU read, a si->cluster_info_pool XArray lookup, and a ci->lock acquire/release on every fault. When nr > 1, the loop also repeats the cluster lookup and ci->lock cycle for each slot instead of locking the cluster once for the range. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203220010.1302= 207-1-nphamcs@gmail.com?part=3D3