Gate swap_bench host runs on desktop stall
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
Python tests / test (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 C6 live check failed: global memory PSI full avg10 rose during host
runs. Global PSI full counts moments when every busy task is stalled,
which the bench scope causes by itself, so no global figure measures the
desktop. A host run now fails (exit 3, row kept) when the login session
scopes stall over 1 s, and records outside_pswpout: zram's pool is not
charged to the scope, so global reclaim swaps other processes too
(153k-224k pages per run vs 111k idle). DOCS corrected: the scope does
not keep the desktop out of swap, and a nonzero zram disk_wb_pages on
the host is background (20k pages over an idle 28 s).

Bug-class-check: linux_configuration/fixes/lib/tests/test_swap_bench.sh (pressed-desktop case)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-27 13:24:52 +01:00
parent c2f4040acc
commit c76ce53e90
12 changed files with 206 additions and 61 deletions

View File

@ -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"
}

View File

@ -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."
}

View File

@ -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=<scratch> 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"
]
}

View File

@ -60,8 +60,9 @@ medians and the winner. Every run stays under 60 s.
`MemoryMax=4G`, `MemorySwapMax=infinity`, `RuntimeMaxSec=55`. Only the `MemoryMax=4G`, `MemorySwapMax=infinity`, `RuntimeMaxSec=55`. Only the
scope is pressed; PSI, zswap counters and writeback come from the scope's 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 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 when MemAvailable is below the 4 GiB cap plus 2 GiB. It fails (exit 3,
push the desktop into swap. (8 GiB took 37-45 s on zram with other jobs 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.) 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 - **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. 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`: `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. memory stall time over the run. `majflt`: the workload's own major faults.
`disk_wb_pages`: pages written to disk swap, Δ`pswpout` minus Δ zram `disk_wb_pages`: pages written to disk swap, Δ`pswpout` minus Δ zram
writes (zram is a swap device, so `pswpout` counts it too). `zswpwb`: writes (zram is a swap device, so `pswpout` counts it too). It is
zswap's writebacks. `desktop_full_ms` (host): full stall of the login system-wide, so on the host it includes other processes (see the C6
session scopes, i.e. the desktop, during the run. 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 - **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 faults break a tie; a difference under 10 % (the run-to-run noise) is a
tie, and a tie on both keeps zram. 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 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 (-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 (`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 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 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 ### Desktop check on the host (C6, zram, re-measured in the fix stage)
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 The bench scope caps the bench's RAM, but it does not keep the rest of the
during a run only because global PSI counts the bench scope's own stalls. 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 ### Raw rows
```tsv ```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 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 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 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 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 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 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 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 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 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 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 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 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 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 ## Host switch log

View File

@ -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 '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" 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' _t_stub_stdin systemd-run <<'STUB'
while [[ $1 != -- ]]; do shift; done while [[ $1 != -- ]]; do shift; done
shift 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 STUB
_t_stub_cat swapon swaps _t_stub_cat swapon swaps
_setup() { # _setup zram|zswap|none|both _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_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 "zram" "$(_col setup)" "run host: row records the zram setup"
_t_eq "host" "$(_col env)" "run host: row records env" _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" _t_eq 0 "$(_col desktop_full_ms)" "run host: records the session scopes' PSI stall"
echo "same seed, same workload (C7)" echo "same seed, same workload (C7)"

View File

@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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

1 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
2 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
3 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
4 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
5 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
6 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
7 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
8 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
9 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
10 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
11 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
12 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
13 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

View File

@ -7,8 +7,10 @@
# #
# One run per call, each under 60 s, appending one row to the results TSV. # 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 # 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 # allowed); its PSI and zswap counters are the scope's own. The scope does
# PSI and zswap counters are the scope's own. VM mode puts the whole guest # 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 # under pressure and uses global counters. A run that fails or times out
# records nothing. The Python side (python_pkg/swap_bench) holds the # records nothing. The Python side (python_pkg/swap_bench) holds the
# workload, the parsing and the winner rule; this script only places it. # 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 ZRAM_SYSFS="${ZRAM_SYSFS:-/sys/block/zram0}"
readonly ZSWAP_PARAMS_DIR="${ZSWAP_PARAMS_DIR:-/sys/module/zswap/parameters}" readonly ZSWAP_PARAMS_DIR="${ZSWAP_PARAMS_DIR:-/sys/module/zswap/parameters}"
readonly HOST_MEMORY_MAX="${SWAP_BENCH_MEMORY_MAX:-4G}" 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 # A wrapper on PATH may add properties a scope refuses (Nice=); point this at
# /usr/bin/systemd-run to bypass it. # /usr/bin/systemd-run to bypass it.
readonly SYSTEMD_RUN="${SWAP_BENCH_SYSTEMD_RUN:-systemd-run}" readonly SYSTEMD_RUN="${SWAP_BENCH_SYSTEMD_RUN:-systemd-run}"
@ -81,8 +87,6 @@ host_has_room() {
((avail_kib >= cap_kib + 2 * 1024 * 1024)) ((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 DIR ENV SIZE SEED — runs inside the scope (host) or the guest (vm).
inner() { inner() {
local dir="$1" env="$2" size="$3" seed="$4" cg local dir="$1" env="$2" size="$3" seed="$4" cg
@ -118,7 +122,6 @@ cmd_run() {
dir="$(mktemp -d)" dir="$(mktemp -d)"
RUN_DIR="$dir" # global: the EXIT trap runs after this function's locals are gone RUN_DIR="$dir" # global: the EXIT trap runs after this function's locals are gone
trap 'rm -rf "${RUN_DIR:?}"' EXIT trap 'rm -rf "${RUN_DIR:?}"' EXIT
echo "global memory PSI full avg10 before: $(global_full_avg10)"
snap "${dir}/before" snap "${dir}/before"
if [[ $env == host ]]; then if [[ $env == host ]]; then
"$SYSTEMD_RUN" --user --scope --quiet --unit="swap-bench-$$" \ "$SYSTEMD_RUN" --user --scope --quiet --unit="swap-bench-$$" \
@ -129,11 +132,11 @@ cmd_run() {
fi fi
((rc == 0)) || die "workload failed (exit $rc): no row recorded" ((rc == 0)) || die "workload failed (exit $rc): no row recorded"
snap "${dir}/after" snap "${dir}/after"
echo "global memory PSI full avg10 after: $(global_full_avg10)" local -a header=() gate=()
local -a header=()
[[ -s $RESULTS ]] || header=(--header) [[ -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" \ 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() { main() {

View File

@ -36,6 +36,11 @@ def _parser() -> argparse.ArgumentParser:
p_row.add_argument("--size-mib", type=int, required=True) p_row.add_argument("--size-mib", type=int, required=True)
p_row.add_argument("--date", 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("--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 = sub.add_parser("summary", help="medians and the winner for a TSV")
p_sum.add_argument("tsv", type=Path) p_sum.add_argument("tsv", type=Path)
return parser return parser
@ -70,6 +75,13 @@ def _cmd_row(args: argparse.Namespace) -> int:
if args.header: if args.header:
sys.stdout.write(format_row(None) + "\n") sys.stdout.write(format_row(None) + "\n")
sys.stdout.write(format_row(row) + "\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 return 0

View File

@ -39,6 +39,7 @@ COLUMNS = (
"zswpwb", "zswpwb",
"global_full_avg10", "global_full_avg10",
"desktop_full_ms", "desktop_full_ms",
"outside_pswpout",
) )
_SECTOR_PER_PAGE = 8 # 512-byte sectors in a 4 KiB page _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)) 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: def _ratio(stored_in: float, stored_out: float) -> str:
return f"{stored_in / stored_out:.2f}" if stored_out > 0 else "na" return f"{stored_in / stored_out:.2f}" if stored_out > 0 else "na"
@ -150,6 +166,7 @@ def compute_row(
"zswpwb": str(zswpwb), "zswpwb": str(zswpwb),
"global_full_avg10": f"{_psi(run / 'after/pressure')['full']['avg10']:.2f}", "global_full_avg10": f"{_psi(run / 'after/pressure')['full']['avg10']:.2f}",
"desktop_full_ms": _desktop_full_ms(run, env), "desktop_full_ms": _desktop_full_ms(run, env),
"outside_pswpout": _outside_pswpout(run, env, before, after),
} }
return {c: values[c] for c in COLUMNS} return {c: values[c] for c in COLUMNS}

View File

@ -51,7 +51,9 @@ def run_dir(tmp_path: Path) -> Path:
2 * _PSI.format(some=0, full=4000, f10="0.00"), 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_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, "peak/memory.stat", "zswap 1000\nzswapped 3500\n")
_write( _write(
tmp_path, tmp_path,

View File

@ -68,6 +68,26 @@ def test_row_with_and_without_header(
assert len(_out(capsys).splitlines()) == 1 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: def test_summary(capsys: pytest.CaptureFixture[str], tmp_path: Path) -> None:
"""``summary`` prints the medians table.""" """``summary`` prints the medians table."""
path = tmp_path / "r.tsv" path = tmp_path / "r.tsv"

View File

@ -29,6 +29,8 @@ def test_zram_host_row(run_dir: Path) -> None:
assert row["global_full_avg10"] == "0.20" assert row["global_full_avg10"] == "0.20"
assert row["pages"] == "256" assert row["pages"] == "256"
assert row["desktop_full_ms"] == "6" # two sessions, 3000 us each 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) 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["zswpwb"] == "2"
assert row["ratio"] == "2.50" assert row["ratio"] == "2.50"
assert row["desktop_full_ms"] == "na" assert row["desktop_full_ms"] == "na"
assert row["outside_pswpout"] == "na"
def test_host_without_sessions_has_no_desktop_psi(run_dir: Path) -> None: def test_host_without_sessions_has_no_desktop_psi(run_dir: Path) -> None: