diff --git a/docs/superpowers/contracts/journal-cap-4g-2026-09-13.json b/docs/superpowers/contracts/journal-cap-4g-2026-09-13.json deleted file mode 100644 index 03da8e12..00000000 --- a/docs/superpowers/contracts/journal-cap-4g-2026-09-13.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "title": "Arch journal cap 300M -> 4G, vacuum only past the cap", - "objective": "The systemd journal keeps weeks of history on kuhy's desktop, not days: a 300M cap held about two days once one Steam boot wrote 480k lines, and the evidence for a curfew failure was gone when it was needed. Every Arch copy of the journal tweak installs a 4G cap and treats 'large' as past that cap.", - "acceptance_criteria": [ - "fix_arch_performance.sh, optimize_arch_desktop.sh and the perf report write SystemMaxUse=4G and vacuum to 4G only when usage is >= 4G", - "a journal measured in megabytes, or under 4G, is neither vacuumed nor reported as large", - "test_arch_hardware_boot.sh, test_arch_perf_fixes.sh, test_arch_perf_report_fixes.sh and test_arch_perf_report.sh pass unchanged in count" - ], - "out_of_scope": [ - "the Ubuntu copy of the same fix (ubuntu_perf_more.sh) -- not this machine", - "rate-limiting the Steam flood itself -- fixed at source in steam-backlog-enforcer" - ], - "verifier": "bash linux_configuration/fixes/lib/tests/test_arch_hardware_boot.sh; bash linux_configuration/fixes/lib/tests/test_arch_perf_fixes.sh; bash linux_configuration/fixes/lib/tests/test_arch_perf_report_fixes.sh; bash linux_configuration/fixes/lib/tests/test_arch_perf_report.sh" -} diff --git a/docs/superpowers/contracts/swap-bench-desktop-gate-2026-11-27.json b/docs/superpowers/contracts/swap-bench-desktop-gate-2026-11-27.json new file mode 100644 index 00000000..dd073bb5 --- /dev/null +++ b/docs/superpowers/contracts/swap-bench-desktop-gate-2026-11-27.json @@ -0,0 +1,14 @@ +{ + "title": "swap_bench host desktop gate and outside-scope swap column", + "objective": "Fix the C6 live-check failure: the host bench judged the desktop by global PSI (which counts the bench scope itself) and claimed only the scope swaps. Measure the desktop by the login sessions' own stall, gate on it, record other processes' swap-outs, and correct the DOCS.", + "acceptance_criteria": [ + "A host run whose login sessions stalled over SWAP_BENCH_MAX_DESKTOP_MS (default 1000) records its row and exits 3 naming the stall", + "Host rows carry outside_pswpout = global pswpout delta minus the scope's own; VM rows carry na", + "The misleading global avg10 before/after lines are gone", + "DOCS-zswap-vs-zram.md shows the re-measured desktop check against an idle baseline and no longer claims zram wrote nothing to disk or that the scope keeps the desktop out of swap" + ], + "out_of_scope": [ + "The A/B winner (PSI full, then major faults) and its 12 committed rows" + ], + "verifier": "test_swap_bench.sh 30/30, pytest python_pkg/swap_bench 31 passed at 100% branch, three live zram host runs exit 0 with desktop stall 6-39 ms and outside_pswpout 153k-224k vs 111k idle." +} diff --git a/docs/superpowers/evidence/swap-bench-desktop-gate-2026-11-27.json b/docs/superpowers/evidence/swap-bench-desktop-gate-2026-11-27.json new file mode 100644 index 00000000..dc65513d --- /dev/null +++ b/docs/superpowers/evidence/swap-bench-desktop-gate-2026-11-27.json @@ -0,0 +1,37 @@ +{ + "intent": "Fix the C6 live-check failure of the zswap/zram A/B: the host bench's desktop check used global PSI, which counts the bench scope's own stall, and the DOCS claimed the scope keeps the desktop out of swap and that zram wrote nothing to disk.", + "scope": [ + "python_pkg/swap_bench: outside_pswpout column, row --max-desktop-ms gate", + "linux_configuration/fixes/swap_bench.sh: passes the 1 s desktop limit on host runs, drops the global avg10 lines", + "DOCS-zswap-vs-zram.md and swap-bench-results.tsv: corrected claims, desktop check table, new column (na for the A/B rows)", + "Non-goal: the winner and the A/B rows" + ], + "changes": [ + "Root cause 1: global PSI full counts moments when every busy task is stalled, which the scope causes alone; global minus scope came out negative (-685 ms), so no global PSI figure measures the desktop. The gate now reads the login session scopes' full stall", + "Root cause 2: zram's pool is not charged to the bench scope, so global reclaim also swaps other processes; the run now records outside_pswpout", + "Root cause 3: disk_wb_pages is system-wide; an idle 28 s had 20k pages of pswpout not taken by zram, the same range as the runs, so nonzero values on the host are background" + ], + "verification": [ + { + "command": "linux_configuration/fixes/lib/tests/test_swap_bench.sh", + "result": "pass", + "evidence": "30 passed; before the shell change the new gate cases failed (exit 0 instead of 3, no stall message)" + }, + { + "command": "python3 -m pytest python_pkg/swap_bench --cov=python_pkg.swap_bench --cov-branch", + "result": "pass", + "evidence": "31 passed, 100% branch; new column and gate tests failed before the implementation" + }, + { + "command": "SWAP_BENCH_SYSTEMD_RUN=/usr/bin/systemd-run SWAP_BENCH_RESULTS= swap_bench.sh run host (x3, zram)", + "result": "pass", + "evidence": "exit 0 each; desktop_full_ms 39, 6, 7; outside_pswpout 213501, 153179, 224178 vs 110829 over an idle 28 s; disk_wb_pages 14958, 9058, 14145 vs 20048 idle" + } + ], + "risks": [ + "The 1 s desktop limit is set from a 4 ms idle baseline and 6-237 ms runs; a busy desktop during a run fails it, which is the intent" + ], + "rollback": [ + "git revert the commit; swap_bench.sh returns to printing global avg10 with no gate" + ] +} diff --git a/linux_configuration/fixes/DOCS-zswap-vs-zram.md b/linux_configuration/fixes/DOCS-zswap-vs-zram.md index ccd40dbc..59095bea 100644 --- a/linux_configuration/fixes/DOCS-zswap-vs-zram.md +++ b/linux_configuration/fixes/DOCS-zswap-vs-zram.md @@ -60,8 +60,9 @@ medians and the winner. Every run stays under 60 s. `MemoryMax=4G`, `MemorySwapMax=infinity`, `RuntimeMaxSec=55`. Only the scope is pressed; PSI, zswap counters and writeback come from the scope's own `memory.pressure` and `memory.stat`. A host run refuses to start - when MemAvailable is below the 4 GiB cap plus 2 GiB, so the bench cannot - push the desktop into swap. (8 GiB took 37-45 s on zram with other jobs + when MemAvailable is below the 4 GiB cap plus 2 GiB. It fails (exit 3, + row kept) when the login sessions stalled more than 1 s during the run + (`SWAP_BENCH_MAX_DESKTOP_MS`). (8 GiB took 37-45 s on zram with other jobs running; zswap is slower, so 6 GiB keeps every run inside the 50 s limit.) - **VM.** 4.5 GiB in a 3.9 GiB guest (8 GiB swapfile), no scope: the whole guest is pressed and global counters are used. @@ -69,9 +70,15 @@ medians and the winner. Every run stays under 60 s. `mm_stat` deltas at peak; zswap `zswapped/zswap` at peak). `psi_*_ms`: memory stall time over the run. `majflt`: the workload's own major faults. `disk_wb_pages`: pages written to disk swap, Δ`pswpout` minus Δ zram - writes (zram is a swap device, so `pswpout` counts it too). `zswpwb`: - zswap's writebacks. `desktop_full_ms` (host): full stall of the login - session scopes, i.e. the desktop, during the run. + writes (zram is a swap device, so `pswpout` counts it too). It is + system-wide, so on the host it includes other processes (see the C6 + check below). `zswpwb`: zswap's writebacks. `desktop_full_ms` (host): full + stall of the login session scopes, i.e. the desktop, during the run. + `outside_pswpout` (host, added after the A/B rows): global Δ`pswpout` + minus the scope's own `pswpout`, the pages every other process swapped + out during the run. `global_full_avg10`: global PSI full after the run; + it counts the bench scope's own stall, so it does not measure the + desktop. - **Winner rule** (kuhy, 2026-11-27). Lower median PSI full wins; major faults break a tie; a difference under 10 % (the run-to-run noise) is a tie, and a tie on both keeps zram. @@ -108,31 +115,61 @@ because other board jobs (gradle, an emulator, ollama) ran during the runs: zram 5546-8223 ms, zswap 5490-11684 ms. Major faults point the same way (-21 %). zswap wrote 1.3-2.3 GB of this run's pages back to disk per run (`zswpwb` 331649-586700 pages), because its pool counts against the scope's -4 GiB. zram wrote nothing to disk. zram's ratio reads lower (2.8 vs 3.2) +4 GiB. zram's three A/B runs recorded no disk writeback. zram's ratio reads lower (2.8 vs 3.2) only because `mm_stat` is device-wide, so other processes swapping during the run dilute it. zswap's ratio comes from the scope's own counters. -The desktop was not pressed (C6). The login session scopes (i3 and -everything it started) stalled for 0-29 ms per run (`desktop_full_ms`), -against 8 ms over an idle 37 s measured the same way. Global PSI rises -during a run only because global PSI counts the bench scope's own stalls. +### Desktop check on the host (C6, zram, re-measured in the fix stage) + +The bench scope caps the bench's RAM, but it does not keep the rest of the +host out of swap. Three zram runs with the `outside_pswpout` column, +against an idle 28 s measured the same way with no bench running: + +| interval | seconds | desktop full stall ms | other processes' pswpout | pswpout not taken by zram | +| -------- | ------- | --------------------- | ------------------------ | ------------------------- | +| idle | 28 | 4 | 110829 | 20048 | +| run 1 | 27.6 | 39 | 213501 | 14958 | +| run 2 | 26.1 | 6 | 153179 | 9058 | +| run 3 | 30.5 | 7 | 224178 | 14145 | + +- **The desktop was not stalled.** The login sessions (i3 and everything it + started) stalled 6-39 ms per run, under the 1 s limit the bench now + enforces. Global PSI full rose during the runs (avg10 6.4-11.7 after + them), but global `full` counts the moments every busy task on the host is + stalled, which the bench scope causes by itself. It is not a desktop + measure, so the bench no longer prints it. +- **Other processes do swap during a zram run.** They swapped out + 153k-224k pages per run against 111k over the idle interval, so the run + adds roughly 40k-110k pages (0.2-0.4 GB). zram's pool is not charged to the + bench scope: zram grows in global RAM, and global reclaim then takes pages + from other processes too. zswap's pool is charged to the scope, so a zswap + run does not do this; the host A/B numbers favour zram for the same reason + as the known bias above. The VM result, pressed system-wide, still picks + zram. +- **`disk_wb_pages` on a zram host run is background.** The idle interval + had 20k pages of `pswpout` that zram did not take, the same range as the + runs (9k-15k), so it is not the bench's. The swapfiles' Used did not grow + in any interval. That fits other processes writing pages back into + swapfile slots they still hold from the zswap test (about 17 GB of slots, + see the switch log), but it was not traced per device. The three A/B zram + rows were taken before the zswap test, and read 0. ### Raw rows ```tsv -date env setup seed size_mib pages fill_crc touch_crc seconds ratio psi_some_ms psi_full_ms majflt disk_wb_pages zswpwb global_full_avg10 desktop_full_ms -2026-11-27T10:59:54Z vm zram 20261127 4608 1179648 531769134 2573270970 18.928 3.21 5996 5996 127223 0 0 34.56 na -2026-11-27T11:00:14Z vm zram 20261127 4608 1179648 531769134 2573270970 13.248 3.21 5782 5782 124816 0 0 39.31 na -2026-11-27T11:00:35Z vm zram 20261127 4608 1179648 531769134 2573270970 13.393 3.21 6118 6118 124559 0 0 43.00 na -2026-11-27T11:02:00Z vm zswap 20261127 4608 1179648 531769134 2573270970 28.698 3.15 10366 10360 147757 92 92 38.06 na -2026-11-27T11:02:29Z vm zswap 20261127 4608 1179648 531769134 2573270970 20.711 3.16 8833 8832 210005 128 128 40.12 na -2026-11-27T11:03:04Z vm zswap 20261127 4608 1179648 531769134 2573270970 27.756 3.18 12828 12826 127486 0 0 52.34 na -2026-11-27T11:16:58Z host zram 20261127 6144 1572864 2708526455 3876889511 24.548 2.83 5546 5546 177006 0 0 4.65 14 -2026-11-27T11:17:33Z host zram 20261127 6144 1572864 2708526455 3876889511 30.586 2.82 8223 8223 168862 0 0 4.21 1 -2026-11-27T11:18:05Z host zram 20261127 6144 1572864 2708526455 3876889511 29.029 3.18 7427 7427 172634 0 0 4.97 0 -2026-11-27T11:20:54Z host zswap 20261127 6144 1572864 2708526455 3876889511 49.381 3.21 11684 11684 218408 617001 586700 3.06 6 -2026-11-27T11:21:45Z host zswap 20261127 6144 1572864 2708526455 3876889511 45.383 3.21 8973 8973 208093 584944 453067 9.56 29 -2026-11-27T11:22:25Z host zswap 20261127 6144 1572864 2708526455 3876889511 35.541 3.21 5490 5490 223518 835213 331649 7.50 13 +date env setup seed size_mib pages fill_crc touch_crc seconds ratio psi_some_ms psi_full_ms majflt disk_wb_pages zswpwb global_full_avg10 desktop_full_ms outside_pswpout +2026-11-27T10:59:54Z vm zram 20261127 4608 1179648 531769134 2573270970 18.928 3.21 5996 5996 127223 0 0 34.56 na na +2026-11-27T11:00:14Z vm zram 20261127 4608 1179648 531769134 2573270970 13.248 3.21 5782 5782 124816 0 0 39.31 na na +2026-11-27T11:00:35Z vm zram 20261127 4608 1179648 531769134 2573270970 13.393 3.21 6118 6118 124559 0 0 43.00 na na +2026-11-27T11:02:00Z vm zswap 20261127 4608 1179648 531769134 2573270970 28.698 3.15 10366 10360 147757 92 92 38.06 na na +2026-11-27T11:02:29Z vm zswap 20261127 4608 1179648 531769134 2573270970 20.711 3.16 8833 8832 210005 128 128 40.12 na na +2026-11-27T11:03:04Z vm zswap 20261127 4608 1179648 531769134 2573270970 27.756 3.18 12828 12826 127486 0 0 52.34 na na +2026-11-27T11:16:58Z host zram 20261127 6144 1572864 2708526455 3876889511 24.548 2.83 5546 5546 177006 0 0 4.65 14 na +2026-11-27T11:17:33Z host zram 20261127 6144 1572864 2708526455 3876889511 30.586 2.82 8223 8223 168862 0 0 4.21 1 na +2026-11-27T11:18:05Z host zram 20261127 6144 1572864 2708526455 3876889511 29.029 3.18 7427 7427 172634 0 0 4.97 0 na +2026-11-27T11:20:54Z host zswap 20261127 6144 1572864 2708526455 3876889511 49.381 3.21 11684 11684 218408 617001 586700 3.06 6 na +2026-11-27T11:21:45Z host zswap 20261127 6144 1572864 2708526455 3876889511 45.383 3.21 8973 8973 208093 584944 453067 9.56 29 na +2026-11-27T11:22:25Z host zswap 20261127 6144 1572864 2708526455 3876889511 35.541 3.21 5490 5490 223518 835213 331649 7.50 13 na ``` ## Host switch log diff --git a/linux_configuration/fixes/lib/tests/test_swap_bench.sh b/linux_configuration/fixes/lib/tests/test_swap_bench.sh index 6fbf2c72..43dab167 100755 --- a/linux_configuration/fixes/lib/tests/test_swap_bench.sh +++ b/linux_configuration/fixes/lib/tests/test_swap_bench.sh @@ -35,10 +35,15 @@ printf '0::/bench.scope\n' >"$PROC_SELF_CGROUP" printf '1 0 0 0 1 0 80 0 0 0 0\n' >"${ZRAM_SYSFS}/stat" printf '4096 1024 0 0\n' >"${ZRAM_SYSFS}/mm_stat" +# BUMP_DESKTOP_FULL_US: stall the login session by this much during the run. _t_stub_stdin systemd-run <<'STUB' while [[ $1 != -- ]]; do shift; done shift -exec "$@" +"$@" || exit $? +if [[ -n ${BUMP_DESKTOP_FULL_US:-} ]]; then + printf 'some avg10=0.00 avg60=0.00 avg300=0.00 total=5000\nfull avg10=0.00 avg60=0.00 avg300=0.00 total=%s\n' \ + "$((2000 + BUMP_DESKTOP_FULL_US))" >"${CGROUP_ROOT}/user.slice/user-1000.slice/session-1.scope/memory.pressure" +fi STUB _t_stub_cat swapon swaps _setup() { # _setup zram|zswap|none|both @@ -60,7 +65,16 @@ _t_contains "$(_t_calls)" "MemorySwapMax=infinity" "run host: scope may swap" _t_contains "$(_t_calls)" "RuntimeMaxSec=55" "run host: scope dies before the 60 s cap" _t_eq "zram" "$(_col setup)" "run host: row records the zram setup" _t_eq "host" "$(_col env)" "run host: row records env" -_t_contains "$out" "global memory PSI full avg10" "run host: prints the global PSI" +_t_eq 0 "$(_col outside_pswpout)" "run host: records other processes' swap-outs" + +echo "host run that stalls the desktop fails loudly (C6)" +rows_before=$(wc -l <"$SWAP_BENCH_RESULTS") +BUMP_DESKTOP_FULL_US=2000000 _t_run bash "$BENCH" run host --seed 7 --size-mib 1 +_t_eq 3 "$?" "pressed desktop: exits 3" +_t_contains "$out" "the login sessions stalled 2000 ms (limit 1000 ms)" "pressed desktop: names the stall" +_t_eq "$((rows_before + 1))" "$(wc -l <"$SWAP_BENCH_RESULTS")" "pressed desktop: the row is still recorded" +sed -i '$d' "$SWAP_BENCH_RESULTS" +printf '%s\n' "$psi" >"${CGROUP_ROOT}/user.slice/user-1000.slice/session-1.scope/memory.pressure" _t_eq 0 "$(_col desktop_full_ms)" "run host: records the session scopes' PSI stall" echo "same seed, same workload (C7)" diff --git a/linux_configuration/fixes/swap-bench-results.tsv b/linux_configuration/fixes/swap-bench-results.tsv index c7d1ced8..9cfaf594 100644 --- a/linux_configuration/fixes/swap-bench-results.tsv +++ b/linux_configuration/fixes/swap-bench-results.tsv @@ -1,13 +1,13 @@ -date env setup seed size_mib pages fill_crc touch_crc seconds ratio psi_some_ms psi_full_ms majflt disk_wb_pages zswpwb global_full_avg10 desktop_full_ms -2026-11-27T10:59:54Z vm zram 20261127 4608 1179648 531769134 2573270970 18.928 3.21 5996 5996 127223 0 0 34.56 na -2026-11-27T11:00:14Z vm zram 20261127 4608 1179648 531769134 2573270970 13.248 3.21 5782 5782 124816 0 0 39.31 na -2026-11-27T11:00:35Z vm zram 20261127 4608 1179648 531769134 2573270970 13.393 3.21 6118 6118 124559 0 0 43.00 na -2026-11-27T11:02:00Z vm zswap 20261127 4608 1179648 531769134 2573270970 28.698 3.15 10366 10360 147757 92 92 38.06 na -2026-11-27T11:02:29Z vm zswap 20261127 4608 1179648 531769134 2573270970 20.711 3.16 8833 8832 210005 128 128 40.12 na -2026-11-27T11:03:04Z vm zswap 20261127 4608 1179648 531769134 2573270970 27.756 3.18 12828 12826 127486 0 0 52.34 na -2026-11-27T11:16:58Z host zram 20261127 6144 1572864 2708526455 3876889511 24.548 2.83 5546 5546 177006 0 0 4.65 14 -2026-11-27T11:17:33Z host zram 20261127 6144 1572864 2708526455 3876889511 30.586 2.82 8223 8223 168862 0 0 4.21 1 -2026-11-27T11:18:05Z host zram 20261127 6144 1572864 2708526455 3876889511 29.029 3.18 7427 7427 172634 0 0 4.97 0 -2026-11-27T11:20:54Z host zswap 20261127 6144 1572864 2708526455 3876889511 49.381 3.21 11684 11684 218408 617001 586700 3.06 6 -2026-11-27T11:21:45Z host zswap 20261127 6144 1572864 2708526455 3876889511 45.383 3.21 8973 8973 208093 584944 453067 9.56 29 -2026-11-27T11:22:25Z host zswap 20261127 6144 1572864 2708526455 3876889511 35.541 3.21 5490 5490 223518 835213 331649 7.50 13 +date env setup seed size_mib pages fill_crc touch_crc seconds ratio psi_some_ms psi_full_ms majflt disk_wb_pages zswpwb global_full_avg10 desktop_full_ms outside_pswpout +2026-11-27T10:59:54Z vm zram 20261127 4608 1179648 531769134 2573270970 18.928 3.21 5996 5996 127223 0 0 34.56 na na +2026-11-27T11:00:14Z vm zram 20261127 4608 1179648 531769134 2573270970 13.248 3.21 5782 5782 124816 0 0 39.31 na na +2026-11-27T11:00:35Z vm zram 20261127 4608 1179648 531769134 2573270970 13.393 3.21 6118 6118 124559 0 0 43.00 na na +2026-11-27T11:02:00Z vm zswap 20261127 4608 1179648 531769134 2573270970 28.698 3.15 10366 10360 147757 92 92 38.06 na na +2026-11-27T11:02:29Z vm zswap 20261127 4608 1179648 531769134 2573270970 20.711 3.16 8833 8832 210005 128 128 40.12 na na +2026-11-27T11:03:04Z vm zswap 20261127 4608 1179648 531769134 2573270970 27.756 3.18 12828 12826 127486 0 0 52.34 na na +2026-11-27T11:16:58Z host zram 20261127 6144 1572864 2708526455 3876889511 24.548 2.83 5546 5546 177006 0 0 4.65 14 na +2026-11-27T11:17:33Z host zram 20261127 6144 1572864 2708526455 3876889511 30.586 2.82 8223 8223 168862 0 0 4.21 1 na +2026-11-27T11:18:05Z host zram 20261127 6144 1572864 2708526455 3876889511 29.029 3.18 7427 7427 172634 0 0 4.97 0 na +2026-11-27T11:20:54Z host zswap 20261127 6144 1572864 2708526455 3876889511 49.381 3.21 11684 11684 218408 617001 586700 3.06 6 na +2026-11-27T11:21:45Z host zswap 20261127 6144 1572864 2708526455 3876889511 45.383 3.21 8973 8973 208093 584944 453067 9.56 29 na +2026-11-27T11:22:25Z host zswap 20261127 6144 1572864 2708526455 3876889511 35.541 3.21 5490 5490 223518 835213 331649 7.50 13 na diff --git a/linux_configuration/fixes/swap_bench.sh b/linux_configuration/fixes/swap_bench.sh index 4144b437..1731f307 100755 --- a/linux_configuration/fixes/swap_bench.sh +++ b/linux_configuration/fixes/swap_bench.sh @@ -7,8 +7,10 @@ # # One run per call, each under 60 s, appending one row to the results TSV. # Host mode confines the pressure to a transient scope (RAM capped, swap -# allowed), so only the bench swaps and the desktop keeps its memory; its -# PSI and zswap counters are the scope's own. VM mode puts the whole guest +# allowed); its PSI and zswap counters are the scope's own. The scope does +# not shield other processes from global reclaim (zram's pool is not charged +# to it), so a host run records their swap-outs and fails when the login +# sessions stall. VM mode puts the whole guest # under pressure and uses global counters. A run that fails or times out # records nothing. The Python side (python_pkg/swap_bench) holds the # workload, the parsing and the winner rule; this script only places it. @@ -27,6 +29,10 @@ readonly CGROUP_ROOT="${CGROUP_ROOT:-/sys/fs/cgroup}" readonly ZRAM_SYSFS="${ZRAM_SYSFS:-/sys/block/zram0}" readonly ZSWAP_PARAMS_DIR="${ZSWAP_PARAMS_DIR:-/sys/module/zswap/parameters}" readonly HOST_MEMORY_MAX="${SWAP_BENCH_MEMORY_MAX:-4G}" +# A host run fails (exit 3, row kept) when the login session scopes (i3 and +# what it started) stalled longer than this. Global PSI cannot tell: it +# counts the bench scope's own stall. +readonly MAX_DESKTOP_MS="${SWAP_BENCH_MAX_DESKTOP_MS:-1000}" # A wrapper on PATH may add properties a scope refuses (Nice=); point this at # /usr/bin/systemd-run to bypass it. readonly SYSTEMD_RUN="${SWAP_BENCH_SYSTEMD_RUN:-systemd-run}" @@ -81,8 +87,6 @@ host_has_room() { ((avail_kib >= cap_kib + 2 * 1024 * 1024)) } -global_full_avg10() { awk '/^full/ {sub("avg10=", "", $2); print $2}' "$PROC_PRESSURE"; } - # inner DIR ENV SIZE SEED — runs inside the scope (host) or the guest (vm). inner() { local dir="$1" env="$2" size="$3" seed="$4" cg @@ -118,7 +122,6 @@ cmd_run() { dir="$(mktemp -d)" RUN_DIR="$dir" # global: the EXIT trap runs after this function's locals are gone trap 'rm -rf "${RUN_DIR:?}"' EXIT - echo "global memory PSI full avg10 before: $(global_full_avg10)" snap "${dir}/before" if [[ $env == host ]]; then "$SYSTEMD_RUN" --user --scope --quiet --unit="swap-bench-$$" \ @@ -129,11 +132,11 @@ cmd_run() { fi ((rc == 0)) || die "workload failed (exit $rc): no row recorded" snap "${dir}/after" - echo "global memory PSI full avg10 after: $(global_full_avg10)" - local -a header=() + local -a header=() gate=() [[ -s $RESULTS ]] || header=(--header) + [[ $env == vm ]] || gate=(--max-desktop-ms "$MAX_DESKTOP_MS") py row --dir "$dir" --env "$env" --setup "$setup" --seed "$seed" --size-mib "$size" \ - --date "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "${header[@]}" | tee -a "$RESULTS" + --date "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "${header[@]}" "${gate[@]}" | tee -a "$RESULTS" } main() { diff --git a/python_pkg/swap_bench/cli.py b/python_pkg/swap_bench/cli.py index e6485a1b..48f4b2ff 100644 --- a/python_pkg/swap_bench/cli.py +++ b/python_pkg/swap_bench/cli.py @@ -36,6 +36,11 @@ def _parser() -> argparse.ArgumentParser: p_row.add_argument("--size-mib", type=int, required=True) p_row.add_argument("--date", required=True) p_row.add_argument("--header", action="store_true", help="print the header first") + p_row.add_argument( + "--max-desktop-ms", + type=int, + help="exit 3 when a host run stalled the login sessions longer", + ) p_sum = sub.add_parser("summary", help="medians and the winner for a TSV") p_sum.add_argument("tsv", type=Path) return parser @@ -70,6 +75,13 @@ def _cmd_row(args: argparse.Namespace) -> int: if args.header: sys.stdout.write(format_row(None) + "\n") sys.stdout.write(format_row(row) + "\n") + stall, limit = row["desktop_full_ms"], args.max_desktop_ms + if limit is not None and stall != "na" and int(stall) > limit: + sys.stderr.write( + f"swap_bench: the login sessions stalled {stall} ms " + f"(limit {limit} ms): this run pressed the desktop\n" + ) + return 3 return 0 diff --git a/python_pkg/swap_bench/stats.py b/python_pkg/swap_bench/stats.py index 1cd341fa..638b9155 100644 --- a/python_pkg/swap_bench/stats.py +++ b/python_pkg/swap_bench/stats.py @@ -39,6 +39,7 @@ COLUMNS = ( "zswpwb", "global_full_avg10", "desktop_full_ms", + "outside_pswpout", ) _SECTOR_PER_PAGE = 8 # 512-byte sectors in a 4 KiB page @@ -88,6 +89,21 @@ def _desktop_full_ms(run: Path, env: str) -> str: return str(round(delta / 1000)) +def _outside_pswpout( + run: Path, env: str, before: dict[str, int], after: dict[str, int] +) -> str: + """Pages the rest of the host swapped out during a host run. + + Global pswpout minus the scope's own. zram's pool is not charged to the + scope, so a zram run can make global reclaim swap other processes out + too. A VM run has no outside: ``na``. + """ + if env != "host": + return "na" + scope_out = _kv(run / "cg_memory.stat").get("pswpout", 0) + return str(after["pswpout"] - before["pswpout"] - scope_out) + + def _ratio(stored_in: float, stored_out: float) -> str: return f"{stored_in / stored_out:.2f}" if stored_out > 0 else "na" @@ -150,6 +166,7 @@ def compute_row( "zswpwb": str(zswpwb), "global_full_avg10": f"{_psi(run / 'after/pressure')['full']['avg10']:.2f}", "desktop_full_ms": _desktop_full_ms(run, env), + "outside_pswpout": _outside_pswpout(run, env, before, after), } return {c: values[c] for c in COLUMNS} diff --git a/python_pkg/swap_bench/tests/conftest.py b/python_pkg/swap_bench/tests/conftest.py index fea7a21e..d32640d4 100644 --- a/python_pkg/swap_bench/tests/conftest.py +++ b/python_pkg/swap_bench/tests/conftest.py @@ -51,7 +51,9 @@ def run_dir(tmp_path: Path) -> Path: 2 * _PSI.format(some=0, full=4000, f10="0.00"), ) _write(tmp_path, "cg_pressure", _PSI.format(some=40000, full=30000, f10="1.00")) - _write(tmp_path, "cg_memory.stat", "zswpwb 3\nzswap 100\nzswapped 400\n") + _write( + tmp_path, "cg_memory.stat", "zswpwb 3\nzswap 100\nzswapped 400\npswpout 7000\n" + ) _write(tmp_path, "peak/memory.stat", "zswap 1000\nzswapped 3500\n") _write( tmp_path, diff --git a/python_pkg/swap_bench/tests/test_cli.py b/python_pkg/swap_bench/tests/test_cli.py index 62187806..f10ccd69 100644 --- a/python_pkg/swap_bench/tests/test_cli.py +++ b/python_pkg/swap_bench/tests/test_cli.py @@ -68,6 +68,26 @@ def test_row_with_and_without_header( assert len(_out(capsys).splitlines()) == 1 +@pytest.mark.parametrize( + ("env", "limit", "code"), + [("host", 5, 3), ("host", 6, 0), ("vm", 0, 0)], +) +def test_row_fails_when_the_desktop_stalled( + capsys: pytest.CaptureFixture[str], + run_dir: Path, + env: str, + limit: int, + code: int, +) -> None: + """A host row whose desktop stall (6 ms here) passes the limit exits 3.""" + argv = ["row", "--dir", str(run_dir), "--env", env, "--setup", "zram"] + argv += ["--seed", "1", "--size-mib", "1", "--date", "d"] + assert cli.main([*argv, "--max-desktop-ms", str(limit)]) == code + out, err = capsys.readouterr() + assert out.startswith("d\t") # the row is printed either way + assert ("the login sessions stalled 6 ms" in err) == (code == 3) + + def test_summary(capsys: pytest.CaptureFixture[str], tmp_path: Path) -> None: """``summary`` prints the medians table.""" path = tmp_path / "r.tsv" diff --git a/python_pkg/swap_bench/tests/test_stats.py b/python_pkg/swap_bench/tests/test_stats.py index b98b89d2..f008a318 100644 --- a/python_pkg/swap_bench/tests/test_stats.py +++ b/python_pkg/swap_bench/tests/test_stats.py @@ -29,6 +29,8 @@ def test_zram_host_row(run_dir: Path) -> None: assert row["global_full_avg10"] == "0.20" assert row["pages"] == "256" assert row["desktop_full_ms"] == "6" # two sessions, 3000 us each + # Global pswpout grew 8000 pages, the scope swapped out 7000. + assert row["outside_pswpout"] == "1000" assert list(row) == list(COLUMNS) @@ -45,6 +47,7 @@ def test_vm_rows_are_system_wide(run_dir: Path) -> None: assert row["zswpwb"] == "2" assert row["ratio"] == "2.50" assert row["desktop_full_ms"] == "na" + assert row["outside_pswpout"] == "na" def test_host_without_sessions_has_no_desktop_psi(run_dir: Path) -> None: