The fourth iteration of patches implementing Virtual Swap Space for Linux were sent out on Wednesday. This stems from ideas going back years for an abstraction to better separate a swap entry from its physical backing storage.
Nhat Pham sent out the Virtual Swap Space v4 patches yesterday and explained for those not following the previous iterations of the patches:
“We need an abstraction that separates a swap entry from its physical backing storage. [In other words], we need to “virtualize” the swap space: swap clients will work with a dynamically allocated virtual swap slot, storing it in page table entries, and using it to index into various swap-related data structures. The backing storage is decoupled from the virtual swap slot, and the newly introduced layer will “resolve” the virtual swap slot to the actual storage. This layer also manages other metadata of the swap entry, such as its lifetime information (swap count), via a dynamically allocated, per-swap-entry descriptor…This design allows us to:
* Decouple zswap (and zeromapped swap entry) from backing swapfile: simply associate the virtual swap slot with one of the supported backends: a zswap entry, a zero-filled swap page, a slot on the swapfile, or an in-memory page.
* Simplify and optimize swapoff: we only have to fault the page in and have the virtual swap slot points to the page instead of the on-disk physical swap slot. No need to perform any page table walking.”
At 0~40% usage the virtual swap overhead ends up being less than the current overhead. At higher usage levels, the overhead can be greater but ultimately just a sub-1% portion of the overall swap file. The performance was found to be competitive with the Virtual Swap Space usage compared to the current swap code.
The Virtual Swap Space could also lead to other features moving forward like multi-tier swapping, swapfile compaction, Zswap writeback optimization, and more.
Those wishing to learn more about this Virtual Swap Space work can do so via this patch series.
