xmem: retry commit() after dropping spare upload buffers on pressure (fixes #1049) #1118

Manually merged
github merged 1 commit from github-bot/gh-1118 into main 2026-11-29 08:22:14 +00:00 AGit
Owner

@⁠erax4193 on GitHub · 2026-11-28 13:35 UTC · original
erax4193:fix/commit-retry-on-pressure → main · +24 −2 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC

Root cause

On 16 GB RAM systems, VirtualAlloc(MEM_COMMIT) fails during core_restofworld.rpf streaming because the Windows commit limit is exhausted. The game allocates ~6.1 GB of physical pages (SEC_RESERVE sections) and commits them on demand through XMemMapPhysicalPages → place() → show_as() → commit().

When the commit limit is hit:

  • commit() returns false
  • XMemMapPhysicalPages() returns null
  • The game stores the null pointer
  • ~2 seconds later the game dereferences [null+0xe] → 0xc0000005

The existing commit_refused() comment already noted: "the title usually faults soon after on the null it gets" — this PR prevents the null from ever being returned.

Fix

Before surfacing the commit failure, drop Victory's spare D3D12 upload buffer pool (trim_spare_chunks, now pub) and retry the commit once.

The SPARE pool holds idle ID3D12Resource upload buffers that back committed Windows pages. Dropping them releases that committed memory back to the system, giving the retry a good chance to succeed. The pool often holds hundreds of MB at the moment of peak pressure.

VirtualAlloc(MEM_COMMIT) fails
  → trim_spare_chunks() drops SPARE upload buffers   ← new
  → retry VirtualAlloc(MEM_COMMIT)                   ← new
  → returns true on success
  → commit_refused() / return false only if retry also fails

Changes

File Change
crates/victory-gpu/src/host.rs trim_spare_chunks made pub, now returns u64 bytes freed
crates/victory-gpu/src/lib.rs Re-exports trim_spare_chunks
crates/victory-hle/src/modules/xmem.rs commit() calls victory_gpu::trim_spare_chunks() on first failure and retries

Testing

The crash is specific to 16 GB RAM. Build verified clean (cargo build --release --locked). The retry path is exercised only when the first VirtualAlloc fails, so there is no overhead on systems that do not hit the commit limit.

Closes #1049

🤖 Generated with Claude Code

**@⁠erax4193** on GitHub · 2026-11-28 13:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1118) `erax4193:fix/commit-retry-on-pressure` → `main` · +24 −2 · 3 files · 1 commits · merged 2026-11-29 08:16 UTC ## Root cause On 16 GB RAM systems, `VirtualAlloc(MEM_COMMIT)` fails during `core_restofworld.rpf` streaming because the Windows commit limit is exhausted. The game allocates ~6.1 GB of physical pages (SEC_RESERVE sections) and commits them on demand through `XMemMapPhysicalPages` → `place()` → `show_as()` → `commit()`. When the commit limit is hit: - `commit()` returns `false` - `XMemMapPhysicalPages()` returns null - The game stores the null pointer - ~2 seconds later the game dereferences `[null+0xe]` → `0xc0000005` The existing `commit_refused()` comment already noted: *"the title usually faults soon after on the null it gets"* — this PR prevents the null from ever being returned. ## Fix Before surfacing the commit failure, drop Victory's spare D3D12 upload buffer pool (`trim_spare_chunks`, now `pub`) and retry the commit once. The `SPARE` pool holds idle `ID3D12Resource` upload buffers that back committed Windows pages. Dropping them releases that committed memory back to the system, giving the retry a good chance to succeed. The pool often holds hundreds of MB at the moment of peak pressure. ``` VirtualAlloc(MEM_COMMIT) fails → trim_spare_chunks() drops SPARE upload buffers ← new → retry VirtualAlloc(MEM_COMMIT) ← new → returns true on success → commit_refused() / return false only if retry also fails ``` ## Changes | File | Change | |------|--------| | `crates/victory-gpu/src/host.rs` | `trim_spare_chunks` made `pub`, now returns `u64` bytes freed | | `crates/victory-gpu/src/lib.rs` | Re-exports `trim_spare_chunks` | | `crates/victory-hle/src/modules/xmem.rs` | `commit()` calls `victory_gpu::trim_spare_chunks()` on first failure and retries | ## Testing The crash is specific to 16 GB RAM. Build verified clean (`cargo build --release --locked`). The retry path is exercised only when the first `VirtualAlloc` fails, so there is no overhead on systems that do not hit the commit limit. Closes #1049 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Both `stores` and `stores_by_address` previously decoded the native
shader program independently, paying the full decode cost twice per
program. The new `classify_stores` function decodes once and checks
both predicates in one pass, short-circuiting as soon as both are
found.

