From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net,
chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com,
hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Kunwu Chan" <chentao@kylinos.cn>,
"Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v8 02/14] mm: xswap support for zswap
Date: Fri, 04 Dec 2026 16:48:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-250220@kernel.org> (raw)
In-Reply-To: <20261203164336.864691-3-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] mm/zswap: unnecessary zswap_lru_del() locking and LRU alloc
for xswap entries
- [Medium] mm: zswap_store() queues shrink_worker() on empty LRU when
xswap fills pool
- [Low] mm: unmentioned add_to_avail_list() bug fix and /proc/swaps
change
- [Low] mm: zswap_store() calls shrink_memcg() without checking
nr_real_swapfiles
--
commit 9c57f7ef12d862357f940d3c5e67abd20d6102eb
Author: Chris Li <chrisl@kernel.org>
mm: xswap support for zswap
This commit adds core swap and zswap support for extendable swap devices
(SWP_XSWAP) that have no backing storage, skipping writeback, readahead,
and zswap LRU insertion for xswap entries while tracking active non-xswap
devices via nr_real_swapfiles.
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index d59fa82208620..558c4b75bf928 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> @@ -1323,10 +1331,11 @@ static void add_to_avail_list(struct swap_info_struct *si, bool swapon)
> /*
> * When device is full and device is on the plist, only one updater will
> * see (inuse_pages == si->pages) and will call del_from_avail_list. If
> - * that updater happen to be here, just skip adding.
> + * that updater happen to be here, just skip adding. @val still has
> + * the off-list bit, so compare its counter part.
> */
> pages = si->pages;
> - if (val == pages) {
> + if ((val & SWAP_USAGE_COUNTER_MASK) == pages) {
> /* Just like the cmpxchg in del_from_avail_list */
> if (atomic_long_try_cmpxchg(&si->inuse_pages, &pages,
> pages | SWAP_USAGE_OFFLIST_BIT))
[Severity: Low]
Should this fix in add_to_avail_list() be split into its own commit?
Because atomic_long_fetch_and_relaxed() returns the value before clearing
SWAP_USAGE_OFFLIST_BIT, the old (val == pages) check was always false and
let a full swap device be added back to swap_avail_head. Splitting it out
lets it carry Fixes: b228386cf237 ("mm, swap: clean up plist removal and
adding") for stable backports. Also, the new "xswap" Type column value
added to /proc/swaps by swap_type_str() is not mentioned in the commit
message.
[ ... ]
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 6a66b898ab470..52f350b2c452f 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
[ ... ]
> @@ -1598,7 +1617,8 @@ static bool zswap_store_page(struct folio *folio, long index,
> entry->objcg = objcg;
> entry->referenced = true;
> INIT_LIST_HEAD(&entry->lru);
> - zswap_lru_add(entry);
> + if (can_writeback)
> + zswap_lru_add(entry);
>
> return true;
[Severity: Medium]
Can zswap_entry_free() skip zswap_lru_del() for xswap entries?
zswap_store_page() never adds SWP_XSWAP entries to zswap_list_lru, but
zswap_entry_free() still calls zswap_lru_del() unconditionally on every
xswap swap-in and slot invalidation. list_lru_del() then does the memcg
XArray lookup and takes the shared per-(memcg, node) l->lock spinlock
only to see list_empty(&entry->lru) is true; during slot freeing via
swap_range_free(), that lock is acquired per page while holding ci->lock.
Similarly, zswap_store() unconditionally calls memcg_list_lru_alloc() for
xswap folios that will never be placed on zswap_list_lru. Gating both on
!(__swap_entry_to_info(...)->flags & SWP_XSWAP) avoids the lock contention
and unused per-memcg list_lru allocations.
[ ... ]
> @@ -1667,7 +1687,7 @@ bool zswap_store(struct folio *folio)
> zswap_pool_put(pool);
> put_objcg:
> obj_cgroup_put(objcg);
> - if (!ret && zswap_pool_reached_full)
> + if (!ret && zswap_pool_reached_full && atomic_read(&nr_real_swapfiles))
> queue_work(shrink_wq, &zswap_shrink_work);
> check_old:
> /*
[Severity: Medium]
Does gating zswap_shrink_work on nr_real_swapfiles cause shrink_worker() to
spin when xswap fills the zswap pool?
When both xswap and a real swap device are active, xswap entries can fill
the zswap pool to zswap_max_pages() without putting any entries on
zswap_list_lru. Every subsequent rejected zswap_store() sees
zswap_pool_reached_full and nr_real_swapfiles > 0 and re-queues
zswap_shrink_work back-to-back while reclaim keeps retrying xswap folios.
On each wakeup, shrink_worker() runs MAX_RECLAIM_RETRIES full passes over
every online memcg and NUMA node, taking and dropping l->lock on every
allocated empty list_lru_one (or 16 empty root LRU walks when memcg is
disabled). Gating the wakeup on whether zswap_list_lru actually has
entries would avoid this background spin.
[Severity: Low]
Should the synchronous shrink_memcg() call in zswap_store() also check
nr_real_swapfiles?
When no real swap device is active (nr_real_swapfiles == 0) and a cgroup
hits memory.zswap.max, dirty xswap folios already in swapcache still reach
zswap_store() and call shrink_memcg() synchronously. Because zswap_store()
allocated list_lru_one entries for the cgroup, shrink_memcg() starts a
block plug and takes l->lock on every NUMA node even though zswap_list_lru
is empty and no writeback target exists.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203164336.864691-1-baoquan.he@linux.dev?part=2
next prev parent reply other threads:[~2026-12-04 16:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:43 [PATCH v8 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-12-03 16:43 ` [PATCH v8 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 02/14] mm: xswap support for zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot [this message]
2026-12-03 16:43 ` [PATCH v8 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-12-03 16:43 ` [PATCH v8 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-12-03 16:43 ` [PATCH v8 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
2026-12-03 16:43 ` [PATCH v8 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
2026-12-04 16:48 ` sashiko-bot
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-250220@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chentao@kylinos.cn \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hebaoquan@kylinos.cn \
--cc=kasong@tencent.com \
--cc=klarasmodin@gmail.com \
--cc=kunwu.chan@gmail.com \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=urezki@gmail.com \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.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