Skip to content

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

Open
erax4193 wants to merge 1 commit into
trustno1-coder:mainfrom
erax4193:fix/commit-retry-on-pressure
Open

erax4193 wants to merge 1 commit into
trustno1-coder:mainfrom
erax4193:fix/commit-retry-on-pressure

Conversation

@erax4193

Copy link
Copy Markdown

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

@Exopus-0x65f7ad0

Copy link
Copy Markdown

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 pipeline: classify stores in a single decode pass (#1055) #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. GPU: an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed (#944) #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 GPU: an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed (#944) #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 GPU: an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed (#944) #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 GPU: an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed (#944) #953 does with freed_mb, would show quickly whether it saves Crash 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x56edab (read 0xe, rax=0x0) right after photosensitivity warning / core_restofworld.rpf load (v2026.11.28.01) #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.)

…essure

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
committed pages back to the system.  The first successful retry logs
freed_mb so it is easy to see how much the pool gave.

Fixes trustno1-coder#1049

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@erax4193
erax4193 force-pushed the fix/commit-retry-on-pressure branch from 7b01c26 to b03c881 Compare November 28, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants