背景

vm.defrag_mode=1 是一种碎片化避免策略:non-movable 分配只从 non-movable pageblock 中取,不侵占 movable block 的空间,从而保护大块连续 movable 区域留给 THP 等大页分配。当系统碎片化严重时,non-movable pageblock 耗尽,non-movable 请求进入 allocator slowpath。

Meta 在生产部署 defrag_mode=1 后,部分工作负载出现 recurring pressure spikes 与 swap storms,并触发基于 pressure 加 swap utilization 的 userspace OOM 规则;tracing 定位到 non-movable 请求在 kswapd/kcompactd 过载时空转,做无产出的 direct reclaim。

┌────────────────────────────────────┐
│ non-movable 只用 non-movable block │
└─────────────────┬──────────────────┘
                  ▼
┌────────────────────────────────────┐
│   direct reclaim 释放 movable 页   │
└─────────────────┬──────────────────┘
                  ▼
┌────────────────────────────────────┐
│       non-movable 请求用不上       │
└─────────────────┬──────────────────┘
                  ▼
┌────────────────────────────────────┐
│       空转触发 reclaim storm       │  swap storm 与 OOM
└────────────────────────────────────┘

问题

  • defrag_mode 下 non-movable 请求只能用 non-movable pageblock。
  • direct reclaim 主要释放 movable 页,non-movable 请求不能用。
  • 极少能整块释放出 non-movable 请求可用的 pageblock。
  • non-movable 请求在无产出的 reclaim 中空转,引发 reclaim storm 与 swap storm,触发 userspace OOM。

方案

让 non-movable 请求在 allocator slowpath 参与 pageblock production:以 pageblock_order 主动发起 direct reclaim 与 direct compaction,生产自己需要的 non-movable pageblock,而不是被动触发释放自己用不上的 movable 页。

┌────────────────────────────────┐
│    non-movable 进 slowpath     │
└───────────────┬────────────────┘
                ▼
┌────────────────────────────────┐
│      参与 pageblock 生产       │
└───────────────┬────────────────┘
                ▼
┌────────────────────────────────┐
│ 主动 compaction 生产所需 block │  以 pageblock_order 发起
└───────────────┬────────────────┘
                ▼
┌────────────────────────────────┐
│      不再空转 storm 消除       │
└────────────────────────────────┘

这需要 allocator 与 compaction 先做配套调整:让 compaction 能为 non-movable 请求生产 pageblock,并把 pageblock 的捕获控制(capture control)交由 allocator 拥有并武装,compaction 只负责把它指向正在 compact 的 zone。这些铺好之后,核心改动(让 non-movable 请求在 slowpath 参与 pageblock production)才得以落地。

收益

作者未提供量化 benchmark,以下为基于机制与 Meta 生产报告的预期收益:

  • non-movable 请求不再在无产出的 direct reclaim 中空转。
  • reclaim storm 与 swap storm 消除,不再触发 userspace OOM 规则。
  • non-movable 请求主动生产需要的 non-movable pageblock(compaction 替代无产出 reclaim)。
  • Meta 生产验证:已在受影响工作负载上运行数周,OOM kill rate 恢复到 !defrag_mode baseline。