From: Baoquan He <baoquan.he@linux.dev>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org,
kasong@tencent.com, hannes@cmpxchg.org, corbet@lwn.net,
yosry@kernel.org, nphamcs@gmail.com, muchun.song@linux.dev,
baohua@kernel.org, youngjun.park@lge.com, hughd@google.com,
baolin.wang@linux.alibaba.com, baoquan.he@linux.dev,
Baoquan He <hebaoquan@kylinos.cn>
Subject: [PATCH v2 00/32] mm, swap: extendable swap devices (xswap phases II-IV)
Date: Fri, 4 Dec 2026 02:12:47 +0800 [thread overview]
Message-ID: <20261203181319.901844-1-baoquan.he@linux.dev> (raw)
From: Baoquan He <hebaoquan@kylinos.cn>
This is the second part of the xswap series. Phase I, posted
separately, added the file-less swap device: a sparse swap address
space that grows on demand, with the data stored in zswap. This part
gives the device a physical backend, accounts the swap that really
reaches a device, and unifies the per-slot backend records. It applies
on top of the phase I series.
Phase II (patches 1-17): a physical backend for xswap slots
-----------------------------------------------------------
A zswap-only slot has one copy: when zswap evicts or refuses the page,
the data is gone. A slot can now be written to a contiguous range of
physical swap slots on a real swap device. The xswap slot stays the
identity, and the physical slots are tagged with their owning xswap
entry, so writeback, readback and rebuild can find each other.
zswap eviction now has a destination, and a refused store falls back to
a real device instead of leaving the page resident. A cache-only entry
releases its physical range early. A large xswap folio is accepted only
when a contiguous physical range can back it, and is read back with one
I/O; otherwise reclaim is asked to split the folio. THP swapin is
enabled for entries whose whole range is contiguous on one device.
A backend that requires NOFS is skipped when the caller may not enter
the filesystem.
This partially refers to Nhat's vswap-v4 series: patch 1 is consistent
with his patch 3, patch 18/19/20/21 are from his patch 8. Tagging a swap
table entry with its owning xswap entry, releasing the physical range of
a cache-only entry, and enabling THP swapin, the principle is similar,
but the implementation is not, because the underlying data structures
differ, add Nhat's Co-developed-by.
Phase III (patches 18-26): swap accounting
------------------------------------------
An xswap entry is recorded with its owner at allocation, but the swap
charge is taken only when the entry gets a physical backend slot, and
given back with it. memory.swap.current therefore matches the backend
device's Used page for page. A zswap-only entry is not charged: the
compressed pool is already charged as memory, and charging it as swap
would count it twice. memory.swap.max=0 still permits swapout through
zswap. cgroup v1 keeps memsw on the slot, so xswap must not touch memsw
when it uncharges the backing.
Phase IV (patches 27-32): per-slot backend records
--------------------------------------------------
Every swap device keeps a per-cluster backend table, allocated on
demand: 512 words, one per slot. A word is either a zswap entry pointer
(low bit 1) or a physical backend entry (low bit 0); zero means no
record. zswap entries are indexed here instead of a per-type xarray,
so a lookup is O(1) by cluster. Reads take no cluster lock; the table
is allocated before the first record is published. A folio's slots or
a cluster's free batch are released with one range walk. The xswap
specific hooks run only on xswap devices.
Design notes
------------
An xswap slot is still a swap entry: the physical backend is a range of
slots on the real device, not a separate address space. The reverse map
is kept on the physical slot, so the physical device's reclaim scanner
can find the owner without walking the xswap cluster array. The owner
is published before the reverse map, and a stale range is dropped before
it is reused.
Testing
-------
QEMU KVM guest, 8G RAM, booted with xswap.max=10G. The complete
46-patch queue was built and booted on 1a7610248a38:
- functional matrix: 30 checks passed, 0 failed; the overcommit case
was run separately with vm.overcommit_memory=2 (8.15G RAM,
overcommit_ratio 50, CommitLimit 14.56G, Committed_AS 4.65G, a
10.49G device) and passed
- swapoff xswap and swapoff -a, including destroying with 1,075,128 kB
of live pages
- 2000 create/destroy cycles: no per-cluster state is leaked (largest
slab growth 196 objects)
- a cgroup that cannot zswap gets no xswap slot
- the vmallocinfo-reader stress with the grow test is clean
- dmesg is clean except for the memcg OOM kill that the cgroup gate
test asks for
The backend-specific tests were run on the previous base; the rebase to
1a7610248a38 is patch-identical (range-diff reports no change), so the
results carry over:
- backend readback: every byte still holds the pattern (1.57M pages)
- writeback + destroy: 3 cycles, the backend returns to 0 every time
- THP swapin: 570,880 pages read back
- shmem and split fallback: PASS
- memcg charge P1-P6: ALL PASS
- limit and race tests: PASS
Performance
-----------
The phase II backend is about capacity, not pageout speed. With the
complete queue on an earlier mm-new snapshot:
- 128 GiB MADV_PAGEOUT, 144 threads, interleaved NUMA: 87,540 vs
87,015 instructions per swapped page (-0.6%), 3,296 vs 3,304 MB/s,
about 40 seconds of pageout on both. The difference is within the
run-to-run spread.
- usemem 64G in a 48G cgroup: with both kernels keeping the data in
zswap, the median was 151.8 s (base) vs 145.2 s (xswap). That 4.3%
difference is smaller than the run-to-run spread.
- kbench, 1G memcg, 40 jobs, THP off, no writeback: median 225.58 s
vs 225.21 s, total CPU 5657.9 s vs 5580.8 s, peak RSS 867 vs 863
MiB, zswap peak 193 vs 227 MiB. This run measures the slot array
and the zswap frontend; the backend is not used with writeback off.
Limitations
-----------
A large folio needs a contiguous physical range. If the range cannot be
allocated, the folio is split; a zswap-backed or mixed large folio is
read back at a smaller order. THP swapin is only used when the whole
range is contiguous on one device. Writeback needs a real swap device;
xswap-only capacity is still the zswap pool.
xswap.max=max reserves a large vmalloc range for the cluster_info
array. The per-type zswap tree of phase I is gone in this series: zswap
entries are indexed in the per-cluster backend table (phase IV). The
overcommit semantics for the swap address space are still open, as
described in the phase I posting. Runtime shrink is phase V and is not
part of this series.
This series depends on the phase I series ([PATCH v8 00/14]); apply
phase I first. The base is 1a7610248a38 (mm-new, 7.4.0-rc4); the phase
I tip is 779bedee9865 and this series ends at 3722b1e2daa3.
History:
======
[PATCH 00/12] mm, swap: give xswap a physical backend (xswap phase II)
https://lore.kernel.org/all/20261003005900.909710-1-hebaoquan@kylinos.cn/T/#u
[PATCH 0/6] mm, swap: charge xswap for physical backing (xswap phase III)
https://lore.kernel.org/all/20261003011111.1003090-1-hebaoquan@kylinos.cn/T/#u
The entire xswap code can be found here:
====
https://github.com/baoquan-he/linux.git xswap-v8
Baoquan He (27):
mm, swap: tag a swap table entry with its owning xswap entry
mm, swap: prepare the folio-less allocation path for xswap
mm, swap: add a physical backend for xswap slots
mm, swap: support swapoff of an xswap physical backend
mm, swap: use the xswap physical backend
mm, swap: fall back to disk when zswap refuses an xswap page
mm, swap: reclaim physical slots backing cache-only xswap entries
mm, swap: drop swap_folio_sector()
mm, swap: drop a stale xswap physical slot range before reallocating
mm, swap: publish the xswap backend owner before its reverse map
mm, swap: skip a NOFS backend for xswap physical writeback
mm, swap: pass the folio order through the swap slot allocator
mm, swap: allocate a multi-slot range without a folio
mm, swap: pass the folio order to the xswap physical backend
mm, swap: enable large xswap folios with a contiguous physical slot
range
mm, swap: enable THP swapin for xswap entries
mm, swap: do not retake the cluster lock when uncharging an xswap slot
mm, swap: uncharge an xswap backend where its record is cleared
mm, swap: account xswap backends for cgroup v1
mm, swap: drop a refused xswap backend slot range directly
mm, swap: route xswap by the zswap eligibility without flushing
mm, swap: keep a per-cluster backend record for every swap device
mm, swap: encode the per-slot backend record
mm, swap: add accessors for the backend record
mm, zswap: index entries in the swap device's backend table
mm, swap: release a range of backend handles at once
mm, swap: only run the xswap backend hooks on xswap devices
Nhat Pham (5):
mm, swap: prepare the swap IO path for xswap backends
mm, swap: split the swap memcg charge helpers
mm, swap: do not charge zswap-backed xswap entries
mm, swap: charge an xswap entry when it gets physical backing
mm, swap: don't gate xswap on the physical swap free count
.../admin-guide/cgroup-v1/memcg_test.rst | 2 +-
Documentation/admin-guide/mm/zswap.rst | 12 +
include/linux/memcontrol.h | 6 +
include/linux/swap.h | 74 +-
include/linux/swap_ops.h | 11 +-
include/linux/zswap.h | 15 +-
mm/memcontrol-v1.c | 3 +-
mm/memcontrol.c | 170 +-
mm/memory.c | 25 +-
mm/page_io.c | 119 +-
mm/shmem.c | 2 +-
mm/swap.h | 52 +-
mm/swap_state.c | 9 +
mm/swap_table.h | 92 +-
mm/swapfile.c | 1567 ++++++++++++++---
mm/vmscan.c | 48 +-
mm/zswap.c | 258 ++-
17 files changed, 2008 insertions(+), 457 deletions(-)
--
2.54.0
next reply other threads:[~2026-12-03 18:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:12 Baoquan He [this message]
2026-12-03 18:12 ` [PATCH v2 01/32] mm, swap: prepare the swap IO path for xswap backends Baoquan He
2026-12-03 18:12 ` [PATCH v2 02/32] mm, swap: tag a swap table entry with its owning xswap entry Baoquan He
2026-12-03 18:12 ` [PATCH v2 03/32] mm, swap: prepare the folio-less allocation path for xswap Baoquan He
2026-12-03 18:12 ` [PATCH v2 04/32] mm, swap: add a physical backend for xswap slots Baoquan He
2026-12-03 18:12 ` [PATCH v2 05/32] mm, swap: support swapoff of an xswap physical backend Baoquan He
2026-12-03 18:12 ` [PATCH v2 06/32] mm, swap: use the " Baoquan He
2026-12-03 18:12 ` [PATCH v2 07/32] mm, swap: fall back to disk when zswap refuses an xswap page Baoquan He
2026-12-03 18:12 ` [PATCH v2 08/32] mm, swap: reclaim physical slots backing cache-only xswap entries Baoquan He
2026-12-03 18:12 ` [PATCH v2 09/32] mm, swap: drop swap_folio_sector() Baoquan He
2026-12-03 18:12 ` [PATCH v2 10/32] mm, swap: drop a stale xswap physical slot range before reallocating Baoquan He
2026-12-03 18:12 ` [PATCH v2 11/32] mm, swap: publish the xswap backend owner before its reverse map Baoquan He
2026-12-03 18:12 ` [PATCH v2 12/32] mm, swap: skip a NOFS backend for xswap physical writeback Baoquan He
2026-12-03 18:13 ` [PATCH v2 13/32] mm, swap: pass the folio order through the swap slot allocator Baoquan He
2026-12-03 18:13 ` [PATCH v2 14/32] mm, swap: allocate a multi-slot range without a folio Baoquan He
2026-12-03 18:13 ` [PATCH v2 15/32] mm, swap: pass the folio order to the xswap physical backend Baoquan He
2026-12-03 18:13 ` [PATCH v2 16/32] mm, swap: enable large xswap folios with a contiguous physical slot range Baoquan He
2026-12-03 18:13 ` [PATCH v2 17/32] mm, swap: enable THP swapin for xswap entries Baoquan He
2026-12-03 18:13 ` [PATCH v2 18/32] mm, swap: split the swap memcg charge helpers Baoquan He
2026-12-03 18:13 ` [PATCH v2 19/32] mm, swap: do not charge zswap-backed xswap entries Baoquan He
2026-12-03 18:13 ` [PATCH v2 20/32] mm, swap: charge an xswap entry when it gets physical backing Baoquan He
2026-12-03 18:13 ` [PATCH v2 21/32] mm, swap: don't gate xswap on the physical swap free count Baoquan He
2026-12-03 18:13 ` [PATCH v2 22/32] mm, swap: do not retake the cluster lock when uncharging an xswap slot Baoquan He
2026-12-03 18:13 ` [PATCH v2 23/32] mm, swap: uncharge an xswap backend where its record is cleared Baoquan He
2026-12-03 18:13 ` [PATCH v2 24/32] mm, swap: account xswap backends for cgroup v1 Baoquan He
2026-12-03 18:13 ` [PATCH v2 25/32] mm, swap: drop a refused xswap backend slot range directly Baoquan He
2026-12-03 18:13 ` [PATCH v2 26/32] mm, swap: route xswap by the zswap eligibility without flushing Baoquan He
2026-12-03 18:13 ` [PATCH v2 27/32] mm, swap: keep a per-cluster backend record for every swap device Baoquan He
2026-12-03 18:13 ` [PATCH v2 28/32] mm, swap: encode the per-slot backend record Baoquan He
2026-12-03 18:13 ` [PATCH v2 29/32] mm, swap: add accessors for the " Baoquan He
2026-12-03 18:13 ` [PATCH v2 30/32] mm, zswap: index entries in the swap device's backend table Baoquan He
2026-12-03 18:13 ` [PATCH v2 31/32] mm, swap: release a range of backend handles at once Baoquan He
2026-12-03 18:13 ` [PATCH v2 32/32] mm, swap: only run the xswap backend hooks on xswap devices 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=20261203181319.901844-1-baoquan.he@linux.dev \
--to=baoquan.he@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hebaoquan@kylinos.cn \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@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