[PATCH v5 00/19] mm/swap: introduce priority queues for swap device allocation

From: Lian Wang

Date: Mon Nov 23 2026 - 09:16:10 EST


Hi all,

This is v5 of Kairui Song's swap priority queue series. Today, choosing
among swap devices of equal priority means rotating a shared plist.
With this series, each CPU advances its own position in a ring of
equal-priority devices. The allocator selects a device before looking for
slots on it. This keeps the existing global swap priorities and does not
add a tier ABI or a per-memcg device-selection policy. Memcg swap
accounting and limits are unchanged.

Thanks to Kairui and Kunwu Chan for reviewing v4. I'm dropping the RFC
tag and submitting the series for review.

Changes since v4:

- Rebased onto mm-unstable at 7d1a16abe4cc (7.4-rc3), retaining the
upstream swap size reporting fix in swap_show() and swapon().
- Following Kairui's review, renamed swap_ring_iterator to
swap_queue_reader_head and ring_only to no_fallback. A large folio
can still try other devices of the same priority after an allocation
failure, but not a lower priority.
- Following Kunwu's review, retained READ_ONCE() in the availability
check, removed a misleading comment about slot reuse, and made both
/proc/swaps iterators check the published swap_file under the read
lock.
- Split the off-list bit fix into patch 10, before the queue conversion.
The plist allocator also needs to mask that bit when checking whether
a swap device is full.
- Revised patch 04 to distinguish all allocated descriptors from
writable devices. drain_mmlist() needs only the usage count and no
longer reads the flags. si_swapinfo() takes one flags snapshot when
accounting for devices being taken offline. I have not carried the
previous Reviewed-by on that patch.

Testing:

I ran Kairui's benchmarks on the 7.4-rc3 base (7d1a16abe4cc) before and
after applying the then-current v5 patches.

On one x86-64 host, both kernels built the same source (4dbe24720eb3)
with make -j96 and eight 8-GiB ZRAM devices. Each build used a fresh
output directory. The BRD test used twelve 8-GiB RAM disks, a 24-GiB
memcg limit and one invocation per kernel:

usemem --init-time -O -y -x -n 32 1536M

Times are in seconds (means for kbuild).

Workload Runs/kernel SYS: Before -> After Wall: Before -> After
kbuild, 2 GiB 12 4193.23 -> 4271.06 167.80 -> 168.80
kbuild, 3 GiB 12 2257.60 -> 2299.63 136.29 -> 136.77
12-BRD 1 141.16 -> 131.44 6.61 -> 6.32

Both kbuild cases used 1.86% more system CPU time; elapsed time rose by
0.60% and 0.35%, respectively. In the single BRD run, throughput
(48 GiB mapped divided by elapsed time) rose from 7436 to 7777 MiB/s
(+4.59%). There was one boot per kernel and the baseline ran first.
The BRD result alone does not establish a repeatable speedup.

v4:
https://lore.kernel.org/all/cover.1794666741.git.lianux.mm@xxxxxxxxx/
v1 and original test method:
https://lore.kernel.org/all/20260714-swap-pcp-priq-v1-0-de9b164ed419@xxxxxxxxxxx/
Related swap tier work:
https://lore.kernel.org/all/20260916183437.2946306-1-youngjun.park@xxxxxxx/

Best regards,
Lian Wang

---

Kairui Song (12):
mm/swap: remove unused parameter for reading swap header
mm/swap: clean up hibernation error handling
mm/swap: cleanup and document swap device availability flag usage
mm/swap: introduce swap device iteration helper
mm/swap: change the swapon lock into a percpu rwsem
mm/swap: serialize swap publication before removing swapon mutex
mm/swap: consolidate swap inuse accounting helpers
mm/swap: add priority queue for swap device allocation
mm/swap: remove available list
mm/swap: bound synchronous discard outside the allocation reader
mm/swap: drop swap active plist
lib/plist.c: remove requeue function

Lian Wang (6):
mm/swap: avoid direct reclaim when populating swap cluster metadata
mm/swap: mask the off-list bit when checking whether swap is full
mm/swap: reuse per-CPU queue readers across priority changes
mm/swap: advance the global queue cursor directly between priority
rings
mm/swap: skip reader rotation for single-device priority rings
mm/swap: redistribute queue readers after membership changes

Youngjun Park (1):
mm/swap: change back to use each swap device's percpu cluster

include/linux/plist.h | 2 -
include/linux/swap.h | 45 +-
lib/plist.c | 71 --
mm/swap.h | 12 +-
mm/swapfile.c | 1446 ++++++++++++++++++++++++++---------------
5 files changed, 963 insertions(+), 613 deletions(-)


base-commit: 7d1a16abe4cc5dccd21e3d6262e44433a5885d27