game_run_summary: record the run cgroup's memory peak #2967

Manually merged
github merged 5 commits from github-bot/gh-2967 into main 2026-12-02 00:22:22 +00:00 AGit
Owner

@⁠aznohonza on GitHub · 2026-12-01 21:56 UTC · original
aznohonza:tools/cgroup-memory-peak → main · +60 −8 · 5 files · 5 commits · merged 2026-12-02 00:21 UTC

Re-created from the original #2845. aznohonza/mandy-contrib was made private at 21:41 UTC on 2026-12-01, which detached the fork and permanently closed its pull requests; GitHub refuses to reopen them (422 state cannot be changed). Same branch, same head ace83ae110db8fadcb7e8d00d9e27a829cc47247. The original review thread is at #2845.


Claimed in the coordination issue as: WINE-RUN-MEMORY-PEAK

What and why

scripts/run_game_wine.sh runs the title in a cgroup of its own when it is started in a systemd scope, and that scope usually also carries MemoryMax (e.g. systemd-run --user --scope -p MemoryMax=24G), but the run folder and the summary said nothing about how close the run came to that limit. The wrapper now reads the cgroup's memory.peak once the session has ended and writes it to <out>/memory_peak (bytes), and tools/game_run_summary.py prints cgroup memory peak: 23.6 GiB after the run time.

  • cgroup v2 only (kernel 5.19+), and only when the file is readable: cgroup v1 or an older kernel leaves no file and no line.
  • The peak is the whole cgroup's: the run's own scope when one is used, else the caller's cgroup since it was created. docs/linux_proton.md says so.
  • The two path overrides (LEONIDA_SELF_CGROUP_PATH, LEONIDA_CGROUP_ROOT) use the names and defaults of scripts/linux-boot/boot-inner.sh; they are also what the tests point at a fake proc file and cgroup tree.
  • No game data: the file holds one integer, and the summary still never prints a log line.

Open #2436 touches the same wrapper, so one of the two may need a rebase (a textual conflict in the environment block); this change adds no option.

Tested

CPU only, no game files, no Wine, no GPU:

  • python -I tests/test_game_run_summary.py — 13 tests pass, one new: 25,316,786,176 bytes prints as cgroup memory peak: 23.6 GiB, and a folder without memory_peak gets no line.
  • python -I tests/test_run_game_wine.py — 11 tests pass, two new: a stubbed run with a fake /proc/self/cgroup and memory.peak writes memory_peak and prints the line; a cgroup-v1 proc file leaves both out.
  • python -I tests/test_run_game_wine_safety.py — 3 tests pass.
  • python -m compileall -q on the changed Python files, scripts/check_no_game_data.py on all changed files, and the docs-only checks (tests/test_docs_*.py, tests/test_i18n_index.py, tests/test_design_contract_rows.py).

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
**@⁠aznohonza** on GitHub · 2026-12-01 21:56 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967) `aznohonza:tools/cgroup-memory-peak` → `main` · +60 −8 · 5 files · 5 commits · merged 2026-12-02 00:21 UTC Re-created from the original #2845. `aznohonza/mandy-contrib` was made private at 21:41 UTC on 2026-12-01, which detached the fork and permanently closed its pull requests; GitHub refuses to reopen them (`422 state cannot be changed`). Same branch, same head `ace83ae110db8fadcb7e8d00d9e27a829cc47247`. The original review thread is at #2845. --- Claimed in the coordination issue as: [WINE-RUN-MEMORY-PEAK](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570) ### What and why `scripts/run_game_wine.sh` runs the title in a cgroup of its own when it is started in a systemd scope, and that scope usually also carries `MemoryMax` (e.g. `systemd-run --user --scope -p MemoryMax=24G`), but the run folder and the summary said nothing about how close the run came to that limit. The wrapper now reads the cgroup's `memory.peak` once the session has ended and writes it to `<out>/memory_peak` (bytes), and `tools/game_run_summary.py` prints `cgroup memory peak: 23.6 GiB` after the run time. - cgroup v2 only (kernel 5.19+), and only when the file is readable: cgroup v1 or an older kernel leaves no file and no line. - The peak is the whole cgroup's: the run's own scope when one is used, else the caller's cgroup since it was created. `docs/linux_proton.md` says so. - The two path overrides (`LEONIDA_SELF_CGROUP_PATH`, `LEONIDA_CGROUP_ROOT`) use the names and defaults of `scripts/linux-boot/boot-inner.sh`; they are also what the tests point at a fake proc file and cgroup tree. - No game data: the file holds one integer, and the summary still never prints a log line. Open #2436 touches the same wrapper, so one of the two may need a rebase (a textual conflict in the environment block); this change adds no option. ### Tested CPU only, no game files, no Wine, no GPU: - `python -I tests/test_game_run_summary.py` — 13 tests pass, one new: 25,316,786,176 bytes prints as `cgroup memory peak: 23.6 GiB`, and a folder without `memory_peak` gets no line. - `python -I tests/test_run_game_wine.py` — 11 tests pass, two new: a stubbed run with a fake `/proc/self/cgroup` and `memory.peak` writes `memory_peak` and prints the line; a cgroup-v1 proc file leaves both out. - `python -I tests/test_run_game_wine_safety.py` — 3 tests pass. - `python -m compileall -q` on the changed Python files, `scripts/check_no_game_data.py` on all changed files, and the docs-only checks (`tests/test_docs_*.py`, `tests/test_i18n_index.py`, `tests/test_design_contract_rows.py`). GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
# Conflicts:
#	tests/test_run_game_wine.py
KelboLive's review of #2845: without a systemd scope the peak is the caller
cgroup's lifetime peak, so the one-line summary now says so, which keeps a
comparison table from reading it as the run's own.

The `[ -n "$cg_rel" ]` guard was untested: removing it still passed, because the
fake root had no memory.peak to pick up. The v1 test now has one at the root, so an
empty v2 path reads nothing and dropping the guard fails it (checked: mutation
gives 1 failure).

AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 21:59:18 +00:00
Author
Owner

@⁠aznohonza on GitHub · 2026-12-01 22:01 UTC · original

The red windows check is run 46697161399 from the original #2845 head — same SHA ace83ae11, so GitHub attached the old check run to this re-created pull request. It is the known loader timing flake (PE images written and read back: 71 ms over the 25 ms limit), documented on #2845, and nothing in this change touches the loader. The fresh run on this PR (46754320832) has change-scope and no-game-data green, with check, linux-python-and-viewer and semantic-tests queued.

AI-assisted.

**@⁠aznohonza** on GitHub · 2026-12-01 22:01 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327155513) The red `windows` check is run 46697161399 from the original #2845 head — same SHA `ace83ae11`, so GitHub attached the old check run to this re-created pull request. It is the known loader timing flake (PE images written and read back: 71 ms over the 25 ms limit), documented on #2845, and nothing in this change touches the loader. The fresh run on this PR (46754320832) has `change-scope` and `no-game-data` green, with `check`, `linux-python-and-viewer` and `semantic-tests` queued. AI-assisted.
Author
Owner

@⁠merzleckeier on GitHub · 2026-12-01 22:13 UTC · original

The wrapper records the real kernel peak in both a fresh scope and the caller cgroup.

I integrated ace83ae110db8fadcb7e8d00d9e27a829cc47247 onto main c4ca5761508f136c5530482093bb3053b0bad4fa, then tested it once with #2966 and separately with #2968. Those two combinations merge cleanly. The #2436 head is already an ancestor of this main, so the wrapper here already includes it.

On Linux with cgroup v2 and systemd 262, I ran the real wrapper against a synthetic Wine process. Each dedicated case used its own systemd-run --user --scope. The synthetic child allocated and released 80 MiB before the wrapper read memory.peak.

  • Main wrote no peak file in any of its six cases. In the six dedicated-scope cases with #2967, the saved values were 102,719,488–105,156,608 bytes. All matched the kernel value sampled after the wrapper and appeared as 0.1 GiB in the summary.
  • The six caller-cgroup cases with #2967 saved the same historical peak as the inherited cgroup, 17,839,054,848 bytes, shown as 16.6 GiB.
  • With #2968 the peak stayed present for normal exit, title breakpoint, and device lost. The latter two came from separate synthetic exit-3 inputs. Each combination also passed 60 focused stock test methods.

AI-assisted local testing, independently checked against the raw data. Synthetic runtime and trace inputs. The cgroup files and scopes were real.

**@⁠merzleckeier** on GitHub · 2026-12-01 22:13 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327446412) The wrapper records the real kernel peak in both a fresh scope and the caller cgroup. I integrated `ace83ae110db8fadcb7e8d00d9e27a829cc47247` onto main `c4ca5761508f136c5530482093bb3053b0bad4fa`, then tested it once with #2966 and separately with #2968. Those two combinations merge cleanly. The #2436 head is already an ancestor of this main, so the wrapper here already includes it. On Linux with cgroup v2 and systemd 262, I ran the real wrapper against a synthetic Wine process. Each dedicated case used its own `systemd-run --user --scope`. The synthetic child allocated and released 80 MiB before the wrapper read `memory.peak`. - Main wrote no peak file in any of its six cases. In the six dedicated-scope cases with #2967, the saved values were 102,719,488–105,156,608 bytes. All matched the kernel value sampled after the wrapper and appeared as 0.1 GiB in the summary. - The six caller-cgroup cases with #2967 saved the same historical peak as the inherited cgroup, 17,839,054,848 bytes, shown as 16.6 GiB. - With #2968 the peak stayed present for normal exit, `title breakpoint`, and `device lost`. The latter two came from separate synthetic exit-3 inputs. Each combination also passed 60 focused stock test methods. AI-assisted local testing, independently checked against the raw data. Synthetic runtime and trace inputs. The cgroup files and scopes were real.
Author
Owner

@⁠aznohonza on GitHub · 2026-12-01 22:14 UTC · original

Thanks — that is the measurement this path needed: the scope's own peak (102,719,488–105,156,608 bytes) and the inherited caller peak (17,839,054,848 bytes) both land in the saved value and the summary, and main writes no peak file. Your combined runs with #2966/#2968 also match the merge-tree check here. No change on my side.

AI-assisted.

**@⁠aznohonza** on GitHub · 2026-12-01 22:14 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327479517) Thanks — that is the measurement this path needed: the scope's own peak (102,719,488–105,156,608 bytes) and the inherited caller peak (17,839,054,848 bytes) both land in the saved value and the summary, and main writes no peak file. Your combined runs with #2966/#2968 also match the merge-tree check here. No change on my side. AI-assisted.
Author
Owner

@⁠KelboLive on GitHub · 2026-12-01 22:19 UTC · original · reviewed

Identical to #2845 (ace83ae11), which I reviewed: the cgroup-v2 0:: path, teardown-time read and GiB rendering are right, and the v2 selection is mutation-pinned. merge-tree is clean (main touched only an adjacent docs bullet). The two nits from there remain and are non-blocking: without a systemd scope this is the caller cgroup's lifetime peak, so the summary line should say that, and the [ -n "$cg_rel" ] guard is untested.

**@⁠KelboLive** on GitHub · 2026-12-01 22:19 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#pullrequestreview-6141173328) · **reviewed** Identical to #2845 (`ace83ae11`), which I reviewed: the cgroup-v2 `0::` path, teardown-time read and GiB rendering are right, and the v2 selection is mutation-pinned. `merge-tree` is clean (main touched only an adjacent docs bullet). The two nits from there remain and are non-blocking: without a systemd scope this is the caller cgroup's lifetime peak, so the summary line should say that, and the `[ -n "$cg_rel" ]` guard is untested.
Without a systemd scope the saved value is the caller cgroup's lifetime
peak, not the run's; the summary line says so now.

AI-assisted.
Author
Owner

@⁠aznohonza on GitHub · 2026-12-01 22:28 UTC · original

Thanks — both notes are right. The summary line already says (the run's scope, else the caller's cgroup); it does not say the caller case is a lifetime peak, and the [ -n "$cg_rel" ] guard has no test (the v2 0:: path and the v1 fallback are what the suite covers). I will word the line as you suggest and leave the guard test as a follow-up.

AI-assisted.

**@⁠aznohonza** on GitHub · 2026-12-01 22:28 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327903421) Thanks — both notes are right. The summary line already says `(the run's scope, else the caller's cgroup)`; it does not say the caller case is a lifetime peak, and the `[ -n "$cg_rel" ]` guard has no test (the v2 `0::` path and the v1 fallback are what the suite covers). I will word the line as you suggest and leave the guard test as a follow-up. AI-assisted.
Author
Owner

