From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org,
kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org,
corbet@lwn.net, nphamcs@gmail.com, baohua@kernel.org,
youngjun.park@lge.com, shikemeng@huaweicloud.com,
yosry@kernel.org, chengming.zhou@linux.dev, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v7 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap
Date: Mon, 30 Nov 2026 15:09:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-241472@kernel.org> (raw)
In-Reply-To: <20261129150755.191662-14-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mm, swap: no_cache in alloc_swap_scan_cluster() fragments SSD
free clusters
- [Medium] mm, swap: early goto failed in folio_alloc_swap() skips
MEMCG_SWAP_FAIL
- [Medium] mm, swap: folio_alloc_swap() returns -E2BIG when real
swapfiles are full
--
commit 635affe850d5047e3d0a27127b5b71819aadffb6
Author: Baoquan He <hebaoquan@kylinos.cn>
mm, swap: do not give an xswap slot to a cgroup that cannot zswap
This commit skips xswap devices during swap slot allocation when the
folio's cgroup cannot accept another zswap page, falling back to physical
swap devices instead.
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 8b2082bdac082..3a84dbd7a54c6 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> @@ -1197,7 +1199,7 @@ static bool swap_prefer_free_cluster(struct swap_info_struct *si)
> static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si,
> struct swap_cluster_info *ci,
> struct folio *folio,
> - unsigned long offset)
> + unsigned long offset, bool no_cache)
> {
> unsigned long next = SWAP_ENTRY_INVALID, found = SWAP_ENTRY_INVALID;
> unsigned long start = ALIGN_DOWN(offset, SWAPFILE_CLUSTER);
> @@ -1238,6 +1240,9 @@ static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si,
> relocate_cluster(si, ci);
> swap_cluster_unlock(ci);
> if (si->flags & SWP_SOLIDSTATE) {
> + if (no_cache &&
> + this_cpu_read(percpu_swap_cluster.si[order]) != si)
> + return found;
> this_cpu_write(percpu_swap_cluster.offset[order], next);
> this_cpu_write(percpu_swap_cluster.si[order], si);
> } else {
[Severity: High]
Does skipping the percpu_swap_cluster update when no_cache is true fragment
si->free_clusters on SWP_SOLIDSTATE physical swap devices?
For SWP_SOLIDSTATE devices, relocate_cluster() moves a newly allocated,
partially used cluster straight to si->frag_clusters[ci->order], relying on
percpu_swap_cluster to retain the cursor for the remaining free slots.
When a cgroup with !may_zswap falls back to a physical SSD while
percpu_swap_cluster.si[order] is NULL or points to the higher-priority
xswap device, returning early discards next. The next !may_zswap
allocation on that CPU misses swap_alloc_fast() and re-enters
cluster_alloc_swap_entry(), which drains another fresh cluster from
si->free_clusters before consulting si->frag_clusters[order]. Each
order-0 allocation therefore strands a 2 MiB free cluster on
si->frag_clusters[0] with only 1 of 512 slots used, exhausting free
clusters for large folio allocations.
Conversely, if percpu_swap_cluster.si[order] already equals the physical
device si (for example, left over with offset == 0 after a previous
cluster filled up), this check is false and caches next on the physical
device, causing subsequent may_zswap allocations on this CPU to use the
lower-priority physical device instead of xswap.
[ ... ]
> @@ -2017,10 +2063,17 @@ int folio_alloc_swap(struct folio *folio)
> }
> }
>
> + /*
> + * Only xswap devices exist and this folio cannot use them; there is
> + * no slot to find.
> + */
> + if (!may_zswap && !atomic_read(&nr_real_swapfiles))
> + goto failed;
> +
> again:
> local_lock(&percpu_swap_cluster.lock);
> - if (!swap_alloc_fast(folio))
> - swap_alloc_slow(folio);
> + if (!swap_alloc_fast(folio, may_zswap))
> + swap_alloc_slow(folio, may_zswap);
> local_unlock(&percpu_swap_cluster.lock);
>
> if (!order && unlikely(!folio_test_swapcache(folio))) {
> @@ -2028,6 +2081,20 @@ int folio_alloc_swap(struct folio *folio)
> goto again;
> }
>
> + /*
> + * The gate was skipped when there was no device; one may have
> + * appeared since, so ask the slot itself.
> + */
> + if (unlikely(!zswap_checked && folio_test_swapcache(folio) &&
> + (__swap_entry_to_info(folio->swap)->flags & SWP_XSWAP))) {
> + zswap_checked = true;
> + may_zswap = folio_may_zswap(folio);
> + if (!may_zswap) {
> + swap_cache_del_folio(folio);
> + goto again;
> + }
> + }
> +
> /* Need to call this even if allocation failed, for MEMCG_SWAP_FAIL. */
> if (unlikely(mem_cgroup_try_charge_swap(folio))) {
> swap_cache_del_folio(folio);
[Severity: Medium]
Does jumping directly to failed when !may_zswap && !nr_real_swapfiles skip
MEMCG_SWAP_FAIL accounting in mem_cgroup_try_charge_swap()?
In addition, because again is placed after that check, if the post-allocation
!zswap_checked path detects !may_zswap after racing with xswap activation,
goto again bypasses the !nr_real_swapfiles shortcut and scans the swap
lists even when no real swapfiles exist.
> @@ -2045,6 +2112,13 @@ int folio_alloc_swap(struct folio *folio)
> if (mem_cgroup_get_folio_swap_margin(folio) <= 0)
> return -ENOMEM;
>
> + /*
> + * Only xswap devices exist and the folio cannot use them; splitting
> + * cannot help.
> + */
> + if (!may_zswap && !atomic_read(&nr_real_swapfiles))
> + return -ENOMEM;
> +
> return order ? -E2BIG : -ENOMEM;
> }
[Severity: Medium]
Can folio_alloc_swap() still return -E2BIG for a !may_zswap large folio
when all real swapfiles are full?
del_from_avail_list() only decrements nr_real_swapfiles on swapoff, not
when a real swap device fills up, while get_nr_swap_pages() includes free
pages on xswap devices. If real swapfiles are active but full and xswap
still has free pages, both get_nr_swap_pages() <= 0 and !nr_real_swapfiles
are false, so folio_alloc_swap() returns -E2BIG and causes callers to split
the large folio even though order-0 swap allocation cannot succeed either.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129150755.191662-1-baoquan.he@linux.dev?part=13
next prev parent reply other threads:[~2026-11-30 15:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 15:07 [PATCH v7 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-11-29 15:07 ` [PATCH v7 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 02/14] mm: xswap support for zswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-11-29 15:07 ` [PATCH v7 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-11-29 15:07 ` [PATCH v7 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-11-29 15:07 ` [PATCH v7 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-11-29 15:07 ` [PATCH v7 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-11-30 15:09 ` sashiko-bot [this message]
2026-11-29 15:07 ` [PATCH v7 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
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-241472@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chengming.zhou@linux.dev \
--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=shikemeng@huaweicloud.com \
--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