Skip to content

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

Open
aznohonza wants to merge 4 commits into
ProjectLeonida:mainfrom
aznohonza:tools/cgroup-memory-peak
Open

aznohonza wants to merge 4 commits into
ProjectLeonida:mainfrom
aznohonza:tools/cgroup-memory-peak

Conversation

@aznohonza

Copy link
Copy Markdown
Contributor

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)

…ard bite

KelboLive's review of ProjectLeonida#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
@aznohonza

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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.

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

@aznohonza

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants