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 10/20] mm, swap: write back vswap zswap entries to physical swap
Date: Fri, 04 Dec 2026 22:09:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-250728@kernel.org> (raw)
In-Reply-To: <20261203220010.1302207-11-nphamcs@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mm: zswap: GFP_NOFS reclaim enters FS swapfile via
shrink_memcg()
- [Medium] mm: zswap: shrinker fails to stop scanning on physical swap
exhaustion
- [Medium] mm: zswap: swap_cache_del_folio_rollback() erases workingset
shadows
--
commit e4671ceb7b90c4ba65b27c95c8ebe7436fb2e260
Author: Nhat Pham <nphamcs@gmail.com>
mm, swap: write back vswap zswap entries to physical swap
This commit adds support for writing back zswap-backed vswap entries to
physical swap by allocating physical backing on demand in
zswap_writeback_entry(), updating the zswap shrinkers to run when
physical swap is available, and adding swap_cache_del_folio_rollback()
to restore cgroup v1 swap accounting on writeback failure.
Link: https://lore.kernel.org/all/sashiko-outbox-181080@kernel.org/
[ ... ]
> diff --git a/mm/swap_state.c b/mm/swap_state.c
> index ee3d8fa5c1f3c..f7df517cf66a0 100644
> --- a/mm/swap_state.c
> +++ b/mm/swap_state.c
> @@ -374,6 +374,20 @@ void __swap_cache_del_folio(struct swap_cluster_info *ci, struct folio *folio,
> __swap_cache_do_del_folio(ci, folio, entry, shadow);
> }
>
> +static void swap_cache_del_folio_common(struct folio *folio, bool rollback)
> +{
> + struct swap_cluster_info *ci;
> + swp_entry_t entry = folio->swap;
> +
> + ci = swap_cluster_lock(__swap_entry_to_info(entry), swp_offset(entry));
> + if (rollback)
> + memcg1_swapin_abort(folio, ci);
> + __swap_cache_del_folio(ci, folio, entry, NULL, false);
> + swap_cluster_unlock(ci);
> +
> + folio_ref_sub(folio, folio_nr_pages(folio));
> +}
[Severity: Medium]
Does swap_cache_del_folio_rollback() permanently erase the workingset
eviction shadow for entries whose writeback aborts?
zswap_writeback_entry() calls __swap_cache_alloc_folio() before
folio_realloc_swap(), so __swap_cache_alloc() replaces the swap table
shadow with the temporary folio and runs workingset_refault(). When
folio_realloc_swap() then fails, passing NULL as the shadow to
__swap_cache_del_folio() discards the eviction shadow for the entry that
remains in zswap while leaving behind spurious refault accounting, which
degrades thrashing detection and reclaim balance under tight swap.
[ ... ]
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 25d4c3f7785ac..54b4ddcf7d733 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
[ ... ]
> @@ -1342,7 +1372,7 @@ 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())
> + if (!zswap_writeback_possible())
> return 0;
[Severity: Medium]
Should zswap_shrinker_scan() also check zswap_writeback_possible() and
return SHRINK_STOP when physical swap is exhausted?
do_shrink_slab() calls count_objects() once and then invokes
scan_objects() in repeated batches, so running out of physical swap
partway through a batch still enters another full scan batch before
returning SHRINK_STOP.
Two related gaps keep the LRU walk running after swap is exhausted:
zswap_writeback_entry() returns -ENOMEM when folio_realloc_swap() fails,
which shrink_memcg_cb() treats as LRU_RETRY rather than stopping the
walk, so remaining entries allocate and roll back swapcache folios,
contend on swap locks in swap_sync_discard(), and rotate cold entries to
the LRU tail. shrink_memcg() also checks zswap_writeback_possible()
only once before its for_each_node_state() loop, continuing to scan
remaining NUMA nodes after swap runs out on an earlier node.
[ ... ]
> @@ -1439,7 +1470,7 @@ static int shrink_memcg(struct mem_cgroup *memcg)
> if (!mem_cgroup_zswap_writeback_enabled(memcg))
> return -ENOENT;
>
> - if (vswap_is_enabled())
> + if (!zswap_writeback_possible())
> return -ENOENT;
[Severity: High]
Can GFP_NOFS direct reclaim now re-enter a filesystem swapfile through
shrink_memcg() and deadlock?
During GFP_NOFS reclaim, may_enter_fs() allows unbacked vswap folios
into swap_writeout(), relying on swap_writeout() to reject
SWAP_OPS_F_REQUIRE_NOFS devices (such as NFS or SMB swapfiles) when
ctx->nofs is set. However, swap_writeout() calls zswap_store() before
that check without propagating ctx->nofs:
shrink_folio_list() [ctx.nofs = true]
-> swap_writeout()
-> zswap_store() [!obj_cgroup_may_zswap()]
-> shrink_memcg() [ctl.io_ctx.nofs = false]
-> zswap_writeback_entry()
-> folio_realloc_swap()
-> __swap_writeout()
Now that shrink_memcg() runs whenever get_nr_swap_pages() > 0, hitting
memory.zswap.max during GFP_NOFS reclaim can allocate a slot on a
SWAP_OPS_F_REQUIRE_NOFS swapfile and submit writeback while the caller
holds filesystem locks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203220010.1302207-1-nphamcs@gmail.com?part=10
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
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 [this message]
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-250728@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