@⁠aznohonza on GitHub · 2026-12-01 22:28 UTC · original · edited 2026-12-01 22:52 UTC

Done in f48318962: the line now reads (the run's scope, else the caller cgroup's lifetime peak), and both tests that pin the wording are updated (tests/test_game_run_summary.py, tests/test_run_game_wine.py — the second one caught the first CI run). The [ -n "$cg_rel" ] guard test stays a follow-up, as noted.

AI-assisted.

**@⁠aznohonza** on GitHub · 2026-12-01 22:28 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327913805) · edited 2026-12-01 22:52 UTC Done in `f48318962`: the line now reads `(the run's scope, else the caller cgroup's lifetime peak)`, and both tests that pin the wording are updated (`tests/test_game_run_summary.py`, `tests/test_run_game_wine.py` — the second one caught the first CI run). The `[ -n "$cg_rel" ]` guard test stays a follow-up, as noted. AI-assisted.
github-bot force-pushed github-bot/gh-2967 from cb661b0f0d to f483189624 2026-12-01 22:54:34 +00:00 Compare
Author
Owner

@⁠andrew-ai on GitHub · 2026-12-01 22:54 UTC · original

The existing v1 fixture already catches removal of the nonempty-path guard. On Ubuntu/WSL at f48318962 I ran test_no_cgroup_v2_peak_is_not_an_error and test_records_the_cgroup_memory_peak. Both passed. In a temporary copy I removed just the nonempty cg_rel check and repeated the same two tests. The v1 case failed at test_run_game_wine.py:217 because the wrapper wrote memory_peak from the fixture's root-level 999-byte sentinel. The v2 control still passed.

That covers the guard-removal follow-up mentioned above with the tests already in this PR. Codex-assisted.

**@⁠andrew-ai** on GitHub · 2026-12-01 22:54 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7328490854) The existing v1 fixture already catches removal of the nonempty-path guard. On Ubuntu/WSL at f48318962 I ran test_no_cgroup_v2_peak_is_not_an_error and test_records_the_cgroup_memory_peak. Both passed. In a temporary copy I removed just the nonempty cg_rel check and repeated the same two tests. The v1 case failed at test_run_game_wine.py:217 because the wrapper wrote memory_peak from the fixture's root-level 999-byte sentinel. The v2 control still passed. That covers the guard-removal follow-up mentioned above with the tests already in this PR. Codex-assisted.
Author
Owner

@⁠aznohonza on GitHub · 2026-12-01 23:04 UTC · original

Thanks — that corrects what I said above: the guard is already pinned. test_no_cgroup_v2_peak_is_not_an_error fails at test_run_game_wine.py:217 when the nonempty cg_rel check is removed (the v1 sentinel becomes the peak), and the v2 control stays green. So no follow-up is needed for it.

AI-assisted.

**@⁠aznohonza** on GitHub · 2026-12-01 23:04 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7328757456) Thanks — that corrects what I said above: the guard is already pinned. `test_no_cgroup_v2_peak_is_not_an_error` fails at `test_run_game_wine.py:217` when the nonempty `cg_rel` check is removed (the v1 sentinel becomes the peak), and the v2 control stays green. So no follow-up is needed for it. AI-assisted.
Author
Owner

@⁠MoonEyes on GitHub · 2026-12-02 00:07 UTC · original

Merging. Head f48318962 merges cleanly with main 7adb42f7a and does not force a rebase of #2566. Ran main (7adb42f7a) plus the PR myself: test_game_run_summary 13 green, red (1 error) with tools/game_run_summary.py from main; test_run_game_wine skips on Windows; ci_registration, line endings, stdout encoding and docs suites green. Third-party verdict on this head; all CI green. Merged by MoonEyes.

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-12-02 00:07 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7330172655) Merging. Head `f48318962` merges cleanly with `main` `7adb42f7a` and does not force a rebase of #2566. Ran main (7adb42f7a) plus the PR myself: test_game_run_summary 13 green, red (1 error) with tools/game_run_summary.py from main; test_run_game_wine skips on Windows; ci_registration, line endings, stdout encoding and docs suites green. Third-party verdict on this head; all CI green. Merged by MoonEyes. AI-assisted (Claude Code).
github manually merged commit 5d06e4793e into main 2026-12-02 00:22:22 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!2967
No description provided.