testsAndMisc/python_pkg/swap_bench/tests/conftest.py
Krzysztof kuhy Rudnicki 5e0d8727d6 A/B zswap vs zram: zram stays the default
Add setup_zswap.sh and make setup_zram.sh its one-command revert
(shared lib/swap_switch.sh: systemd-boot/GRUB cmdline, live switch or
exit 3 "reboot to apply"). Add swap_bench.sh + python_pkg/swap_bench, a
seeded memory-pressure benchmark. 3 runs x 2 setups in vmbox and on the
host: zram has lower median PSI full in both (VM 5996 vs 10360 ms, host
7427 vs 8973 ms), so the host keeps booting with zram. Results in
linux_configuration/fixes/DOCS-zswap-vs-zram.md.

Bug-class-check: none — new feature and measurement, not a bug fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:34:25 +01:00

62 lines
2.0 KiB
Python

"""Fixture trees of the raw files swap_bench.sh copies for one run."""
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from pathlib import Path
_PSI = (
"some avg10=0.00 avg60=0.00 avg300=0.00 total={some}\n"
"full avg10={f10} avg60=0.00 avg300=0.00 total={full}\n"
)
def _write(root: Path, name: str, text: str) -> None:
path = root / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text)
@pytest.fixture
def run_dir(tmp_path: Path) -> Path:
"""A zram run: 3 GiB in, 1 GiB compressed, 800 pages to disk."""
gib = 1 << 30
_write(
tmp_path,
"workload.txt",
"pages=256\nfill_crc=11\ntouch_crc=22\nmajflt=500\nseconds=12.5\n",
)
_write(tmp_path, "before/vmstat", "pswpout 1000\nzswpwb 5\npgmajfault 9\n")
_write(tmp_path, "after/vmstat", "pswpout 9000\nzswpwb 7\npgmajfault 9\n")
_write(tmp_path, "before/zram_stat", "1 0 0 0 1 0 8000 0 0 0 0\n")
_write(tmp_path, "after/zram_stat", "1 0 0 0 1 0 65600 0 0 0 0\n")
_write(tmp_path, "before/mm_stat", f"{gib} {gib // 2} 0 0\n")
_write(tmp_path, "peak/mm_stat", f"{4 * gib} {gib + gib // 2} 0 0\n")
_write(tmp_path, "before/pressure", _PSI.format(some=1000, full=500, f10="0.10"))
_write(
tmp_path, "after/pressure", _PSI.format(some=301000, full=200500, f10="0.20")
)
_write(
tmp_path,
"before/desktop_pressure",
2 * _PSI.format(some=0, full=1000, f10="0.00"),
)
_write(
tmp_path,
"after/desktop_pressure",
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, "peak/memory.stat", "zswap 1000\nzswapped 3500\n")
_write(
tmp_path,
"peak/meminfo",
"MemTotal: 100 kB\nZswap: 200 kB\nZswapped: 500 kB\n",
)
return tmp_path