From: Kairui Song <ryncsn@gmail.com>
To: Baoquan He <hebaoquan@kylinos.cn>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, chrisl@kernel.org,
kasong@tencent.com, nphamcs@gmail.com, baohua@kernel.org,
youngjun.park@lge.com, hannes@cmpxchg.org, yosry@kernel.org,
shikemeng@huaweicloud.com, chengming.zhou@linux.dev,
baoquan.he@linux.dev, david@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 00/16] xswap: extendable swap device backed by zswap
Date: Tue, 1 Sep 2026 01:54:29 +0800 [thread overview]
Message-ID: <apVNB2FRTFMDtvGP@KASONG-MC4> (raw)
In-Reply-To: <20260827094509.1016740-1-hebaoquan@kylinos.cn>
On Thu, Aug 27, 2026 at 05:44:50PM +0800, Baoquan He wrote:
> xswap is an extendable swap device with no backing storage. Swapped-out
> pages live only in zswap, so the device wastes no disk space and its
> size is independent of any physical device.
>
> xswap decouples PTE swap entries from physical backing storage. The
> cluster_info array is backed by a sparse vmalloc (VM_SPARSE) area that is
> grown and shrunk on demand:
>
> - Grow: when cluster allocation runs out of free clusters and the device
> is below its ceiling, more physical pages are mapped into the VM_SPARSE
> area and their clusters are added to the free list.
>
> - Shrink: when contiguous free clusters accumulate at the tail of the
> mapped range (tracked in O(1) via nr_free_tail), they are unmapped and
> the backing pages freed. Shrink is deferred to a workqueue to avoid
> lock recursion.
>
Hi Baoquan,
I didn't check too many details on how the implementation in previous
RFC until now, After looking at it, using VM_SPARSE to setup the cluster
info area is a really smart idea, really good job!
I think many info are missing in the cover letter though so I wasn't
sure how this grow and shrink works from the description, after
checking the code, it looks much cleaner to me now, correct me
if I'm wrong:
Every xswap device will have a huge and fixed "hard limit"
(si->max and si->nr_clusters_max), and practically can be considered
large enough to hold any workload, and won't change once swapon
is done.
The actually data (si->cluster_info) of xswap device is completely
sparse and dynamic using VM_SPARSE, and so we don't need to change
any existing routine. It grow/alloc and shrink/free automatically by
the kernel, limited or driven by a "soft limit" (si->nr_clusters
and si->pages) which you can modify using the interface below.
Once concern is that the "hard limit" is now the total RAM size. Isn't
that actually a bit small? Will be better if that one is tunable too?
With a parameter, and before swap on, as the hard limit is hard to
adjust once swapon is done. Any thing limiting this?
And I think these details better be mentioned bit more too.
> A per-device ceiling (nr_clusters) bounds growth and is adjustable at
> runtime via debugfs.
>
> Interface:
>
> /sys/kernel/mm/xswap/create write "<percent> [<prio>]" to
> create a device; percent is a
> percent of RAM (0 for the default),
> prio is an optional swap priority
> (default DEF_SWAP_PRIO)
With what I have read so far, the mandatory percent limit here is kind of
strange, even with 0 as default. Why not make both args optional and just
let it grow without any limit by default? It looks more "fully dynamic"
that way.
> /sys/kernel/mm/xswap/destroy write a swap type to tear down
> a device
> /sys/kernel/debug/xswap/type<N>_cluster_limit
> read/write the per-device
> cluster ceiling
Having a lot of type<N>_cluster_limit in a seperate debug path
looks a bit odd to me too, and the _cluster_limit doesn't look
like a debug interface, we will be relying on debugfs for setting
the limit, also see below.
>
> Since xswap has no backing, swapped-out pages are stored compressed in
> zswap: physical writeout is skipped, and zswap writeback is disabled when
> every swapfile in the system is an xswap device. xswap requires zswap, so
> device creation is refused when zswap is unavailable.
>
> Naming:
> ======
> I'm going with "xswap" (the "x" for extendable/extension) rather than "vswap".
> Chris suggested this name, and this aligns with the "VFS-like swap layers"
> direction Chris Li described in the first swap abstraction LPC talk
> (co-hosted with Yosry) the swap ops and the xswap extension interfaces in
> this series are moving toward exactly that. I don't have a strong preference
> between xswap and vswap, so if reviewers object to the name, please comment.
>
> Note:
> =====
> This patchset only build the base. On top of this, the subsequent core code
> implementation of xswap writeback, rmap etc can be done more easily. E.g, we
> only need add one field in struct swap_cluster_info to let xs_table point to
> physical swap entry, or zswap entry etc. On top of this patchset, no need to
> stir core data structure too much or introduce extra data structure.
>
> --- a/mm/swap.h
> +++ b/mm/swap.h
> @@ -57,6 +57,9 @@ struct swap_cluster_info {
> u8 order;
> atomic_long_t __rcu *table; /* Swap table entries, see mm/swap_table.h */
> unsigned int *extend_table; /* For large swap count, protected by ci->lock */
> +#ifdef CONFIG_XSWAP
> + unsigned long *xs_table;
> +#endif
>
> Testing (taken on qemu kvm guest with 8G memory):
> =========
> 1. enable zswap and create/destroy xswap device
> ~# echo 0 > /sys/kernel/mm/xswap/create
> -bash: echo: write error: Operation not supported
> ~# echo 1 > /sys/module/zswap/parameters/enabled
> ~# echo 0 > /sys/kernel/mm/xswap/create
Recent proposal have mentioned mm/xswap, and mm/swap/tiers, while we
already have mm/swap and module/zswap. I think it's fine to use sysfs
to organize things but will it be good to have it in unified way to
put them all under mm/swap/? And will mkdir be prettier than
echo > create? For these part, just an idea, no strong opinion here.
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap0 xswap 2.3G 0B -1
> ~# echo 0 > /sys/kernel/mm/xswap/destroy
> ~# swapon
>
> 2. create xswap device and tune the zswap size
>
> ~# echo "50 10" > /sys/kernel/mm/xswap/create
> ~# echo 0 > /sys/kernel/mm/xswap/create
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap0 xswap 3.9G 0B 10
> xswap1 xswap 2.3G 0B -1
>
> ~# cat /sys/kernel/debug/xswap/type0_cluster_limit
> 1990
> ~# cat /sys/kernel/debug/xswap/type1_cluster_limit
Can we just use size instead? Calculating the cluster number
seems not neccessary, only making it harder to use, if this
is suppose to be a formal interface and not debug only.
> 1194
> ~# echo 2048 > /sys/kernel/debug/xswap/type0_cluster_limit
> ~# echo 2048 > /sys/kernel/debug/xswap/type1_cluster_limit
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap0 xswap 4G 0B 10
> xswap1 xswap 4G 0B -1
>
> 3. under heavy memory pressure tune swap size or destroy xswap device
>
> ~# stress-ng --vm 1 --vm-bytes 8G --vm-keep --timeout 120s &
>
> ~# echo 1024 > /sys/kernel/debug/xswap/type0_cluster_limit
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap0 xswap 2G 2.6G 10
> xswap1 xswap 4G 182M -1
> ~# echo 1024 > /sys/kernel/debug/xswap/type1_cluster_limit
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap0 xswap 2G 1.4G 10
> xswap1 xswap 2G 315.4M -1
>
> ~# echo 0 > /sys/kernel/mm/xswap/destroy
> ~# swapon
> NAME TYPE SIZE USED PRIO
> xswap1 xswap 2G 1.1G -1
>
> I tried create/destroy and grow/shrink xswap device under heavy
> memory pressure, all passed.
Do you have some performance reading on this? I remember you had
some in your previous RFC, better to at least keep a link, I spend
quite some time to find the previous zswap test result from you.
I noticed this series is different from what you sent before as it
only contains the foundation so there could be no performance gain
currently but still, might worth mentioning what this could achieve.
Another thing is, maybe we can defer the implementation of shrink
for easier understand and review? The memory consumption is totally
acceptable even without shrink.
next prev parent reply other threads:[~2026-08-31 17:54 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 9:44 [PATCH 00/16] xswap: extendable swap device backed by zswap Baoquan He
2026-08-27 9:44 ` [PATCH 01/16] mm: zswap: return -ENOENT when the swap device is gone Baoquan He
2026-09-02 14:53 ` Nhat Pham
2026-09-03 7:54 ` Baoquan He
2026-08-27 9:44 ` [PATCH 02/16] mm: xswap support for zswap Baoquan He
2026-08-27 9:44 ` [PATCH 03/16] mm, swap: add CONFIG_XSWAP and xswap fields to swap_info_struct Baoquan He
2026-08-27 9:44 ` [PATCH 04/16] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-08-27 9:44 ` [PATCH 05/16] mm, swap: add xswap cluster grow via VM_SPARSE vmalloc Baoquan He
2026-08-27 9:44 ` [PATCH 06/16] mm, swap: add sysfs create interface for xswap Baoquan He
2026-08-27 9:44 ` [PATCH 07/16] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-09-02 14:15 ` Nhat Pham
2026-09-03 8:24 ` Baoquan He
2026-08-27 9:44 ` [PATCH 08/16] mm, swap: add xswap_try_shrink and shrink trigger on cluster free Baoquan He
2026-08-27 9:44 ` [PATCH 09/16] mm, swap: free backing pages in xswap_unmap_clusters Baoquan He
2026-08-27 9:45 ` [PATCH 10/16] mm, swap: add nr_free_tail for O(1) xswap shrink detection Baoquan He
2026-08-27 9:45 ` [PATCH 11/16] mm, swap: add adjustable runtime ceiling (nr_clusters) for xswap Baoquan He
2026-08-27 9:45 ` [PATCH 12/16] mm, swap: add debugfs knob for xswap per-device cluster limit Baoquan He
2026-08-27 9:45 ` [PATCH 13/16] mm, swap: defer xswap shrink to workqueue to avoid lock recursion Baoquan He
2026-09-02 14:50 ` Nhat Pham
2026-09-03 9:17 ` Baoquan He
2026-08-27 9:45 ` [PATCH 14/16] mm, swap: refactor swapoff + add xswap_destroy Baoquan He
2026-09-03 6:59 ` Youngjun Park
2026-09-04 5:33 ` Baoquan He
2026-08-27 9:45 ` [PATCH 15/16] mm, swap: require zswap for xswap devices Baoquan He
2026-09-03 6:52 ` Youngjun Park
2026-09-04 7:57 ` Baoquan He
2026-08-27 9:45 ` [PATCH 16/16] mm, swap: allow setting xswap device priority at creation Baoquan He
2026-08-27 13:59 ` [syzbot ci] Re: xswap: extendable swap device backed by zswap syzbot ci
2026-08-31 8:35 ` Baoquan He
2026-08-31 17:54 ` Kairui Song [this message]
2026-09-01 11:03 ` [PATCH 00/16] " Baoquan He
2026-09-02 14:10 ` Nhat Pham
2026-09-04 9:42 ` Baoquan He
2026-09-02 14:33 ` Nhat Pham
2026-09-03 7:35 ` Youngjun Park
2026-09-04 3:33 ` 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=apVNB2FRTFMDtvGP@KASONG-MC4 \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hebaoquan@kylinos.cn \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=shikemeng@huaweicloud.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