From: sashiko-bot@kernel.org
To: "Nhat Pham" <nphamcs@gmail.com>, linux-mm@kvack.org
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
"Chris Li" <chrisl@kernel.org>,
"Kairui Song" <kasong@tencent.com>,
"Kemeng Shi" <shikemeng@huaweicloud.com>,
"Baoquan He" <baoquan.he@linux.dev>,
"Barry Song" <baohua@kernel.org>,
"Youngjun Park" <youngjun.park@lge.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Yosry Ahmed" <yosry@kernel.org>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Qi Zheng" <qi.zheng@linux.dev>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Axel Rasmussen" <axelrasmussen@google.com>,
"Yuanchu Xie" <yuanchu@google.com>, "Wei Xu" <weixugc@google.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Michal Hocko" <mhocko@kernel.org>,
"David Hildenbrand" <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Hugh Dickins" <hughd@google.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Roman Gushchin" <roman.gushchin@linux.dev>,
"Muchun Song" <muchun.song@linux.dev>,
"Arnd Bergmann" <arnd@arndb.de>,
"Karl Mehltretter" <kmehltretter@gmail.com>,
"Dapeng Mi" <dapeng1.mi@linux.intel.com>,
"Marco Elver" <elver@google.com>,
"Ethan Nelson-Moore" <enelsonmoore@gmail.com>,
"Borislav Petkov (AMD)" <bp@alien8.de>,
"Jeff Layton" <jlayton@kernel.org>, "Tejun Heo" <tj@kernel.org>,
"Michal Koutný" <mkoutny@suse.com>
Subject: Re: [PATCH v7 03/20] mm/swap: prepare zswap and zero storage for virtual entries
Date: Fri, 04 Dec 2026 22:09:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-250721@kernel.org> (raw)
In-Reply-To: <20261203220010.1302207-4-nphamcs@gmail.com>
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 <nphamcs@gmail.com>
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 folio *folio)
> */
> swap_zeromap_folio_clear(folio);
>
> + 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 unlocks.
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 = container_of(ci, struct swap_cluster_info_dynamic, ci);
> +
> + for (ci_off = ci_start; ci_off < ci_start + nr; ci_off++) {
> + vt = __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_class
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 shrinker *shrinker,
> if (!zswap_shrinker_enabled || !mem_cgroup_zswap_writeback_enabled(memcg))
> return 0;
>
> + 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 calling
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 = 0, attempts = 0;
> unsigned long thr;
>
> + /*
> + * 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 = swp_offset(entry);
> - struct xarray *tree = swap_zswap_tree(entry);
> + struct xarray *tree;
> unsigned long index = offset;
> + unsigned int i;
> +
> + /* Virtual entries have no native zswap tree. */
> + if (is_vswap_entry(entry)) {
> + for (i = 0; i < nr; i++)
> + if (vswap_zswap_load(swp_entry(swp_type(entry), offset + i)))
> + return true;
> + return false;
> + }
> + tree = swap_zswap_tree(entry);
>
> 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 fast
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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203220010.1302207-1-nphamcs@gmail.com?part=3
next prev parent reply other threads:[~2026-12-04 22:09 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 21:59 [PATCH v7 00/20] mm: mandatory virtual swap Nhat Pham
2026-12-03 21:59 ` [PATCH v7 01/20] mm/swap: prepare dynamic clusters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 02/20] mm, swap: prepare the swap IO path " Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 03/20] mm/swap: prepare zswap and zero storage for virtual entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot [this message]
2026-12-03 21:59 ` [PATCH v7 04/20] mm/swap: allocate virtual swap slots Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 05/20] mm/swap: return physical entries from the swap allocator Nhat Pham
2026-12-03 21:59 ` [PATCH v7 06/20] mm/swap: resolve physical backing for reads and device flags Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 07/20] mm/swap: prepare physical swapoff for virtual backing Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 08/20] mm/swap: support physical swap as a vswap backend Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 21:59 ` [PATCH v7 09/20] mm, swap: enable THP swapin for vswap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 10/20] mm, swap: write back vswap zswap entries to physical swap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 11/20] mm, swap: reclaim physical slots backing cache-only vswap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 12/20] mm, swap: add debugfs counters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 13/20] mm, swap: only charge physical swap entries Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 14/20] mm, swap: defer memcg_table allocation for physical swap clusters Nhat Pham
2026-12-03 22:00 ` [PATCH v7 15/20] mm, swap: add vmstat and memcg counters for vswap Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 16/20] mm/swap: make vswap mandatory Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 17/20] mm/swap: drop direct physical swapcache handling Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 18/20] mm/zswap: store compressed entries only in the vtable Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 19/20] mm/swap: reclaim physical backing through reverse mappings Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:00 ` [PATCH v7 20/20] mm/swap: move virtual swap metadata into vswap clusters Nhat Pham
2026-12-04 22:09 ` sashiko-bot
2026-12-03 22:14 ` [PATCH v7 00/20] mm: mandatory virtual swap Yosry Ahmed
2026-12-03 23:00 ` Nhat Pham
2026-12-03 23:05 ` Yosry Ahmed
2026-12-03 23:14 ` Nhat Pham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-250721@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baoquan.he@linux.dev \
--cc=bp@alien8.de \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=dapeng1.mi@linux.intel.com \
--cc=david@kernel.org \
--cc=elver@google.com \
--cc=enelsonmoore@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=jlayton@kernel.org \
--cc=kasong@tencent.com \
--cc=kmehltretter@gmail.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=skhan@linuxfoundation.org \
--cc=tj@kernel.org \
--cc=vbabka@kernel.org \
--cc=weixugc@google.com \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.com \
--cc=yuanchu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox