New Linux Patches Aim To Better Handle Multiple Swap Devices - Phoronix
Articles & Reviews
News Archive
Forums
Premium Ad-Free<br>Contact
Popular Categories
Close
Articles & Reviews
News Archive
Forums
Premium
Contact
Categories
Computers Display Drivers Graphics Cards Linux Gaming Memory Motherboards Processors Software Storage Operating Systems Peripherals
New Linux Patches Aim To Better Handle Multiple Swap Devices
Written by Michael Larabel in Linux Kernel on 13 July 2026 at 08:38 PM EDT. 8 Comments
For those having Linux systems with multiple swap devices, such as for swap tiering or layered swap handling, a set of patches posted today for the Linux kernel are looking to improve the situation.
While most Phoronix readers are likely not leveraging multiple swap devices, for those with more complex Linux server deployments there is a new and interesting patch series out of Tencent. Kairui Song has been leading the effort to better distribute I/O to multiple swap devices and address multiple outstanding design issues in the process with the Linux swap handling.
Song noted in today's request for comments (RFC) patch series:<br>"This series introduces a new way to fairly distribute the IO to multiple swap devices, completely gets rid of the mutable plist and global lock, hence removes the global cluster cache and allows allocation and rotation to happen more freely. This is especially helpful for swap tiering or layered swap. Sending as RFC for review first as tiering should land first, this can rebase and join later as an optimization, and there are a few items that can still be improved based on this series. I specifically kept the tiering and layered ideas in mind to make the new design friendly for new ideas like these and tested a few different appraoches locally.
As a dependency, this also cleanup and rework the locking pattern for swap device management. All swap devices and the newly introduced percpu reader priority queue are now guarded by a percpu rwsem for better scalability and a more future-proof design.
Previously, each swap device had its own percpu cluster cache. To improve performance, commit 1b7e90020eb7 ("mm, swap: use percpu cluster as allocation fast path") moved the cluster cache to a global scope and let every device share the same global cache, so we don't need to always touch the plist. Fast swap allocation will just use each CPU's cluster cache. Device rotation is still always handled by the plist when one cluster is drained in the cluster cache, which bundled cluster allocation with rotation. It works, but this whole design caused several long-standing issues:
1) The global percpu cluster cache sitting above device selection fundamentally conflicts with concepts like swap tiering and layered swap allocation. We need to bypass certain swap devices, so we have to bypass the cache as well because the cache doesn't have stable ownership. That would result in very poor performance. And there are other problems like priority inversion and device rotation. These are described in more detail in the swap tier series.
2) The plist itself requires plist_requeue() to rotate devices for round-robin, which needs swap_avail_lock held. Allocators must cycle: lock -> pick -> unlock -> allocate -> lock -> rotate. All CPUs contend on the same global list head, and the design is neither flexible nor robust.
3) Rotation is considered the slow path. The fast / slow path design to avoid touching the plist has caused workarounds like commit 9fb749cd15078 ("mm, swap: do not perform synchronous discard during allocation"), we can't stably grab an actual device before touching the plist, so the design is suboptimal and has many constraints.
4) We don't have a clear rule of how rotation works. The round-robin rotation is strongly bundled to the cluster allocation algorithm, and cluster drain is unpredictable. We will have a roughly 2M rotation block size but that varies from time to time.
This series gets rid of all these issues step by step."
Those wanting to learn more about improving the multi SWAP device handling for Linux cam see the patches for this promising work.
8 Comments
Tweet
Reworked System Call Entry Handling Slated For Linux 7.3<br>Linux 7.2-rc3 Released: Close To The "New Normal"<br>Linux 7.2-rc3 Bringing Display Detection Improvement To Help Some Multi-GPU Systems<br>Proposed Linux Patch For A Brief Delay To Match PCI Spec Will Hopefully Address Some Bugs<br>Linux 7.3 To Make It Easier To Disable Syscall User Dispatch<br>Linux 7.3 Expected To "Flatten The Pick" For Better Scheduling While Gaming & More
Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and...