LLVM: Memory becomes saturated in configurations with many threads. #3041
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Imported from ubiquitarianism/leonida. Originally posted by boludoz on 2026-12-02T04:24:49Z.
The shader LLVM will fail when faced with many threads and cores; It is well known that each additional core places stress on the RAM.
Specs: RTX 3080 ASUS 12 GB Edition, 32 GB of ram DDR5, Ryzen 7 9850X3D.
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T07:21:21Z.
finding: source audit + 16C/32T RAM scaling check on
main(f37c4a87d, Windows 10 Pro 22H2, AMD Ryzen 9 5950X 16C/32T, 64 GiB RAM, NVIDIA RTX 5070 12 GB, driver621.40).1. Where high thread counts currently scale memory without a RAM cap
While
d3d12/crates/leonida-shaderemits LLVM 3.7 DXIL bitcode directly in Rust (emit/bitcode.rs) rather than linking LLVM, there are four concrete shader / LLVM / driver-compiler paths in the repo whose default concurrency scales purely with logical core count and ignores available host RAM:d3d12/apps/leonida/src/warm.rs:71-72(warm::warm, invoked byplay-nvidia.ps1:894-913): defaults tocores * 2 / 3separate child processes (21processes on a 32-thread CPU), each creating its ownID3D12Device, GPU driver shader compiler context, and mimalloc arenas, with no upper bound and no host-RAM check.d3d12/apps/leonida/src/warm.rs:305(warm::store_these): defaults toavailable_parallelism() * 2 / 3unbounded threads inside a single process creating pipelines concurrently viaknown::store, with no upper clamp or RAM check.d3d12/apps/leonida/src/translate.rs:275, 291-306, 402(leonida translateandleonida shaders): defaults to100%ofavailable_parallelism()(32threads on 16C/32T) with no upper cap. Intranslate.rs:291-306, every worker inside the per-filethread::scopealso instantiates its ownValidator::load(dxil.dllLLVM 3.7 validator) andHost::new(false)(ID3D12Device+ driver compiler) per file.scripts/build_llvm_mc.ps1:60, 130: builds LLVM'sllvm-mcfrom C++ source with-j ([Environment]::ProcessorCount / 2)(16parallel MSVCcl.exeprocesses on 32T) without checking available RAM or limitingLLVM_PARALLEL_LINK_JOBS/LLVM_PARALLEL_COMPILE_JOBS.2. Measured RAM scaling on 16C/32T (Ryzen 9 5950X, 64 GiB RAM)
30-35 s sampled runs of
leonida.exe(mainf37c4a87d,--profile diag,diagnostics,dlss,mimalloc) against a local title package (read-onlytranslate):--jobsleonida translate(CPU DXIL emission only)leonida translate(CPU DXIL emission only)leonida translate --pipelines(per-threadHost::new)3. Existing pattern in the repo worth reusing
In-game pipeline compilation (
d3d12/crates/leonida-gpu/src/pipeline/make.rs:1034-1053) already caps workers to(processors * 2 / 3).clamp(2, 16)and drops the cap to(processors * 3 / 4).clamp(2, 8)whenresidency::limited_host_ram()(GlobalMemoryStatusEx,ullTotalPhys <= 32 GiB,d3d12/crates/leonida-gpu/src/residency.rs:175-178) holds.Applying a similar RAM-aware cap (e.g.,
GlobalMemoryStatusExtotal/available physical RAM +clampon default jobs inwarm.rs,translate.rs, andbuild_llvm_mc.ps1, plus hoistingHost::new/Validatorreuse out of the per-file worker loop intranslate.rs:291-306) would prevent high-core-count machines with 16-32 GiB RAM from saturating memory while still allowing explicit--jobs Noverrides.AI-assisted: yes (Antigravity).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T15:05:31Z.
Measured on a 16-thread machine, and the number narrows this: the shader cache build is not the memory hog. Peak working set of
leonida.exe shadersover the whole archive (25,689 files, empty cache each time):--jobsAbout 950 MB of baseline and some 85 MB for each worker (
950 + 85 x jobsfits all three points within 60 MB), so thirty-two threads of this would be around 3.7 GB - a lot for a start-up phase, but not "memory saturated" on the 16-64 GB machines people run this on, and it says nothing about the crash the report is about.Which leaves
warm, exactly where the finding above points.warmcompiles host pipelines, and each of those is a driver-compiler job; the process's memory is then dominated by whatever the compiler holds per pipeline, not by the translator's own allocations. That is a different measurement than the one above and needs aknown-pipelines.binfrom a real run to make - the book is what tellswarmwhich pipelines to make, and without the game there is nothing for it to compile here.So: with a
known-pipelines.bin(the cache folder of anyone who has run the title,%LOCALAPPDATA%\Leonida\d3d12\cache)leonida warm --jobs Ncan be measured the same way, at 4, 8 and 16, and then a default that respects free memory can be written with a number behind it rather than a guess. The measurement above is the part of the path that does not need the game, and it says the cap belongs onwarm, not onshaders.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T15:12:19Z.
Measured
warmitself, on this machine's own book (48 MB,known-pipelines.binfrom a real run) with the compiler children counted - peak of the parent plus everyleonida*.exechild, polled every 200 ms:--jobsTwo things follow, and the second one changes what the fix should be:
known.rssays the title creates 84,000; the ones a session draws with are some 2,000 - so a fullwarmof the drawn ones is 15-20 GB on the numbers above, which is the saturation this issue reports, and it is whyplay-nvidia.ps1gives up on a machine that cannot hold it.--limit: make a piece, let it end, start the next.warmalready takes it; nothing in the launcher uses it in a loop.What I could not do: run the whole book. It needs many minutes and the peaks above say why I would not do it on a 16 GB machine deliberately.
What I would suggest, then:
--limitchunked in the launcher (or inwarmitself, restarting its children every N pipelines) with a ceiling taken from the machine's free memory, rather thancores * 2 / 3processes and hope. The per-pipeline figure above (about 10 MB) is enough to size the chunk: free memory minus 2 GB, divided by 10 MB.One correction to my earlier comment in this issue: I measured
shadersfirst and said the cache build was not the hog - that part stands (2.3 GB at 16 workers), butwarmis, and these are its numbers.AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.