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 3E717606A322 for ; Fri, 4 Dec 2026 22:10:31 +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=BU+kJn+7 Received: by kanga.kvack.org (Postfix) id 15B7D6B05C8; Fri, 4 Dec 2026 17:09:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10BBF6B05C9; Fri, 4 Dec 2026 17:09:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 021526B05CA; Fri, 4 Dec 2026 17:09:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CF10D6B05C8 for ; Fri, 4 Dec 2026 17:09:41 -0500 (EST) Received: from smtpin15.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F164DA05B4 for ; Fri, 4 Dec 2026 22:09:37 +0000 (UTC) X-FDA: 85507693194.15.1BFF136 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf16.hostedemail.com (Postfix) with ESMTP id 4EC4F180003 for ; Fri, 4 Dec 2026 22:09:36 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=BU+kJn+7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 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=1796422176; b=TKVnyJpyeIDL+ay0oxyx1Rhlr9MQqM60hR0CvTeQHqrUGKiru9Gp9SFtauw3uKxD+8DIDu vVsHJMnP7L5m8ag5lPVDykFwR4EKTrRBt9lrg+dNS2zT7AxHQsVl3nCtGH+Odxqn8czNn5 tfcCs7JrsR5fbZYe7M7nNwlyMwdbIlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796422176; 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=FmwKAQPAflqGjnMk6hMwkHlP6R6YrzR2DhVSJX2OsSc=; b=jpPckMUgfNkCD7OKnw4iGCl9wQBzLOqDh3F+tdMCY68pNrIdHjNMj7FC0aDSTXJ23wqy1v rwc26lRYzayZbXI2Px9K6wGlRhCldudxd/G6v+ffsZcU8GzPjETR8k3X+kO9Nkbof9KUvk fAHHuLrM8mCBDkUrZkJ8fVPBulSLw5Y= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=BU+kJn+7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 9D20F40722; Fri, 4 Dec 2026 22:09:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DC8F1F00936; Fri, 4 Dec 2026 22:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422175; bh=FmwKAQPAflqGjnMk6hMwkHlP6R6YrzR2DhVSJX2OsSc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=BU+kJn+74+nEp46aGKKUkgPVhSge1l5MtQwjqwbXy3yisNvT2zNNmOHpc0yX59Flr klPyFgLZc44lBgN6JEVWRn/PI8KDmu4wgJLH2OZFe9MiEQfKB/50Rgq5RJN0uOGck1 CfTiFkn4L5tEz6IiqSoJmvS3q4+I6GEtXfvjUSpNo/xRZB3a1uF4oUZCQUlrIJ95g0 L2AJoMp6itMfs74te5L6rMDHa0qc0dLf3ERJNHGJkzrqTwZZl2wZeuLKzYx0KBXi61 ELuu2gozl+QH8FpZrng9ySRMmUpBLGMz7RjvyKrEqiWPigTP9GNj7sicc2iU5XGFU9 2IbkFqGFnExtg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 16/20] mm/swap: make vswap mandatory 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-17-nphamcs@gmail.com> References: <20261203220010.1302207-1-nphamcs@gmail.com> <20261203220010.1302207-17-nphamcs@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 22:09:33 +0000 X-Rspamd-Server: rspam02 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-Stat-Signature: 78soqjodi37ox3jqqer7qyd6nh5yzo41 X-Rspamd-Queue-Id: 4EC4F180003 X-HE-Tag: 1796422176-466345 X-HE-Meta: U2FsdGVkX1/ODjEmritL8Fqem2cP7E2gl4lXa8uhmT5PU2dc7TMH0EWujO4E0UUmOq2+TfXTwimLCvDI8Mgg04Vz0i+EXSzscNJ4u31qyKD2+b9L60J4DhZw9vLojA7UNie6t15aLojm+v1haBesGcZyGq/YhTTS+KAME5oKfBtnQWKM+9Dws0CHM2fMZNaKyMu3Wr9lUcO5yKAo0Ci9D2zXk3MX0WnyVoyBxWM3S0DOA1wmDeL4/fyvwz/MaCM5WBwkbB0FlF/Q5DemhlvrZGWMCfFcgzPnMHKOBz3NU4eFANnOGPUklFGu4cT6TxTWxEKB+2X++QpF1sUml3YPMjrN9l4H6UQREt4+e0eaLces+eaXUTw/9ZKWWOt0ycLWk6zUlBngLcYdQJAhAYh7qhJNx/zqFZ2kUtMreiRSgcBm7GqEqCXx+EBOkQB+RBopHqzux3AdBlXFnyXbZglKiL3vBcbI4VdSi6EQgb+vGnVdBziiINmwg+f9MweUdvuds+caQnDuvyfOBr4tmu2ovm3BGV9obbLWJd4hril7AdLic+NKRw69g5pQg7eFkWAPYWcEVzbV0ZDZK2D3nG53NedmgTRPY7PlnK2aYEUOK9tCXQXqExZPBSAFYxdGCjYBUcin3ofdHYRncQnkoA0+fOpmqptvhKHZ+o7uZuAXMbwaUeV6qymPb1EskdzcoV4+gVH8rwSchWZCu3mTxz410T9Ouy0xCoGnJ1RJiw9S9wdaU0xBf3oxR5JZSGzNpJ7SR2rb9HlC0h76yWK9OwOyGnMMiWPl4V8Trlu9wi2HeRfbnOqcJVj4/Hymo8NM104WuNBL4T7fjJ8o78cX/M9DD/cLfMls4qkfRZLegxZYPC0rtcxZ2wYHSAnpertQtZTcF9vjzUKLi8YD3zegL9GdKG9Yhi3AsbNy3aD08zhLMjHXWlu0G4/IDXm7RzQDNTDmcqz1tyeSb1EYdDFiLta VNYN3Rd5 DkmC7F7Yk+z4J+j258HyIh7Kyl6+1vN9EfUqFphPLx6R8sMc+lSjE2debiLbCB/06HW0wlJWkhB1Lt7VbTD8KAP3OC3jcz/KBXowSfoOzE4rI9RJCStvGZ9YzpqO+n6g56G6lp+u7Ra1V77Cp9ZMxT/we7zurR3cbrVrx+UxTKyHC+Iqa8I+rH2eD64fZvCNsX+8Res7jUV/ZhvV5kzvUFsZ9OkCG/L3sEtvrHdC3zFy+1fR1bEVVws0kihnysimFVnd5GVYahGo3NE0XoMea3cp7pbtp5dVxqMkrVS9hw62mV2Xn0QUlerYcm77zelxl/b6Uh7cFppKrEFdLKQGsQgk/311KkGK2owmVuxBcsn1zqUfltQKeVHnAhpMoX+yNGL0gd9LamHqrX9c+aL/e8E9w3lzDK4w4yaz+2f09LzpvaoTygaIErdtFrLdun7e7kcrCkZoOV4v23Vbp4i1uWUEHpTUB9nHBDh0tuR+zPZ58XCKB04++FkzokE5IAgaUTd0loGzL03ukKy52QT3QhckzqEZB8usag8BaCqC5jRdhu5xHn8xLQylKNnjKCHiIZ9R3amvVNeUBJnTftX/tOeQEeTe4RYQ2Xrgq8o/hsk7lmjNn7YXA6LhVQ0ktJfrmMGcLf3mjQM3JARhceA1HhSmTy7bhXVrWHZmLZQOiyG7LE0P1vDvVveer3Xt9toYzA8BM9CyPYIfiZ0c+GiDt6HlgYk2BT0+/TV/vyeq38uBlSHgO4J/FTVYxX4u8aVqa8qDi9N8L45zGQl9Km4ZGJAM27Br9L5ckWsQw2eiRMbnGw6tWHe1+mO2WrkcyikKVcmXU 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 9 potential issues to consider: - [High] mm/swap: missing SWP_RMAP_CACHE_ONLY on pre-reserved physical swap slots - [Medium] mm/swap: zero-filled and zswap shmem entries lose synchronous swapin fast path - [Medium] mm/swap: mem_cgroup_can_swap() and folio_alloc_swap() ignore vswap exhaustion - [Medium] mm/swap: mandatory vswap relies on GFP_ATOMIC-only cluster allocations - [Medium] mm/swap: swap reporting and OOM accounting ignore mandatory vswap capacity cap - [Medium] mm/swap: cacheline false sharing and barrier in vswap_capacity_in_pages() - [Medium] mm/swap: redundant vswap cluster locking and barriers on swap-in faults - [Medium] mm/swap: missing NULL check or acquire ordering in vswap_capacity_in_pages() - [Medium] mm/swap: redundant cluster locks and zero-page slot churn on disk swapout -- commit 4d9278f9d6b32ab62d490caafb93e1e6851a00d3 Author: Nhat Pham mm/swap: make vswap mandatory This commit initializes the virtual swap device unconditionally when CONFIG_SWAP is enabled, removes the vswap Kconfig and boot controls, and routes all ordinary swapout through virtual swap while reserving physical backing upfront for folios ineligible for zswap. It also caps overcommit and swapoff swap capacity checks at vswap_capacity_in_pages() and uses swap_entry_backend_has_flag() for shmem synchronous swap-in checks. > diff --git a/mm/shmem.c b/mm/shmem.c > index 5d3695886ecd1..a9000a4436746 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c [ ... ] > @@ -2609,10 +2608,12 @@ static int shmem_swapin_folio(struct inode *inode= , pgoff_t index, > /* Look it up and read it in.. */ > folio =3D swap_cache_get_folio(swap); > if (!folio) { > - if (vswap_unuse || data_race(si->flags & SWP_SYNCHRONOUS_IO)) { > - /* Direct swapin skipping swap cache & readahead */ > + if (vswap_unuse || > + swap_entry_backend_has_flag(si, swap, SWP_SYNCHRONOUS_IO)) { > folio =3D shmem_swap_alloc_folio(inode, vmf, index, > - swap, vswap_unuse ? 0 : order, gfp); > + swap, > + vswap_unuse ? 0 : order, > + gfp); > } else { > /* Cached swapin only supports order 0 folio */ > folio =3D shmem_swapin_cluster(swap, gfp, info, index); [Severity: Medium] Does this demote zero-filled and zswap-backed shmem entries to order-0 readahead swap-in? For a zero-filled folio, swap_zeromap_folio_set() releases any physical backing via __vswap_release_backing(), and zswap-backed entries have no physical slot either. In both cases vswap_to_phys() returns 0, so swap_entry_backend_has_flag() returns false and shmem_swapin_folio() falls back to shmem_swapin_cluster(), forcing shmem_split_large_entry() on large entries and triggering speculative readahead of neighboring slots. Zero-filled anonymous entries hit the same regression in do_swap_page(), where both swap_entry_synchronous() and swap_entry_backend_has_flag() return false and send the fault to order-0 swapin_readahead() instead of swapin_sync(). [Severity: Medium] Can mandatory vswap amplify cluster spinlock and barrier overhead on the swap-in fault path? Replacing the unlocked si->flags check here with swap_entry_backend_has_flag() adds an XArray lookup, a ci->lock round-trip, and a get_swap_device()/smp_rmb()/put_swap_device() pair on every shmem swap-in miss. On anonymous swap-in faults, do_swap_page() and should_try_to_free_swap() now perform up to five separate vswap_lock_cluster() round-trips and two get_swap_device()/smp_rmb() pairs for a single fault. In particular, zswap_is_present() checks is_vswap_entry() before zswap_never_enabled(), so swap_entry_synchronous() locks the vswap cluster on every fault even when zswap has never been enabled. Checking zswap_never_enabled() first in zswap_is_present() and resolving the backing type and flags once across do_swap_page() and should_try_to_free_swap() would avoid these redundant lock cycles. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index b0865d617512a..72652a2099e9d 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -2062,25 +2062,37 @@ static int swap_dup_entries_cluster(struct swap_i= nfo_struct *si, > return err; > } > =20 > -bool mem_cgroup_can_vswap(struct mem_cgroup *memcg) > +/** > + * mem_cgroup_can_swap - check backing headroom for ordinary swapout > + * @memcg: the cgroup to query, or NULL for global reclaim > + * @nr_pages: the number of pages the caller wants to swap out > + * > + * Return: true if compression or physical capacity and quota permit swa= pout. > + */ > +bool mem_cgroup_can_swap(struct mem_cgroup *memcg, long nr_pages) > { > - return vswap_is_enabled() && zswap_is_enabled() && > - (!memcg || mem_cgroup_may_zswap(memcg, false)); > + long nr_swap_pages; > + > + if (!vswap_is_enabled()) > + return false; > + > + if (zswap_is_enabled() && > + (!memcg || mem_cgroup_may_zswap(memcg, false))) > + return true; > + > + nr_swap_pages =3D memcg ? mem_cgroup_get_nr_swap_pages(memcg) : > + get_nr_swap_pages(); > + return nr_swap_pages >=3D nr_pages; > } [Severity: Medium] Should mem_cgroup_can_swap() also check whether vswap_si has at least nr_pages of free virtual slots left? Once vswap_usage_in_pages() reaches vswap_capacity_in_pages(), this still returns true whenever zswap is enabled or physical swap has free slots, so reclaim keeps scanning and isolating anonymous folios. In addition, folio_alloc_swap()'s failed: path returns -E2BIG for large folios even when vswap_si is exhausted, causing shrink_folio_list() and shmem_writeout() to split THPs/mTHPs and retry order-0 allocation only to fail again. [ ... ] > @@ -2218,8 +2232,7 @@ int folio_alloc_swap(struct folio *folio) > } > } > =20 > - if (!may_vswap || !vswap_alloc(folio)) > - folio_alloc_phys_swap(folio); > + vswap_alloc(folio); [Severity: Medium] Can removing the physical swap fallback here cause swapout failures under memory pressure because vswap_alloc_cluster() only uses GFP_ATOMIC? Unlike swap_cluster_populate(), which drops its locks and retries with __GFP_HIGH | __GFP_NOMEMALLOC | GFP_KERNEL, vswap_alloc_cluster() performs several GFP_ATOMIC | __GFP_NOWARN allocations (ci_dyn, swap_table, vtable, and xa_alloc()) under percpu_vswap_cluster.lock and ci->lock with no sleeping fallback and without __GFP_NOMEMALLOC. When atomic reserves are depleted, vswap_alloc() fails even with abundant physical swap, triggering futile large-folio splits on -E2BIG, reclaim stalls, or premature OOMs. [ ... ] > if (unlikely(!folio_test_swapcache(folio))) > goto failed; > =20 > + /* Reserve disk-only backing here so large allocation failures can spli= t. */ > + if (!may_zswap && !folio_realloc_swap(folio).val) { > + swap_cache_del_folio(folio); > + goto failed; > + } > + > return 0; [Severity: High] Does reserving physical backing via folio_realloc_swap() here leave SWP_RMAP_CACHE_ONLY clear on physical swap slots whose vswap swap_count is still 0? vswap_alloc() enters the folio into swapcache with swap_count =3D=3D 0, and folio_realloc_swap() allocates physical slots via __swap_cluster_alloc_entries(), which initializes the physical swap_table rmap entries without SWP_RMAP_CACHE_ONLY. folio_realloc_swap() then installs vtable_mk_phys() under ci->lock without checking for swap_count =3D=3D 0, while vswap_mark_cache_only() only runs on a 1 -> 0 transition in swap_put_entries_cluster(). If try_to_unmap() fails in shrink_folio_list() (or the folio is deferred while !mem_cgroup_swap_full() and !folio_test_mlocked()), folio_free_swap() is skipped and the folio returns to the LRU in swapcache with swap_count =3D=3D 0 and physical backing lacking SWP_RMAP_CACHE_ONLY. A concurrent swap_put_entries_cluster() dropping swap_count from 1 to 0 while folio_realloc_swap() has dropped ci->lock for folio_alloc_phys_swap() hits the same state: CPU0 CPU1 folio_realloc_swap() spin_unlock(&ci->lock) folio_alloc_phys_swap() swap_put_entries_cluster() swap_count 1 -> 0 vswap_mark_cache_only() (vtable still NONE/ZSWAP; no-op) spin_lock(&ci->lock) __vtable_set(..., vtable_mk_phys()) spin_unlock(&ci->lock) <-- SWP_RMAP_CACHE_ONLY never set Once swap fills past 50%, cluster_scan_range(), cluster_reclaim_range(), and swap_reclaim_full_clusters() skip Vswap-tagged physical slots without SWP_RMAP_CACHE_ONLY, pinning physical swap space until the folio is freed or swapoff runs and risking premature swap exhaustion. Checking swap_count =3D=3D 0 under ci->lock in folio_realloc_swap() and calling swap_rmap_mark_cache_only() fixes both paths. [Severity: Medium] Does calling folio_realloc_swap() eagerly for every !may_zswap folio add avoidable cluster lock round-trips and zero-page slot churn on disk swapout? For a non-zero disk-backed folio, folio_alloc_swap() and swap_writeout() now perform 8 cluster spinlock cycles and 7 XArray lookups (compared to 3 cluster locks and 0 XArray lookups before): folio_realloc_swap() locks ci->lock just to re-check vtable_type and re-read memcg_id that folio_alloc_swap() already holds, and swap_writeout() locks ci->lock three more times for swap_zeromap_folio_clear(), folio_release_non_phys_swap_backing(), and folio_realloc_swap() again. For zero-filled !may_zswap folios, folio_alloc_swap() allocates physical slots and charges memcg->swap only for swap_zeromap_folio_set() to immediately free the unwritten slots via __vswap_release_backing(), bouncing nr_swap_pages and psi->inuse_pages, uncharging memcg->swap, and invoking swap_slot_free_notify() and potential cluster discards. [ ... ] > +long vswap_capacity_in_pages(void) > { > - return kstrtobool(buf, &vswap_enabled_early); > -} > -early_param("vswap", early_vswap); > + struct swap_info_struct *si; > =20 > -/* vswap does no IO on its own. */ > -static const struct swap_ops vswap_ops =3D { }; > + if (!vswap_is_enabled()) > + return 0; > + /* Pairs with publication in vswap_init(), before allocation is enabled= . */ > + si =3D smp_load_acquire(&vswap_si); > + return si->pages; > +} [Severity: Medium] Can vswap_capacity_in_pages() dereference a NULL vswap_si during boot when CONFIG_JUMP_LABEL=3Dn? Async initramfs unpacking (populate_rootfs() -> do_populate_rootfs() -> shmem_acct_blocks() -> __vm_enough_memory()) runs concurrently with late_initcall(vswap_init). With CONFIG_JUMP_LABEL=3Dn, static_key_enable() uses a relaxed atomic_set() and vswap_is_enabled() uses a relaxed raw_atomic_read(). The conditional branch after vswap_is_enabled() does not order the subsequent smp_load_acquire(&vswap_si) after the load of vswap_key.key.enabled on weakly-ordered CPUs: CPU0 (vswap_init) CPU1 (do_populate_rootfs) vswap_capacity_in_pages() si =3D smp_load_acquire(&vswap_si) (reordered early; reads NULL) smp_store_release(&vswap_si, si) static_branch_enable(&vswap_key) atomic_set(&key->enabled, 1) vswap_is_enabled() -> true return si->pages; <-- NULL deref Checking if (!si) return 0; (or reading si =3D smp_load_acquire(&vswap_si) without relying on the static key for ordering) prevents the NULL pointer dereference. [Severity: Medium] Does calling vswap_capacity_in_pages() from __vm_enough_memory() introduce cacheline false sharing and an acquire barrier on the mmap/brk hot path? Under both OVERCOMMIT_GUESS (vm_overcommit_guess_limit()) and OVERCOMMIT_NEVER (vm_commit_limit()), every __vm_enough_memory() call now invokes vswap_capacity_in_pages(), executing smp_load_acquire(&vswap_si) and reading si->pages. In struct swap_info_struct, pages sits adjacent to frag_clusters[] and atomic_long_t inuse_pages, which swap_usage_add() and swap_usage_sub() modify globally on every swap allocation and free. Since vswap_si->pages is a boot-time constant initialized before static_branch_enable(&vswap_key), caching it in a __ro_after_init scalar avoids both the false sharing and the acquire barrier. > diff --git a/mm/util.c b/mm/util.c > index 47c4cf7400cf7..d0dbe4de593fb 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -924,7 +924,7 @@ unsigned long vm_commit_limit(void) > else > allowed =3D ((totalram_pages() - hugetlb_total_pages()) > * sysctl_overcommit_ratio / 100); > - allowed +=3D total_swap_pages; > + allowed +=3D min(total_swap_pages, vswap_capacity_in_pages()); > =20 > return allowed; > } [Severity: Medium] Should swap reporting and OOM accounting also be capped at vswap_capacity_in_pages() now that a single virtual swap device is mandatory? vswap_init() caps the sole virtual swap device at min(swapfile_maximum_size, REFCOUNT_MAX) (~8 TiB on 64-bit 4 KiB systems, or 512 MiB on 32-bit MIPS), and this commit caps vm_commit_limit(), vm_overcommit_guess_limit(), and swapoff_check_commit() there. However, si_swapinfo() (used by /proc/meminfo and sysinfo(2)), constrained_alloc() in mm/oom_kill.c, and mem_cgroup_get_max() in mm/memcontrol.c still read uncapped total_swap_pages and nr_swap_pages, causing reported swap totals and OOM badness calculations to disagree with actual usable swap capacity when total physical swap exceeds vswap_capacity_in_pages() or vswap_init() fails. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203220010.1302= 207-1-nphamcs@gmail.com?part=3D16