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 06/14] mm, swap: create the xswap device from swapon(2)
Date: Mon, 30 Nov 2026 15:09:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-241465@kernel.org> (raw)
In-Reply-To: <20261129150755.191662-7-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm, swap: xswap_create() breaks large-folio swapout by
omitting SWP_BLKDEV
--
commit 282f185a2ad0b754fef5ebdb7c9c3e00cfa24f2b
Author: Baoquan He <hebaoquan@kylinos.cn>
mm, swap: create the xswap device from swapon(2)
This commit adds support for activating a file-less xswap device via
swapon("xswap", ...), sized at twice RAM with lazily mapped clusters.
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 912cfa68ba01a..4e598ab8da656 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
[ ... ]
> @@ -3985,6 +4021,117 @@ static int setup_swap_clusters_info(struct swap_info_struct *si,
> return err;
> }
>
> +#ifdef CONFIG_XSWAP
> +/*
> + * Create the file-less xswap device, sized at twice RAM. Called from
> + * swapon(2) with SWAP_FLAG_XSWAP; there is at most one device per system.
> + */
> +static int xswap_create(int prio)
> +{
> + struct swap_info_struct *si;
> + unsigned long ram, maxpages;
> + unsigned int type;
> + int error;
> +
> + mutex_lock(&xswap_ctl_lock);
> +
> + spin_lock(&swap_lock);
> + for (type = 0; type < nr_swapfiles; type++) {
> + struct swap_info_struct *q = swap_info[type];
> +
> + if (q && (q->flags & SWP_XSWAP)) {
> + spin_unlock(&swap_lock);
> + error = -EBUSY;
> + goto out;
> + }
> + }
> + spin_unlock(&swap_lock);
> +
> + si = alloc_swap_info();
> + if (IS_ERR(si)) {
> + error = PTR_ERR(si);
> + goto out;
> + }
> +
> + INIT_WORK(&si->discard_work, swap_discard_work);
> + INIT_WORK(&si->reclaim_work, swap_reclaim_work);
> +
> + ram = totalram_pages();
> + maxpages = min_t(unsigned long, ram * 2, swapfile_maximum_size);
> + /* A cluster index is an unsigned int, so cap the cluster count. */
> + if (maxpages / SWAPFILE_CLUSTER > UINT_MAX)
> + maxpages = (unsigned long)UINT_MAX * SWAPFILE_CLUSTER;
> + /* Cluster-aligned, so no cluster holds a slot past si->max. */
> + if (maxpages > SWAPFILE_CLUSTER)
> + maxpages = rounddown(maxpages, SWAPFILE_CLUSTER);
> + if (maxpages < 2)
> + maxpages = 2;
> +
> + si->bdev = NULL;
> + si->swap_file = NULL;
> + si->flags |= SWP_XSWAP | SWP_SOLIDSTATE;
[Severity: Medium]
Does leaving SWP_BLKDEV unset on the xswap device break large-folio
swapout across the system once xswap is activated?
cluster_alloc_swap_entry() rejects order > 0 allocations unless
SWP_BLKDEV is set:
mm/swapfile.c:cluster_alloc_swap_entry() {
...
if (order && !(si->flags & SWP_BLKDEV))
return 0;
...
}
Because xswap defaults to DEF_XSWAP_PRIO (0x7fff), it sits at the head of
swap_avail_head. When swap_alloc_slow() tries the xswap device first for
a large folio, cluster_alloc_swap_entry() fails and swap_alloc_slow()
immediately returns on folio_test_large(folio) without trying any
lower-priority SWP_BLKDEV devices:
mm/swapfile.c:swap_alloc_slow() {
...
if (get_swap_device_info(si)) {
cluster_alloc_swap_entry(si, folio);
put_swap_device(si);
if (folio_test_swapcache(folio))
return;
if (folio_test_large(folio))
return;
}
...
}
As a result, folio_alloc_swap() fails with -E2BIG for every large folio,
forcing reclaim to split all large folios into order-0 pages on swapout.
Should cluster_alloc_swap_entry() also allow SWP_XSWAP (e.g. checking
!(si->flags & (SWP_BLKDEV | SWP_XSWAP)))?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129150755.191662-1-baoquan.he@linux.dev?part=6
next prev parent reply other threads:[~2026-11-30 15:09 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 [this message]
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
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-241465@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