fix(gpu): cap default pipeline workers by RAM (#520) #528

Open
github-bot wants to merge 1 commit from github-bot/gh-528 into main AGit
Owner

@⁠Skid-ster on GitHub · 2026-12-06 01:54 UTC · original
Skid-ster:fix/ram-aware-pipeline-workers → main · +42 −1 · 2 files · 1 commits · open

Summary

Cap the default host pipeline worker count by total RAM, so first-run pipeline compilation on 16/32 GiB PCs no longer starts a dozen in-process DXIL compiles at once and runs the machine out of memory.

Problem

worker_count() defaults to 3/4 of logical CPUs (2..24) with no regard for RAM. Each worker runs a host compile on its own thread, so on a 16-thread PC 12 compiles are in flight at once. Issue #520 reports exactly the failure this leads to: RAM climbs throughout the initial pipeline compilation until, at 60,622/60,623 pipelines, Windows becomes unresponsive and the whole PC crashes (32 GiB system).

Related finding: the release package's bin\launch.ps1 (packaging-only, not in this repo) deletes every env:LARP_* variable before starting larp.exe, so lowering LARP_PRELOAD_THREADS in a shell has no effect when launching via series-s.cmd — which likely explains why the #520 reporter's attempts to lower it did not help. This PR fixes the binary-side default so safety no longer depends on the variable reaching the process; the packaging script should ideally preserve allow-listed tuning variables too (filed here as context, not changed here).

Change

  • crates/larp-gpu/src/host.rs: add total_physical_ram() next to the existing available_physical_ram(), using the same GlobalMemoryStatusEx pattern (ullTotalPhys).
  • crates/larp-gpu/src/pipeline/make.rs: add a pure workers_for_ram() helper and apply it in worker_count() only when LARP_PRELOAD_THREADS/LARP_PRELOAD_CPU is unset:
    • ≤ 8 GiB RAM → at most 2 workers
    • ≤ 16 GiB RAM → at most 4 workers
    • ≤ 32 GiB RAM → at most 8 workers
    • above that, or if the RAM query fails → unchanged default
  • Explicit values (low/medium/high/max/numeric) are completely unchanged.
  • Unit test workers_for_ram_caps_small_memory_pcs covering the 8/16/32/64 GiB boundaries, the unknown-RAM case, and a below-cap count.

Testing

  • Not built locally — needs verification. The machine where this was prepared has no Rust toolchain or Visual Studio Build Tools, and this repo pins Rust 1.98.1 (rust-toolchain.toml). Please run:
    • cargo test -p larp-gpu pipeline::make
    • cargo build --release -p larp
  • The change is deliberately small and follows the existing GlobalMemoryStatusEx code in host.rs verbatim, but that is not a substitute for compiling it.
  • Motivating hardware (not a test result): i5-13400 (16 threads → 12 workers by default today), 16 GiB RAM, RTX 5060 Ti 8 GiB — with this change that PC would default to 4 workers. No game runs are claimed.
**@⁠Skid-ster** on GitHub · 2026-12-06 01:54 UTC · [original](https://github.com/gamingwithhomie/larp/pull/528) `Skid-ster:fix/ram-aware-pipeline-workers` → `main` · +42 −1 · 2 files · 1 commits · open ## Summary Cap the *default* host pipeline worker count by total RAM, so first-run pipeline compilation on 16/32 GiB PCs no longer starts a dozen in-process DXIL compiles at once and runs the machine out of memory. ## Problem `worker_count()` defaults to 3/4 of logical CPUs (2..24) with no regard for RAM. Each worker runs a host compile on its own thread, so on a 16-thread PC 12 compiles are in flight at once. Issue #520 reports exactly the failure this leads to: RAM climbs throughout the initial pipeline compilation until, at 60,622/60,623 pipelines, Windows becomes unresponsive and the whole PC crashes (32 GiB system). Related finding: the release package's `bin\launch.ps1` (packaging-only, not in this repo) deletes every `env:LARP_*` variable before starting `larp.exe`, so lowering `LARP_PRELOAD_THREADS` in a shell has no effect when launching via `series-s.cmd` — which likely explains why the #520 reporter's attempts to lower it did not help. This PR fixes the binary-side default so safety no longer depends on the variable reaching the process; the packaging script should ideally preserve allow-listed tuning variables too (filed here as context, not changed here). ## Change - `crates/larp-gpu/src/host.rs`: add `total_physical_ram()` next to the existing `available_physical_ram()`, using the same `GlobalMemoryStatusEx` pattern (`ullTotalPhys`). - `crates/larp-gpu/src/pipeline/make.rs`: add a pure `workers_for_ram()` helper and apply it in `worker_count()` **only when `LARP_PRELOAD_THREADS`/`LARP_PRELOAD_CPU` is unset**: - ≤ 8 GiB RAM → at most 2 workers - ≤ 16 GiB RAM → at most 4 workers - ≤ 32 GiB RAM → at most 8 workers - above that, or if the RAM query fails → unchanged default - Explicit values (`low`/`medium`/`high`/`max`/numeric) are completely unchanged. - Unit test `workers_for_ram_caps_small_memory_pcs` covering the 8/16/32/64 GiB boundaries, the unknown-RAM case, and a below-cap count. ## Testing - **Not built locally — needs verification.** The machine where this was prepared has no Rust toolchain or Visual Studio Build Tools, and this repo pins Rust 1.98.1 (`rust-toolchain.toml`). Please run: - `cargo test -p larp-gpu pipeline::make` - `cargo build --release -p larp` - The change is deliberately small and follows the existing `GlobalMemoryStatusEx` code in `host.rs` verbatim, but that is not a substitute for compiling it. - Motivating hardware (not a test result): i5-13400 (16 threads → 12 workers by default today), 16 GiB RAM, RTX 5060 Ti 8 GiB — with this change that PC would default to 4 workers. No game runs are claimed.
Default worker count is 3/4 of logical CPUs with no regard for RAM, so a 16-thread PC runs a dozen in-process DXIL compiles at once; on 16/32 GiB machines first-run preload can exhaust RAM and crash the PC (#520). Cap only the automatic default by total RAM (<=8GiB:2, <=16GiB:4, <=32GiB:8); explicit LARP_PRELOAD_THREADS values are unchanged. Adds host::total_physical_ram() beside available_physical_ram() and a unit test for the caps.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 02:00:30 +00:00
Author
Owner

@⁠Skid-ster on GitHub · 2026-12-06 02:41 UTC · original

Overnight build/test results for commit 76069e5ee6:

  • cargo test -p larp-gpu pipeline::make — 2 passed, 0 failed (parse_wait_budget_handles_opt_in_values, workers_for_ram_caps_small_memory_pcs); 37 filtered out.
  • cargo build --release -p larp — succeeded in 16m56s (rustc/cargo 1.98.1 as pinned by rust-toolchain.toml, CARGO_BUILD_JOBS=4). Warnings only, all pre-existing and in untouched files: unused import / dead code in crates/larp-hle/src/modules/gameinput/playstation.rs, and dead code in apps/larp/src/host_name.rs and apps/larp/src/mods.rs.
  • Smoke test: installed the built larp.exe into a local CNF package copy; larp.exe nv-profile runs and reports the 1024 MiB shader-heap profile.

Marking ready for review.

**@⁠Skid-ster** on GitHub · 2026-12-06 02:41 UTC · [original](https://github.com/gamingwithhomie/larp/pull/528#issuecomment-7450134598) Overnight build/test results for commit 76069e5ee640c67c7efaaf3cef0d2a61dbccef90: - `cargo test -p larp-gpu pipeline::make` — **2 passed, 0 failed** (`parse_wait_budget_handles_opt_in_values`, `workers_for_ram_caps_small_memory_pcs`); 37 filtered out. - `cargo build --release -p larp` — **succeeded** in 16m56s (rustc/cargo 1.98.1 as pinned by `rust-toolchain.toml`, `CARGO_BUILD_JOBS=4`). Warnings only, all pre-existing and in untouched files: unused import / dead code in `crates/larp-hle/src/modules/gameinput/playstation.rs`, and dead code in `apps/larp/src/host_name.rs` and `apps/larp/src/mods.rs`. - Smoke test: installed the built `larp.exe` into a local CNF package copy; `larp.exe nv-profile` runs and reports the 1024 MiB shader-heap profile. Marking ready for review.
Author
Owner

@⁠dekulruno on GitHub · 2026-12-06 02:59 UTC · original

I have this same failure on 64gb memory so it seems to affect above 32gb also.

**@⁠dekulruno** on GitHub · 2026-12-06 02:59 UTC · [original](https://github.com/gamingwithhomie/larp/pull/528#issuecomment-7450351949) I have this same failure on 64gb memory so it seems to affect above 32gb also.
Author
Owner

@⁠christopear on GitHub · 2026-12-06 03:06 UTC · original

One packaging interaction for the Linux release. With the current wrapper, the proposed RAM cap is bypassed even when the user has set no override.

I compared the v1.1.6 FULL package's run.sh with linux-test at 0436029. They match. The script computes a CPU default, clamps it to 4–18, and exports it as LARP_PRELOAD_THREADS. The Rust selector then sees an explicit value.

I ran the launcher's --print-env path with nproc reporting 16 and passed its selected value to the worker selection code from 76069e5e. I fixed the CPU and RAM probes at 16 logical CPUs and 16 GiB for this test.

User setting Direct selector Through current Linux defaults
Neither variable set 4 12
LARP_PRELOAD_THREADS=3 3 3
Only LARP_PRELOAD_CPU=3 3 12
LARP_PRELOAD_THREADS=high 12 12

For packaging, leaving the worker variable unset unless configured would let the binary apply the RAM cap and honor the older alias. That would also change the wrapper's existing 4–18 limits, so worth deciding explicitly. The print-env output could say “automatic” when unset.

Separately, an empty or unrecognized value passed directly to the binary also returned 12. It falls back to the default formula but skips the cap because the variable exists. Applying the cap whenever parsing falls back to automatic selection would cover that case without changing valid overrides.

This measures selection only. It doesn't establish the cause of any particular OOM, especially on machines above the proposed thresholds.

**@⁠christopear** on GitHub · 2026-12-06 03:06 UTC · [original](https://github.com/gamingwithhomie/larp/pull/528#issuecomment-7450438414) One packaging interaction for the Linux release. With the current wrapper, the proposed RAM cap is bypassed even when the user has set no override. I compared the v1.1.6 FULL package's run.sh with [linux-test at 0436029](https://github.com/gamingwithhomie/larp/blob/04360294e112eff61a2282864eb5ee8b7a0b044a/linux/run.sh#L171-L200). They match. The script computes a CPU default, clamps it to 4–18, and exports it as LARP_PRELOAD_THREADS. The Rust selector then sees an explicit value. I ran the launcher's `--print-env` path with nproc reporting 16 and passed its selected value to the worker selection code from `76069e5e`. I fixed the CPU and RAM probes at 16 logical CPUs and 16 GiB for this test. | User setting | Direct selector | Through current Linux defaults | |---|---:|---:| | Neither variable set | 4 | 12 | | LARP_PRELOAD_THREADS=3 | 3 | 3 | | Only LARP_PRELOAD_CPU=3 | 3 | 12 | | LARP_PRELOAD_THREADS=high | 12 | 12 | For packaging, leaving the worker variable unset unless configured would let the binary apply the RAM cap and honor the older alias. That would also change the wrapper's existing 4–18 limits, so worth deciding explicitly. The print-env output could say “automatic” when unset. Separately, an empty or unrecognized value passed directly to the binary also returned 12. It falls back to the default formula but skips the cap because the variable exists. Applying the cap whenever parsing falls back to automatic selection would cover that case without changing valid overrides. This measures selection only. It doesn't establish the cause of any particular OOM, especially on machines above the proposed thresholds.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/528/head:github-bot/gh-528'
git switch 'github-bot/gh-528'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-528'
git switch 'github-bot/gh-528'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-528'
git switch 'github-bot/gh-528'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-528'
git switch 'main'
git merge --squash 'github-bot/gh-528'
git switch 'main'
git merge --ff-only 'github-bot/gh-528'
git switch 'main'
git merge 'github-bot/gh-528'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.