v6
2026-10-23
实现虚拟交换空间 vswap · v6
vswap 系列引入虚拟交换设备及 zswap、物理交换等后端,评论要求补充磁盘交换性能数据。
原始补丁链接
子 Patch(12)
1/12
mm, swap: add virtual swap device infrastructure
新增 vswap 虚拟交换设备、xarray 动态 cluster 分配器及 vswap= 开关;初始化后启用 static key,设备常驻且暂未接入 swap 分配路径。
2/12
mm, swap: support zswap and zero-filled swap pages as vswap backends
vswap 接入 zswap 与零页后端,zswap_store 失败时保留 swap cache 并暂禁回写/THP swapin;新增 mem_cgroup_can_swap() 并修正 OVERCOMMIT_GUESS 的可用 swap 计算。
3/12
mm, swap: prepare the swap IO path for vswap
将 swap I/O 路径改为使用显式 swap entry:传入 swap_add_folio()/__swap_writeout()/can_merge 并存入 swap_iocb,使 vswap 页按物理 slot 而非 folio->swap 提交 I/O。
4/12
mm, swap: support physical swap as a vswap backend
物理 swap 后端:zswap 拒绝时按需分配物理 slot,并用带 vswap 标记的 swap_table 记录 rmap;swapoff 读失败时丢弃未 uptodate 的 folio,避免写回未初始化数据。
5/12
mm, swap: enable THP swapin for vswap entries
当 vswap 条目在同步 I/O 设备上拥有连续物理 swap slot 时,允许大 anon folio 整体 swapin;zswap/混合后端批次仍拒绝并降阶重试。
6/12
mm, swap: write back vswap zswap entries to physical swap
扩展 zswap 回写路径,使 vswap 的 zswap 条目在回写时按需分配物理 swap slot 并写入,而非依赖 PTE 已固定 slot;仅在物理 swap 耗尽时跳过 vswap 条目。
7/12
mm, swap: reclaim physical slots backing cache-only vswap entries
在物理 swap 使用超过一半(vm_swap_full())时,由物理回收扫描器回收 swap count 已为零但仍在 swap cache 的 vswap 条目所占 slot,释放 swapfile 空间。
8/12
mm, swap: only charge physical swap entries
改为仅在 vswap 条目获得物理 swap 后备时计入 memcg->swap,使 zswap/零页不占 memory.swap.current;并拆分 memcg swap 的 get/charge/put 辅助,回写时才可能限失败。
9/12
mm, swap: add debugfs counters for vswap
新增 /sys/kernel/debug/vswap/ 调试接口,暴露 used(当前已分配虚拟 swap 页数)和 alloc_reject(累计 vswap slot 分配失败页数)两个计数器。
10/12
mm, swap: defer memcg_table allocation for physical swap clusters
Stop allocating a memcg table for every physical swap cluster that only ever holds vswap backings. The table costs SWAPFILE_CLUSTER * sizeof(unsigned short) per cluster, 1 KB per 2 MB of swap on a 64-
11/12
mm, swap: add vmstat and memcg counters for vswap
Add nr_vswap to /proc/vmstat and vswap to cgroup’s memory.stat to report virtual swap usage. These counters help diagnose swapping issues. Userspace can also use vswap as a component of a workload’s
12/12
mm, swap: back vswap clusters with a VM_SPARSE array
vswap keeps its cluster_info in an xarray of individually allocated clusters. Replace it with the VM_SPARSE vmalloc array Baoquan He designed for xswap: one reservation at init, mapped a page of clust