Set vm.swappiness=100 for zram swap
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run

The optimizer pinned swappiness at 10, which keeps the kernel from
using the 32 GiB zstd zram device. Raise it to 100.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWUvCN36e1dx3Ejii1p
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 14:46:41 +01:00
parent 1c193f78c3
commit 88d8b4454c
4 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,41 @@
{
"intent": "Raise vm.swappiness from 10 to 100 permanently so the kernel uses the 32 GiB zram swap.",
"scope": [
"linux_configuration/fixes/lib/arch_sysctl.sh (owns /etc/sysctl.d/90-desktop-performance.conf)",
"its test arch_sysctl_quarantined_cases.sh and the optimizer header comment",
"non-goal: other sysctl values, zram sizing, arch_perf_probes advice text"
],
"changes": [
"tweak_vm_sysctl: vm.swappiness 10 -> 100 in params map and drop-in",
"Test expectations updated to 100"
],
"verification": [
{
"command": "bash fixes/lib/tests/arch_sysctl_quarantined_cases.sh",
"result": "pass",
"evidence": "RED 18 passed 5 failed with tests at 100 and code at 10; GREEN 23 passed 0 failed after the code change"
},
{
"command": "vm run swp: sysctl -n vm.swappiness before, tweak_vm_sysctl, after guest reboot",
"result": "pass",
"evidence": "60 -> 100 -> 100 after reboot (uptime 39s); guest deleted"
},
{
"command": "sudo -n tweak_vm_sysctl on host; sysctl -n vm.swappiness",
"result": "pass",
"evidence": "100; drop-in has vm.swappiness = 100"
},
{
"command": "fixes/lib/tests/test_*.sh in 4 shards; pre-commit run on touched files",
"result": "pass",
"evidence": "34 test files passed, 0 failed; pre-commit green"
}
],
"risks": [
"More anonymous pages move to zram earlier; a full zram holds about 11 GiB of RAM",
"arch_perf_probes.sh still suggests sysctl vm.swappiness=10 under memory pressure"
],
"rollback": [
"Set vm.swappiness = 10 in /etc/sysctl.d/90-desktop-performance.conf and run sysctl --system"
]
}

View File

@ -13,9 +13,9 @@ tweak_vm_sysctl() {
# by the test harness, which runs un-jailed in ci_mirror.sh and in CI.
local dropin="${SYSCTL_DROPIN_DIR:-/etc/sysctl.d}/90-desktop-performance.conf"
# Desktop workloads: low swappiness, aggressive VFS caching, tuned dirty ratios
# Desktop workloads: high swappiness (zram swap is compressed RAM, see fixes/setup_zram.sh), aggressive VFS caching, tuned dirty ratios
local -A params=(
["vm.swappiness"]="10"
["vm.swappiness"]="100"
["vm.vfs_cache_pressure"]="50"
["vm.dirty_ratio"]="15"
["vm.dirty_background_ratio"]="5"
@ -42,13 +42,13 @@ tweak_vm_sysctl() {
cat >"$dropin" <<'VMEOF'
# Desktop performance tuning — managed by optimize_arch_desktop.sh
#
# vm.swappiness=10 — prefer keeping data in RAM over swapping
# vm.swappiness=100 — favor the 32 GiB zram swap (zstd, prio 100) over dropping page cache
# vm.vfs_cache_pressure=50 — favor keeping inode/dentry caches (speeds up file operations)
# vm.dirty_ratio=15 — allow up to 15% RAM dirty before synchronous writeback
# vm.dirty_background_ratio=5 — start async writeback at 5% dirty
# vm.dirty_writeback_centisecs=1500 — flush dirty pages every 15s (less I/O churn)
# vm.page-cluster=0 — read one page at a time from swap (reduces latency on SSD)
vm.swappiness = 10
vm.swappiness = 100
vm.vfs_cache_pressure = 50
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5

View File

@ -49,7 +49,7 @@ printf '\n-- tweak_vm_sysctl --\n'
_stub_sysctl_tuned() {
_t_stub_stdin sysctl <<'STUB'
case "$2" in
vm.swappiness) echo 10 ;;
vm.swappiness) echo 100 ;;
vm.vfs_cache_pressure) echo 50 ;;
vm.dirty_ratio) echo 15 ;;
vm.dirty_background_ratio) echo 5 ;;
@ -85,7 +85,7 @@ _t_lacks "$(_t_calls)" "sysctl --system" \
arch_desktop_reset
_stub_sysctl_tuned
_t_run tweak_vm_sysctl
_t_contains "$(_t_dropin 90-desktop-performance.conf)" "vm.swappiness = 10" \
_t_contains "$(_t_dropin 90-desktop-performance.conf)" "vm.swappiness = 100" \
"tweak_vm_sysctl: writes the drop-in when it is missing"
_t_lacks "$out" "already tuned" \
"tweak_vm_sysctl: does not report a skip when the drop-in is absent"
@ -100,7 +100,7 @@ esac
STUB
_t_run tweak_vm_sysctl
dropin="$(_t_dropin 90-desktop-performance.conf)"
_t_contains "$dropin" "vm.swappiness = 10" "tweak_vm_sysctl: writes swappiness"
_t_contains "$dropin" "vm.swappiness = 100" "tweak_vm_sysctl: writes swappiness"
_t_contains "$dropin" "vm.vfs_cache_pressure = 50" \
"tweak_vm_sysctl: writes vfs_cache_pressure"
_t_contains "$dropin" "vm.page-cluster = 0" "tweak_vm_sysctl: writes page-cluster"

View File

@ -5,7 +5,7 @@
# Tuning areas:
# 1. CPU scheduler — performance governor on all cores
# 2. I/O scheduler — optimal scheduler per drive type (none for NVMe, mq-deadline for SATA SSD)
# 3. Memory / swap — lower swappiness, tune dirty page writeback for responsiveness
# 3. Memory / swap — high swappiness for zram swap, tune dirty page writeback for responsiveness
# 4. Kernel network — TCP BBR, fastopen, larger buffers
# 5. Filesystem — fstrim timer, noatime advisory
# 6. NVIDIA GPU — max performance level via persistence mode