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 B8E5A606A32C for ; Fri, 4 Dec 2026 22:09:43 +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=eqlczaff Received: by kanga.kvack.org (Postfix) id AA9036B05BE; Fri, 4 Dec 2026 17:09:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A59976B05BF; Fri, 4 Dec 2026 17:09:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9222C6B05C0; Fri, 4 Dec 2026 17:09:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6C7F06B05BE for ; Fri, 4 Dec 2026 17:09:25 -0500 (EST) Received: from smtpin14.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 05780A8122 for ; Fri, 4 Dec 2026 22:09:25 +0000 (UTC) X-FDA: 85507692690.14.4542B8E Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf30.hostedemail.com (Postfix) with ESMTP id 5027C80010 for ; Fri, 4 Dec 2026 22:09:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=eqlczaff; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796422163; b=QviRVj2X6VBfoDwtW3SSddQREaHIObK/TM+Ip7xMS4VZz2X53iXeiBXy2EZEBFGOD+9hN2 ENdwwBEUNt0pElLu7RvUrEQJIxt1p/mdk23/Ys0cX0a49cPqYg47PQ13aqFD7CSXDjNMqI l/SUc8bVYurE9p5HDenMm0jdZ3bZ+nQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796422163; 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=YDgL6kPYJp6TbUCP0jr0Hgc7YyaGs7Kd4DK6NpQcgic=; b=eYrgMlB7rvxu4bieW+rnOQ56e23nSmaizgH/uxMPZg3A0UNa0NmjBBynxhb2khH613gMWW 85r2+O+z2+ZqrmLrDNGIYbNHQ0i2kmVvvd5gd7BooeqrVM9J6/bBk9ZGvEY/Wx35ebxWtr WCiCtqRgW5lDGEZnLUqLtA991Dnhilw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=eqlczaff; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf30.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id E6AFA61FD2; Fri, 4 Dec 2026 22:09:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A8D71F00A10; Fri, 4 Dec 2026 22:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422162; bh=YDgL6kPYJp6TbUCP0jr0Hgc7YyaGs7Kd4DK6NpQcgic=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eqlczaff7kn4AHIcrui/OihIaymV0Su17ih8Jnx4h6zDfEDo71KhbdLot+XudKOCD VZH1QlpAfa6pqk5uxayuha/7oFaUM1iOSTM8H5t/DEn4qB/GsD1rLuXAJDkTkUTR6u PL+KVeaNDX+wJI24dmGMrxWYIbNR80aWZFA+BZLowr1Yc7r/ZAs439EBtvxovdMuK8 W4g2P5/T8Uc4FPfxtQ/YYF0zAWcnp0lqDt3NCgejDpdiUnlHtyj7RNdDVkqGBIg4VT h1zfS96nvbJ/mpgEtWq0E95JDlq8jlCGnSxhYHjXPI9oQu6OUB4q4XRS0NDCchAndO WDhEMdXhcny6Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 08/20] mm/swap: support physical swap as a vswap backend 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-9-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> <20261203220010.1302207-9-nphamcs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:09:21 +0000 X-Stat-Signature: omjq4fgx9c5eaugkh6y83sj9jmr7apmp 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-Rspam-User: X-Rspamd-Queue-Id: 5027C80010 X-Rspamd-Server: rspam07 X-HE-Tag: 1796422163-582916 X-HE-Meta: U2FsdGVkX1/4QQKxVcgIn1lnpnuB+mpIy6GD/O2bsoS9FLf9X9hjcNj0NZmN4FOoJWni9JiZ7MaB+PnQ9M+nWm6U8oPqVHrv32Yrgc3BcBf9GTKm3+0D/bZJa1t5Gl7bx7yGwaWA+NLAuKElWbeiwiIubrst2uORNxhBWcIRnxP27YvbMtYsQDJQ6tPe06KPwYVyw51yKuFczs+POVsZI+p3bRXbHAF/Gn7ztkOKBywmwSRIPZBvh5N7ol+jGUSP2a9lPplRgJEse0b5bAwc+STJN3Q/zeL8wpnDxbEqX2oZae4f8fC7NYTsLh8zegSiO/U7Ox9CeA86YdTlRVlHk230OBFxq74AE8OcpMh/j6GD0G3UrWnRBV1RwlsAlrUQv7duENFvIzbWDDkToJjUGdPBrSCpkgOfVaIrAFAEKPhAtHYCm5KpduEVJM1aM4vSW1qQDch6k1Ciuqd3/xFPyS/Gh2tnfFRK8JHI0oPLdWNMtooqL5JvmgTCTnjdeYAcgH+cQ+iSbdCjrOP+PGARLOPunbamT8b9bcutK/G2VGRY7gX/u4yYio3Jy2EvBGbT/geP5FGDVLb/Gf4JUoyrMraUTBr238Nf94UW14yLZpJLr+Epo4qC6vD6EwhEmY4WoyyP+/U1aad52fee9XAKwI+7Sq0sxpKGTPNgr6K81jJLxaBZQGRl/0f6TEMDtsljRClzwYxzjAjrLXKjVItpDgXgwHewhOyhJvbOdB42qNlbEJBweRne/pir7CyBfEIUVtA4abOtBnlMAT3LtQZMufNeM/4sCofVd9OMHC8asNn2uPaKcgKX/qBXy3uafb1hrQKlZ4Z0Bzu1EZsT/C1wmLzfaee2YRp8xQFVHl3RPrdQtNNXp+3d4hKq6ikoqGnH+NRXtF1cPQltrqZfBW8u19J12NmRZBsbNdpWmQb5KCUxofEZo2F9YDpVk+EGFqjaZ98v6KMsWsjaqXaATyw D8fIBKvd d8hLH5hZ7hSE5O5oRL3uFuJeNJz1/qP10L+34QVEJflt5NuEZCu7nzLM05ix32L9AtUgsX7jlrph92ThMJNPPAZJu+yrGg2pq/KXcUwvSXMa8h7pMyrqpAy/HTcXC00oUkeMp3hVYABk1Oekcl9IOGC1aHpFWIGc/wjJBRWowKKXRAiDDgQH6wy47YRIVgk9uBATXEB7czUAeJmGnsAIsIA5a1AuwgPumnivBxVD9kPhnG0TyPghfiaVMbHM2yjP2C4arMQoJy6DaANdCO9CRtEOGj/dbgQm8Ty2ajzHjDVG69EqbvVT22pN04xy5XSqUfnmG3OlT98yEpb1jCXHByEfhzWpNVpH1+fbH63Kuo02enwXinVpedqNfM/88KkK0udaV+5NQylrufEHwoGanXyQ1V1+O3dTE7yU4cYbrPNuxbl/CD02GRFnTbXnE+lzA9sW0VBzVWVwJLcgz5rusgvUL6s6E+Z64aioNXRQkCqnofyXZfQBgFDzHm+jb6VRQzEwXQATQ0yuYwr74Ry55r2OV1cFwURURSwx8a+CK3BTOeEn4NgVDS3g3gM2QEcNB4ktytjTjdCpKm4j8lB90ptAplnvTeP9KGiM1/MIVw74gTS7/rYLEsBcOCQffH7uJtgajrrExDoNGMRxJ46MmDxCm7xUOYDs9XBkgTemJNBjnCidlAVnHk9BmKM5ciqH+iSustkL0KbUQdZchpF7nh9lH9a13cDokNOxg2eJIAjy5bMY8qszidYrFog3TtktFJD1WxNg4Gs2Cz4bqGhKOeqb8UE0e9yptk16t78tigc7x+LT8Vi3Ia27FdTrAB4zo1/goSWlR9BVjEWcD9qBOICRn8w== 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: - [High] mm: large vswap folios declined by zswap cannot split on phys fallback - [Medium] mm: vswap reclaim predicates ignore global zswap pool fullness - [Medium] mm: duplicate forced rstat flush per swapped folio in folio_may_vswap() - [Medium] mm/swap: vswap_init() bypasses swapon/swapoff with empty vswap_ops - [Low] mm/swap: unbatched per-page physical backing free in zswap_store() -- commit d69d6282bb4267cdc2da182e4603e10f267cd488 Author: Nhat Pham mm/swap: support physical swap as a vswap backend This commit adds physical swapfile backing for virtual swap entries when zswap declines a folio, records physical-to-virtual reverse maps, and registers the virtual swap device at boot behind the vswap=3D parameter and CONFIG_VSWAP_DEFAULT_ON. Link: https://lore.kernel.org/all/sashiko-outbox-181078@kernel.org/ Link: https://lore.kernel.org/all/sashiko-outbox-181079@kernel.org/ [ ... ] > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index df02308bb80ab..a3d065c594bc9 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c [ ... ] > @@ -6324,36 +6342,38 @@ static struct cftype swap_files[] =3D { > * spending cycles on compression when there is already no room left > * or zswap is disabled altogether somewhere in the hierarchy. > */ > -bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) > +bool mem_cgroup_may_zswap(struct mem_cgroup *memcg, bool may_flush) > { [ ... ] > /* Force flush to get accurate stats for charging */ > - __mem_cgroup_flush_stats(memcg, true); > + if (may_flush) > + __mem_cgroup_flush_stats(memcg, true); > pages =3D memcg_page_state(memcg, MEMCG_ZSWAP_B) / PAGE_SIZE; > - if (pages < max) > - continue; > - ret =3D false; > - break; > + if (pages >=3D max) > + return false; > } > - mem_cgroup_put(original_memcg); > + return true; > +} > + > +bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) > +{ > + struct mem_cgroup *memcg; > + bool ret; > + > + memcg =3D get_mem_cgroup_from_objcg(objcg); > + ret =3D mem_cgroup_may_zswap(memcg, true); > + mem_cgroup_put(memcg); > return ret; > } [Severity: Medium] With vswap enabled by this patch, does folio_may_vswap() calling obj_cgroup_may_zswap() double the forced rstat flushes on every swapped folio? For cgroups with a finite non-zero memory.zswap.max, folio_alloc_swap() now invokes obj_cgroup_may_zswap() -> mem_cgroup_may_zswap(memcg, true), which unconditionally runs css_rstat_flush() across all possible CPUs under the global rstat lock, and zswap_store() then repeats the same forced flush on the same folio during swap_writeout(). Folios that never reach zswap_store() (such as zero-filled or unmap-failed folios) also pay this cost. Since zswap_store() already performs the authoritative flushing check and mem_cgroup_may_zswap(memcg, false) still catches memory.zswap.max =3D=3D 0, could folio_may_vswap() use mem_cgroup_may_zswap(memcg, false) instead? > diff --git a/mm/page_io.c b/mm/page_io.c > index 956c3ffc10397..854b0b71581d6 100644 > --- a/mm/page_io.c > +++ b/mm/page_io.c [ ... ] > @@ -252,8 +253,14 @@ int swap_writeout(struct swap_io_ctx *ctx, struct fo= lio *folio) > */ > swap_zeromap_folio_clear(folio); > =20 > + /* > + * For vswap: release stale non-swapfile backings (e.g. ZSWAP from a > + * previous swapout cycle) so zswap_store or folio_realloc_swap > + * starts on clean slots. Contiguous PHYS backing is preserved for > + * reuse by folio_realloc_swap. > + */ > if (is_vswap_entry(folio->swap)) > - folio_release_vswap_backing(folio); > + folio_release_non_phys_swap_backing(folio); > =20 > if (zswap_store(folio)) { [Severity: Low] When a physically backed large folio is redirtied in the swap cache and then accepted by zswap_store(), does preserving the physical backing here cause it to be freed one page at a time? zswap_store_page() calls vswap_zswap_store() per subpage, which invokes __vswap_release_backing(&ci_dyn->ci, voff, 1) and bypasses the contiguous batching in __vswap_release_backing(). For a 2MB THP, that repeats pci->lock, smp_wmb(), and global nr_swap_pages atomics up to 512 times, and exposes the half-freed physical cluster on nonfull_clusters while the remaining subpages are still compressing. Batch-releasing the physical backing once in zswap_store() after admission checks pass would keep physical slots intact on rejection while avoiding per-page teardown on acceptance. [ ... ] > - /* A vswap folio has no physical slot to write to. */ > if (is_vswap_entry(folio->swap)) { > + phys =3D folio_realloc_swap(folio); > + if (!phys.val) { > + folio_mark_dirty(folio); > + return AOP_WRITEPAGE_ACTIVATE; > + } > + } [Severity: High] Can a large vswap folio become permanently unreclaimable if zswap_store() rejects it and folio_realloc_swap() cannot allocate a contiguous physical entry? Because cluster_alloc_swap_entry() exempts vswap_si from the SWP_BLKDEV check, folio_alloc_swap() succeeds for large folios instead of returning -E2BIG and triggering a split. If zswap_store() later declines the folio (for example, when the global zswap pool is full or GFP_NOWAIT compression allocation fails), folio_realloc_swap() calls folio_alloc_phys_swap() on the unsplit folio, which unconditionally fails on regular swapfiles and fails on fragmented block swap devices. Returning AOP_WRITEPAGE_ACTIVATE leaves an anonymous large folio in the swap cache with vswap PTEs installed, so subsequent shrink_folio_list() passes skip the !folio_test_swapcache(folio) block and can never reach split_folio_to_list(). Large shmem folios hit a similar loop because shmem_writeout() jumps to redirty rather than try_split on AOP_WRITEPAGE_ACTIVATE, leading to reclaim thrashing and premature OOM even when plenty of order-0 physical swap is free. [ ... ] > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 6933e069bd2ea..3dca9bd557361 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -1911,6 +1935,12 @@ static int swap_dup_entries_cluster(struct swap_in= fo_struct *si, > return err; > } > =20 > +bool mem_cgroup_can_vswap(struct mem_cgroup *memcg) > +{ > + return vswap_is_enabled() && zswap_is_enabled() && > + (!memcg || mem_cgroup_may_zswap(memcg, false)); > +} > + > static bool folio_may_vswap(struct folio *folio) > { > struct obj_cgroup *objcg; [Severity: Medium] Should mem_cgroup_can_vswap() and the other vswap reclaim predicates (folio_may_vswap(), can_reclaim_anon_pages(), can_age_anon_pages(), and shmem_writeout()) also check global zswap pool capacity? Right now, zswap_pool_reached_full is only checked inside zswap_store(). When zswap is used without a physical swap device and the pool reaches zswap_max_pool_percent, reclaim keeps isolating anonymous and shmem folios, allocating vswap entries, unmapping PTEs with TLB shootdowns, and failing at swap_writeout() with AOP_WRITEPAGE_ACTIVATE. Checking global zswap headroom before reclaim and swap allocation would avoid this thrashing loop. [ ... ] > @@ -4515,3 +4710,76 @@ subsys_initcall(swapfile_init); > =20 > struct swap_info_struct *vswap_si; > DEFINE_STATIC_KEY_FALSE(vswap_key); > + > +static bool vswap_enabled_early __initdata =3D IS_ENABLED(CONFIG_VSWAP_D= EFAULT_ON); > + > +static int __init early_vswap(char *buf) > +{ > + return kstrtobool(buf, &vswap_enabled_early); > +} > +early_param("vswap", early_vswap); > + > +/* vswap does no IO on its own. */ > +static const struct swap_ops vswap_ops =3D { }; > + > +static int __init vswap_init(void) [Severity: Medium] As reported by Chris Li on v5 [1], vswap_ops is left empty while core swap paths accumulate scattered swap_is_vswap() special cases (including bypassing si->users refcounting in get_swap_device_info() and put_swap_device()), and vswap_init() auto-registers a swap device outside the swapon/swapoff lifecycle. Later commit "mm/swap: make vswap mandatory" removes the vswap=3D boot parameter and CONFIG_VSWAP_DEFAULT_ON, making this auto-registration unconditional on CONFIG_SWAP kernels while leaving vswap_ops empty. Can vswap-specific behavior be encapsulated behind swap_ops to avoid fragmenting the core swap and locking paths? [1] https://lore.kernel.org/r/CACePvbVaDNspMDSw_qAcapKAzXj3JGV-KMYmow7aePa0= POHpSg@mail.gmail.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203220010.1302= 207-1-nphamcs@gmail.com?part=3D8