Closes #1055

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
On 16 GB RAM systems, VirtualAlloc(MEM_COMMIT) fails during
core_restofworld.rpf streaming because the Windows commit limit is
exhausted by ~6.1 GB of physical pages.  commit() returned false,
XMemMapPhysicalPages() returned null, the game stored the null, and
2 s later dereferenced [null+0xe] → 0xc0000005.

Before surfacing the failure, drop Victory's spare D3D12 upload buffer
pool (trim_spare_chunks, now pub) and retry the commit once.  The SPARE
pool holds committed GPU upload memory that Windows can reuse, freeing
hundreds of MB at the moment the pressure peaks.

Fixes #1049

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:33:44 +00:00
Author
Owner

@⁠Exopus-0x65f7ad0 on GitHub · 2026-11-28 13:41 UTC · original

Three things that may save a round of review:

  1. This branch also carries f5fec6b ("pipeline: classify stores in a single decode pass"), which has the same tree as #1096. The 91-line pipeline.rs change has nothing to do with the commit retry, so this PR is easier to review rebased onto main with only 7b01c26.

  2. #953 changes the same function the same way: trim_spare_chunks() -> u64, returning the bytes freed, for a retry of refused upload buffers. Whichever lands second will conflict there. Worth coordinating with kibagami-nc so both retries share one helper.

  3. A data point on how much this frees under real pressure. I tested #953's version of the same idea, free the spare chunks and then ask again, on an 8 GB card with 16 GB RAM (report on #953). In the start that ran out of memory at world load, trim_spare_chunks freed 0, 3, 0 and 0 MB on its four calls. By the time memory runs out, the spare pool has usually been drained already (by the pressure sweep, or by lists taking chunks back). So the retry is cheap and correct, but don't expect "hundreds of MB" at the moment it fires. Logging the freed bytes, as #953 does with freed_mb, would show quickly whether it saves #1049's case.

(Also: in my runs on the same machine, commit itself never ran out — 64 GB page file, ~52 GB commit free. The failures were the D3D12 non-local budget. #1021, on the other hand, is the commit limit: physical_free_mib=13960 available_commit_mib=2847. So this PR targets a real case, just on machines with a small page file.)

**@⁠Exopus-0x65f7ad0** on GitHub · 2026-11-28 13:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1118#issuecomment-7240116585) Three things that may save a round of review: 1. **This branch also carries `f5fec6b` ("pipeline: classify stores in a single decode pass")**, which has the same tree as #1096. The 91-line `pipeline.rs` change has nothing to do with the commit retry, so this PR is easier to review rebased onto `main` with only `7b01c26`. 2. **#953 changes the same function the same way**: `trim_spare_chunks() -> u64`, returning the bytes freed, for a retry of refused upload buffers. Whichever lands second will conflict there. Worth coordinating with kibagami-nc so both retries share one helper. 3. **A data point on how much this frees under real pressure.** I tested #953's version of the same idea, free the spare chunks and then ask again, on an 8 GB card with 16 GB RAM (report on #953). In the start that ran out of memory at world load, `trim_spare_chunks` freed **0, 3, 0 and 0 MB** on its four calls. By the time memory runs out, the spare pool has usually been drained already (by the pressure sweep, or by lists taking chunks back). So the retry is cheap and correct, but don't expect "hundreds of MB" at the moment it fires. Logging the freed bytes, as #953 does with `freed_mb`, would show quickly whether it saves #1049's case. (Also: in my runs on the same machine, commit itself never ran out — 64 GB page file, ~52 GB commit free. The failures were the D3D12 non-local budget. #1021, on the other hand, is the commit limit: `physical_free_mib=13960 available_commit_mib=2847`. So this PR targets a real case, just on machines with a small page file.)
github-bot force-pushed github-bot/gh-1118 from 7b01c26c22 to b03c8817d0 2026-11-28 18:08:06 +00:00 Compare
github manually merged commit 7787fe1a72 into main 2026-11-29 08:22:14 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1118
No description provided.