Skip to content

perf(system-optimize): tune zram sizing and swap policy - #59

Merged
LucaLin233 merged 1 commit into
mainfrom
forge/perf-zram-parameters
Oct 23, 2026
Merged

LucaLin233 merged 1 commit into
mainfrom
forge/perf-zram-parameters

Conversation

@LucaLin233

Copy link
Copy Markdown
Owner

Summary

  • >4 GiB 档容量表达式改为 min(ram / 2, 8192),避免大内存主机按比例生成过大的逻辑 zram。
  • zram-generator 配置显式写入 swap-priority = 100,为将来低优先级磁盘 swap 保留排序契约。
  • 纯 zram 场景 vm.swappiness 统一为 100,不再按内存档位递减。
  • THP defrag 只把 always 转为 defer+madvise;已有 defer/madvise/never 保持不变。
  • 修正 min(ram / 2, 8192) 自带逗号导致的 swappiness 解析错误(${config%,*} / ${config##*,})。

Scope

仅现有参数计算、配置渲染、匹配判据与测试;不新增磁盘 swap、容器限额或 PostgreSQL 参数。本分支基于 forge/fix-zswap-systemd,PR 1 合并后需 rebase 到 main 再合并。

Validation

  • Ubuntu 24.04 x86_64 沙箱:tests/test-system-optimize.sh 175 条断言通过;shellcheck 通过。
  • hkaws(Debian 13):渲染为 ram * 1.5、swap-priority = 100、swappiness = 100;重复 install 幂等(rc=0,不重建设备);restore initial 后 swappiness 回到 60、配置文件与基线一致。
  • 真实 zram-generator 对 min(ram / 2, 8192) 的解析仅在 ≤4 GiB 主机验证了另一分支;>16 GiB 场景未实测。

Risks

  • swappiness 提高会让更多匿名页进入压缩路径,CPU 与缺页延迟可能上升。
  • 容量表达式落盘不等于设备已生效;有交换页时延期到安全重启。
  • 混合磁盘 swap 部署不在本 PR 的适用范围内。

Rollback

恢复安装前配置与运行快照;设备容量/算法/priority 等待安全重启,不强制 swapoff。

Base automatically changed from forge/fix-zswap-systemd to main October 23, 2026 18:46
Cap the large-memory zram expression at 8 GiB, render swap-priority explicitly, unify swappiness at 100 for the pure-zram case, narrow the THP defrag conversion to always, and split the comma-bearing size expression correctly.
@LucaLin233
LucaLin233 force-pushed the forge/perf-zram-parameters branch from ad30e93 to 9c3f66a Compare October 23, 2026 18:48
@LucaLin233
LucaLin233 merged commit 53d9eec into main Oct 23, 2026
9 checks passed
@LucaLin233
LucaLin233 deleted the forge/perf-zram-parameters branch October 23, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant