runtime: honor LEONIDA_TITLE_MEMORY_MB in XSystemGetAppMemoryUsageLimit and XMemGetWorkingSetStatistics (RT-TITLE-MEMORY-CAP) #441
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!441
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/441/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@jujumoneylol on GitHub · 2026-11-24 05:22 UTC · original
jujumoneylol:pr/title-memory-cap→main· +93 −2 · 5 files · 2 commits · merged 2026-11-24 22:45 UTCClaimed in the coordination issue as: RT-TITLE-MEMORY-CAP (#14)
What and why
Implements @KoLolX3's finding in #14: both
XSystemGetAppMemoryUsageLimit(runtime/shims/xgameruntime.cpp) andXMemGetWorkingSetStatistics(runtime/shims/xmem.cpp) previously always reported total host physical RAM (ullTotalPhys), causing memory-constrained hosts (16 GB systems or cgroup-capped runs) to tell the title it has more memory than it can safely allocate.LEONIDA_TITLE_MEMORY_MBin bothXSystemGetAppMemoryUsageLimit()andXMemGetWorkingSetStatistics()(total memory at+0).2048..65536MiB (2 GiB..64 GiB).GlobalMemoryStatusEx().ullTotalPhys/ 12 GiB fallback unchanged).6144), lower/upper clamping (512→2048,131072→65536), and malformed values inruntime/test/xgameruntime_test.cppandruntime/test/xmem_test.cpp.Tested
xgameruntime_testandxmem_testwith MSVC 19.44 (vcvars64) + Ninja on top ofmain8f481cf16.xgameruntime_test: OK (166 checks).xmem_test: OK (222 checks).py -3.13 -I scripts/check_no_game_data.py runtime/shims/xgameruntime.cpp runtime/shims/xmem.cpp runtime/test/xgameruntime_test.cpp runtime/test/xmem_test.cpp: clean.GPUs tested: n/a (CPU-only runtime shim & unit tests on Windows 11 26200)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — runtime shim only)@Kokonotcu on GitHub · 2026-11-24 05:38 UTC · original
Same topic from our side (not opening a second PR): the override is useful, but the default still tells the title it owns all host RAM, so an untuned 16 GB host still oversizes its pools. What we run locally for both functions is one value computed once:
LEONIDA_TITLE_MEMORY_MBoverrides it,That gives 13.5 GiB on 32/64 GiB hosts, 12 GiB on 16, 4 GiB on 8. It also makes the two functions agree when
GlobalMemoryStatusExfails (todayXMemfalls back to 12 GiB whileXSystemGetAppMemoryUsageLimitreturns 0).If you want it on top of this PR:
github.com/Kokonotcu/leonida@c88d29c82(shims/title_memory.h,budget_for(physical, override_mb)plus host-size tests inxmem_test). Happy to rebase it onto #441 once this lands.🤖 Generated with Claude Code
@jujumoneylol on GitHub · 2026-11-24 05:44 UTC · original
Thanks @Kokonotcu — really appreciate you coordinating instead of duplicating! Keeping #441 focused on the opt-in
LEONIDA_TITLE_MEMORY_MBoverride keeps it small and easy to review, and rebasing your Series X default budget +GlobalMemoryStatusExfallback alignment on top once #441 lands sounds great.@QemmHD on GitHub · 2026-11-24 08:54 UTC · original
Tested on Windows 11 (VS 2022, main
1c93c86): the xgameruntime/xmem ctests pass (8/8) and the new tests fail without the change, so the code looks right. One thing blocks it:tests/test_docs_env_vars.py::test_every_variable_is_named_in_a_documentfails, becauseLEONIDA_TITLE_MEMORY_MBisn't named in any .md. A line in the docs (e.g. where the other runtime env vars are listed) will fix it; happy to re-test and merge after that.AI-assisted (Claude Code, Claude Opus 5.5).
@jujumoneylol on GitHub · 2026-11-24 21:51 UTC · original
Thanks for testing and catching that, @QemmHD!
Added
LEONIDA_TITLE_MEMORY_MBto the environment-overrides table inruntime/README.mdin6cb16a4faand verifiedtests/test_docs_env_vars.py(4/4 tests) andscripts/check_no_game_data.pyboth pass. Ready for re-test/merge!AI-assisted doc update and check.
@QemmHD on GitHub · 2026-11-24 22:45 UTC · original
Merging.
Why merged: RT-TITLE-MEMORY-CAP:
LEONIDA_TITLE_MEMORY_MB(MiB, clamped to 2048..65536) overrides whatXSystemGetAppMemoryUsageLimitandXMemGetWorkingSetStatisticsreport. I held this earlier for one reason: the env var wasn't documented, sotest_docs_env_varsfailed. The author fixed that in6cb16a4fa(runtime/README.md overrides table). Kokonotcu's idea of a different default budget was accepted as a follow-up.Why it's good: the env read is bounded:
GetEnvironmentVariableAinto a 32-byte buffer, thenstrtoull, rejecting a sign, trailing text, 0 and overflow. Tested on Windows 11 / RTX 4070 SUPER, VS 2022 + Ninja RelWithDebInfo, merged onto main2a5ff9714together with #992:d3d12_depth_resolve, and xmem and xgameruntime pass;d3d12_*tests under validation give 119/120 with 0 VUIDs.git merge-tree against current main
89d7dfcf5: no conflicts.Small follow-ups, not blockers: the README row says "Caps", but a value above host RAM raises the reported limit (up to 64 GiB). The parsing is duplicated in xgameruntime.cpp and xmem.cpp, so a shared helper would keep them in sync. Separately, the xmem check "mapping them does not charge them" measures system-wide commit charge, so it can flake on a heavily loaded machine. It passed 120/120 repeats on an idle one, and that's unrelated to this PR.
AI-assisted (Claude Code, Claude Opus 5.5).