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

Merged
erax4193 merged 1 commit from upstream-pr/1118 into main 2026-11-29 08:16:57 +00:00
erax4193 commented 2026-11-28 13:35:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by erax4193 on 2026-11-28T13:35:24Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5540656739 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1118). Originally posted by [erax4193](https://github.com/erax4193) on 2026-11-28T13:35:24Z. --- ## 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)
Exopus-0x65f7ad0 commented 2026-11-28 13:41:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Exopus-0x65f7ad0 on 2026-11-28T13:41:34Z.


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.)

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240116585 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1118#issuecomment-7240116585). Originally posted by [Exopus-0x65f7ad0](https://github.com/Exopus-0x65f7ad0) on 2026-11-28T13:41:34Z. --- 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.)
Sign in to join this conversation.
No reviewers
No labels
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.

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