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

Merged
aznohonza merged 5 commits from upstream-pr/2967 into main 2026-12-02 00:21:22 +00:00
aznohonza commented 2026-12-01 21:56:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T21:56:03Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5595283531 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T21:56:03Z. --- 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://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7303967030) ### 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)
aznohonza commented 2026-12-01 22:01:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:01:22Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327155513 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327155513). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T22:01:22Z. --- 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.
merzleckeier commented 2026-12-01 22:13:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T22:13:24Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327446412 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327446412). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T22:13:24Z. --- 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.
aznohonza commented 2026-12-01 22:14:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:14:31Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327479517 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327479517). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T22:14:31Z. --- 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.
KelboLive commented 2026-12-01 22:19:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T22:19:28Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6141173328 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#pullrequestreview-6141173328). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T22:19:28Z. **Review:** COMMENTED --- 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.
aznohonza commented 2026-12-01 22:28:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:28:21Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327903421 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327903421). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T22:28:21Z. --- 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 commented 2026-12-01 22:28:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:28:47Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327913805 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7327913805). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T22:28:47Z. --- 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.
andrew-ai commented 2026-12-01 22:54:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T22:54:34Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7328490854 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7328490854). Originally posted by [andrew-ai](https://github.com/andrew-ai) on 2026-12-01T22:54:34Z. --- 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.
aznohonza commented 2026-12-01 23:04:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T23:04:24Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7328757456 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7328757456). Originally posted by [aznohonza](https://github.com/aznohonza) on 2026-12-01T23:04:24Z. --- 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.
MoonEyes commented 2026-12-02 00:07:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T00:07:39Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7330172655 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2967#issuecomment-7330172655). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T00:07:39Z. --- 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).
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
ProjectLeonida/mandy!2967
No description provided.