freenode
Kernel & Low-Level

Linux mm series keeps anonymous THPs intact across swap

Usama Arif's 29-patch work adds PMD-level swap entries so huge pages need not split on reclaim, with roughly 4x throughput on a swap-heavy benchmark.

A 29-patch series from Usama Arif aims to stop the kernel from breaking up anonymous transparent huge pages (THPs) when it swaps them out.

Today, reclaim splits a PMD-mapped anonymous THP into hundreds of PTE-level swap entries before unmap. Swap-in then takes that many faults and leaves small mappings until khugepaged collapses the range again. The series introduces a compact PMD-level swap entry that encodes a contiguous run of swap slots, so the huge mapping can survive the round-trip and a new handler can restore the PMD mapping directly on fault.

Swap-map accounting stays per-slot. If the swap cache has split, a slot is in zswap, allocation fails, or the VMA no longer allows PMD-order THPs, the entry splits and falls back to the ordinary PTE path. Native PMD-order zswap load and store is left for follow-up work already underway elsewhere. Consumers are updated before the swap-out path starts installing the new entries.

On vm-scalability's case-swap-w-seq (4 vCPUs, 4 GiB RAM, heavy sequential anonymous write traffic through virtio swap, zswap off, THP always), Arif measured median aggregate throughput rising from 584.3 MiB/s to 2,408.9 MiB/s (about 4.12x), elapsed time down 75.7%, major faults down 87.4%, and swap I/O rate up roughly fourfold. The gains come mainly from far fewer swap faults and less page-table churn while PMD mappings stay intact.

Andrew Morton called the change an inevitable step on the THP path and said leaving reassembly to khugepaged after swap-in "was so lame." He asked for the numbers in the cover letter and wants further review of the core fault handler and swap-out producer before merging. Selftests cover swap-in, fork, COW, mprotect, munmap, UFFDIO_MOVE, madvise, swapoff, and related edges.