Repository navigation
fix(system-optimize): disable zswap through systemd - #58
Merged
Merged
Conversation
added 2 commits
October 24, 2026 01:45
zswap 在多数内核默认开启,旧实现把 kernel.zswap.enabled 写进 sysctl.d 配置,但该键在多数内核不存在,会让整份 sysctl 配置应用失败, zswap 实际仍然开启。 - 新增 linux-setup-disable-zswap.service 与两个 swap drop-in,在 dev-zram0.swap/swap.target 之前把 zswap 运行值写为 0 并回读校验; Wants 语义保证 unit 失败不会取消 swap 启动。 - 每次 install 都 restart 该 unit(active 时 start 不会重跑 ExecStart), 失败后由脚本独立回读实际状态,回读仍为 enabled 时记 degraded。 - 保存 zswap/vm.swappiness/vm.page-cluster 运行快照,恢复时按 stop unit → 恢复文件 → daemon-reload → 恢复运行值的顺序执行。 - 备份/恢复列表从五个文件扩展到八个文件,单个失败不阻断其余文件。 - 配置匹配与设备重建拆分:sysctl、service、drop-in 漂移不再触发 zram stop/start;有交换页时只落配置并记录 pending。 - 状态展示增加 zswap 状态、compressor/zpool/max_pool_percent、 活动压缩算法与 mm_stat 压缩比,分母为 0 时显示 N/A。 - 入口改为 source 守卫(不注册 ERR trap、不执行 main),并加入 LINUX_SETUP_TEST_MODE 下的显式路径覆盖与 fail-closed 校验, 生产路径保持不变。 - 新增 tests/test-system-optimize.sh:假 sysfs、函数桩与 PATH 桩, 不调用真实 systemctl/sysctl/modprobe/apt-get/swapon。
Verify the running zram device (disksize, active algorithm, swap priority) before clearing the pending reconfigure marker; fail closed on config writes, daemon-reload, and post-start verification. Propagate restore errors instead of returning success, distinguish a missing unit from a failed query, and check THP snapshot/config writes. Tighten test path isolation for symlinked leaves and directories, and run the suite against real getters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
write_zram_config()中针对不存在路径/proc/sys/kernel/zswap/enabled的死分支;该分支从未生效,zswap 一直保持开启。linux-setup-disable-zswap.service与dev-zram0.swap、swap.target两个 drop-in,在 swap 激活前写/sys/module/zswap/parameters/enabled。使用Wants而非Requires:关闭失败不阻断 swap 启动。setup_zram()分离「配置已生效」与「设备需重建」;容量、活动算法、swap priority 从运行态读取,只有运行确证匹配才清除zram-reconfigure.pending。show_swap_status()增加 zswap 状态、compressor、活动算法、mm_stat压缩比与实际占用比。source不执行主流程;测试模式只接受显式隔离路径,缺失/逃逸即拒绝加载。Scope
仅
modules/system-optimize.sh与新增tests/test-system-optimize.sh。未修改tests/run.sh、CI、安装器及其他模块。Validation
bash tests/test-system-optimize.sh129 条断言通过;shellcheck -x --severity=warning modules/system-optimize.sh与shellcheck -x --severity=error tests/test-system-optimize.sh通过(shellcheck 0.9.0;CI 版本以流水线为准)。zswap=N,unit active,systemd-analyze verify无输出,dev-zram0.swap的After含该 unit;Finished早于 zram swap 激活;ExecStart;restore initial后两个配置文件与安装前逐字节一致,unit 与 drop-in 删除,zswap 回Y、swappiness 回 60、swap 仍 active。tests/run.sh未在沙箱执行(部分套件依赖 systemd/root),由 CI 覆盖。Risks
swapoff追求排空。ConditionPathExists跳过,这不是「已验证关闭」。Rollback
bash modules/system-optimize.sh restore initial(或previous):先停 unit,再恢复文件与运行值;不执行swapoff,设备容量等待安全重启。