Repository navigation
GPU: free memory is not the runtime's to watch (fixes a world-load deadlock under Wine) - #1849
crashbashash wants to merge 1 commit into
Conversation
f2c5f1f to
de95e51
Compare
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Free memory is not the runtime's to watch (fixes a world-load…): stops the runtime treating free pages as its own — likely a crash/OOM fix on world load. Windows-only.
|
Tested on an RTX 5080, Wine 11.22, on I forced the hang by allocating plain memory at On this Wine the process heap was above 4 GiB in 13 of 13 probes, so the null window wouldn't reach it here. A gap that remains: |
runtime_memory looked at the first page only, so a range starting in a reservation with plain committed memory further in was still guarded, and a write there blocked whoever allocated it (as in free memory). Each region of the range is checked now (VirtualQuery walk); a range with any free or plain committed region is not tracked and is copied whole instead. track runs when a copy is made, not per submission. Reported by astrosteveo on Marvisak#1849.
|
Tested on Linux/Proton with an AMD RDNA4 card: without this PR, current Setup: RX 9070 XT (RDNA4), Mesa RADV, Gentoo, kernel 7.3.4, 64 GB RAM. Proton Experimental What the freeze looked like here (
With this pr the 7 |
runtime_memory looked at the first page only, so a range starting in a reservation with plain committed memory further in was still guarded, and a write there blocked whoever allocated it (as in free memory). Each region of the range is checked now (VirtualQuery walk); a range with any free or plain committed region is not tracked and is copied whole instead. track runs when a copy is made, not per submission. Reported by astrosteveo on Marvisak#1849.
A title buffer object's copy is, with VICTORY_IN_PLACE=1, the title's memory too: placed from the 64 KiB boundary at or below the buffer (views find their bytes by address), past its end by 256 bytes where the allocation has them. A placed buffer's end only needs to be committed pages, not 64 KiB. A remap drops in-place title buffers over it as well. Buffers over many separately mapped 64 KiB views (MEM_MAPPED, one allocation each) are still copied: one heap cannot span them, and tile mappings into heaps opened over process memory were not reliable under vkd3d-proton here. Measured (RTX 5080, proton-cachyos 11.0, the title loading its world, with Marvisak#259, Marvisak#177 and Marvisak#1849 on top for NVIDIA under Wine): 3,335 title buffers and 2,117 loose windows in place, none refused, no device errors; 8 large buffers (378 MB) over separate views still copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fixes a world-load deadlock under Wine)
|
Automated triage for the maintainers.
One thing to keep an eye on: free pages inside a tracked range are now copied whole (as failing reads) on every use instead of counted as zero pages, so a range with large free parts may cost a bit more per frame. CI: passing. Generated by Claude Code |
|
Thanks for testing this on NVIDIA, and for the gap. You're right: I don't know whether the title hits it either; in our runs the change made no measurable difference. AI-assisted (Claude Code). No game data attached. |
|
Test report, as asked in #1921: five runs with this PR on the setup where Setup: Linux (Arch, kernel 6.18 LTS), GTX 1660 6 GB, NVIDIA 620.73.04 (open modules), Wine from GE-Proton11-6 with vkd3d-proton
All five runs with the PR ran to the 15-minute limit in the world. Two started from warm shader and pipeline caches, three from empty ones. Per run: 788 to 855 compute pipelines made, last frame 2,834 to 3,002, frame time in the world about 1.3 s once loading settles (one run 2.4 s at the cut), 0.3 to 24 s during loading. The freeze without the PR was the one described in #1921: no log line and no present any more, Not part of this PR, but for the record on this card with that tree: 153 compute pipelines refused per run (wave64 on a 32-lane host) and 149 to 195 Not tested: Windows, AMD, anything past the first playable scene (the runs only press Enter). 🤖 Generated with Claude Code |
…ain's per-region runtime_pages # Conflicts: # crates/victory-gpu/src/watch.rs
The previous main (old upstream base) is the first parent; the second is upstream main with the current heads of our pull requests merged in: Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491, Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's element-type key on main's three handle maps, and the README. Marvisak#2112 (opt-in, in place) stays in the renderer branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A loose copy of title memory for a null address covers 0..4 MiB, and `runtime_pages` takes free memory for the runtime's (its `shortcut:`), so free parts of the window are tracked and guarded once something is committed there. On Windows nothing is. Under Wine the process heap is: its pages became read-only, and a heap write by a thread holding the guard lock (in `Tracked::take`, `writing` or the fault handler itself) faulted into the handler, which waited for that lock forever: the title stopped at the end of loading. The region check now leaves free memory out, as it leaves out plain committed memory and images; reserved memory still counts (the shortcut keeps that part). Test: a block reserved and released (free memory at a known address) is not tracked. It fails without the change; it only counts if the block is still free afterwards, since other tests allocate meanwhile.
8e4cfd9 to
4f6bace
Compare
|
Rebased onto The test changed with it. The old one tracked the window of a null address, but with the region walk that window is no longer all free under Wine: Wine maps read-only locale files there, which count as views. The new test reserves a block and releases it, so it has free memory at a known address, and checks that it isn't tracked. It fails without the change. Tests: @Impre-visible, thanks for the five runs on the GTX 1660. That's the clearest evidence this PR has had. AI-assisted (Claude Code). No game data attached. |
…fixes a world-load deadlock under Wine)
…r the structure builder started) Two runs with VICTORY_BVH_BUILDER=1 froze 3 and 18 s after the builder started: CPU time stopped, the card idle, no device loss. Thread dumps: threads waiting in watch::install::on_write for the guard lock (the submission thread, the title's main thread, a pipeline worker, and a D3D12 background thread inside the driver's shader compiler), and others waiting for the process heap's lock (audio, XInput). The faulting write on one of them was at 0x5a2e30, inside the process heap (0x590000). is_view took a range with free memory in it for a view and noted its blocks absent, to be guarded once mapped; whatever the process allocated there later was guarded with it, the heap too. The heap's own code then faulted while holding its lock, the fault waited for the guard lock, and the guard lock's holder for the heap. Free memory now is no view and is not noted absent (placeholders still are), as Marvisak/VIctory#1849 found under Wine. New test free_memory_is_not_tracked fails without the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r the structure builder started) Two runs with VICTORY_BVH_BUILDER=1 froze 3 and 18 s after the builder started: CPU time stopped, the card idle, no device loss. Thread dumps: threads waiting in watch::install::on_write for the guard lock (the submission thread, the title's main thread, a pipeline worker, and a D3D12 background thread inside the driver's shader compiler), and others waiting for the process heap's lock (audio, XInput). The faulting write on one of them was at 0x5a2e30, inside the process heap (0x590000). is_view took a range with free memory in it for a view and noted its blocks absent, to be guarded once mapped; whatever the process allocated there later was guarded with it, the heap too. The heap's own code then faulted while holding its lock, the fault waited for the guard lock, and the guard lock's holder for the heap. Free memory now is no view and is not noted absent (placeholders still are), as Marvisak/VIctory#1849 found under Wine. New test free_memory_is_not_tracked fails without the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fixes a world-load deadlock under Wine)
…s to watch (fixes a world-load deadlock under Wine)
What this branch does about Wine: our run-time shaders as DXIL, Marvisak#1849, Marvisak#2249 and Marvisak#2723 merged, lower.rs's larger limit, why Marvisak#1010 stays, and the Wine PRs not taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified 4f6bacef7f53e781bf0a48eca8cd223402092d76 merged cleanly onto 63bcca43 on Windows 11 with both an RTX 5090 (VICTORY_D3D12_DEBUG=1) and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1).
Code review
- Adding
info.State != MEM_FREEinruntime_pages(crates/victory-gpu/src/watch.rs:333-368, condition atwatch.rs:361) cleanly excludes free address space from being treated as runtime GPU memory while keeping write-watched pools (watched(...)),MEM_RESERVEreservations/placeholders, andMEM_COMMIT | MEM_MAPPEDviews tracked, and keepingMEM_IMAGEand plainMEM_COMMIT | MEM_PRIVATEexcluded. - Because any 64 KiB page touching a
MEM_FREEregion is added tootherand removed byruntime.difference(&other)(watch.rs:364-367), a range straddling a reservation and adjacent free space leaves the free page untracked and never registers it ing.protected, preventing future allocations into that free region from faulting intoon_writewhileGUARDSis held.
Verification
cargo xtask policy:191 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.- RTX 5090 +
VICTORY_D3D12_DEBUG=1:watch::16 passed, 0 failed (includingfree_memory_is_not_trackedatwatch.rs:1049). - WARP +
--features diagnostics+VICTORY_D3D12_DEBUG=1:watch::16 passed, 0 failed. - Additional probe on both RTX 5090 and WARP verifying: (1) a 128 KiB
MEM_FREErange returnsNonefromtrack_copy, (2) a mixed[MEM_RESERVE 64 KiB | MEM_FREE 64 KiB]range tracks page 0 and puts page 1 inuntrackedwithout ever inserting page 1 intog.protected, (3) committing plainPAGE_READWRITEmemory at that formerly free page 1 and writing to it while holdingguards()completes with no fault or deadlock, and (4) a write-watched pool remains 100% tracked with zero untracked bytes.
Under Wine/Proton,
mainat70564aestops at the end of loading or just after entering the world: no frames, no audio, the title idle, no GPU fault. Six of six runs here (RX 6800 XT, RADV, GE-Proton11-14). This is the cause and a one-condition fix.What happens
shadow::loose()makes a 4 MiB window copy for an address outside every known buffer. For a null address that window is0x0..0x400000, andShadow::newaskswatch::track(0, 4 MiB, true)to track it.runtime_memory(0, true)accepts it:GetWriteWatchfails, and the view test is "anything but committed private memory", which free memory (MEM_FREE) passes.VirtualProtectcalls just fail (I haven't checked on Windows). Under Wine the process heap lives there (here, heap writes faulted on guarded blocks from0x140000to0x260000), and its pages become read-only.on_write. When the faulting thread already holdsGUARDS(it allocates insideTracked::take,writing(), oron_writeitself),on_writewaits for the lock its own thread holds, forever. Audio (apu::XApuEnqueueCommand), GPU submission (Host::execute→Tracked::take) and the title's workers then queue behind it.Evidence
xmem::map_alias→watch::title_memory_remappedfaulting intoon_write→Mutex::lock_contended; others waiting inon_write(audio) andTracked::take(GPU submission).GUARDSlogged faults at0x1400d8(RtlEnterCriticalSectionon the process heap's lock) and0x1de770(ucrtbasememcpyinto the heap), with the lock taken inTracked::take,writing()andon_write. With those faults let through, the title ran 5 minutes in the world.track():0x0+0x400000fromshadow.rs:205,VirtualQuerystate0x10000(MEM_FREE).The change
runtime_memoryalso requiresState != MEM_FREE. Placeholders and views, which it is meant to accept, are reserved or mapped, never free. New testfree_memory_is_not_tracked(track(0, 4 MiB, true)isNone): it fails without the change and passes with it. All 7watchtests pass under Wine.In the title
70564ae+ the watchdog hook (#454) + three of #994's Proton commits (4828716,e5a8c2f,d469fe9), shaders and pipelines precached withtranslate --cache --pipelines, RX 6800 XT, RADV / Mesa 26.2.6, GE-Proton11-14:With it, the opening renders: sky, skyline, characters and credits, 2,500–3,600 draws per frame, 4.8–6.2 s per frame. One of the three runs ended at 5 minutes in an access violation in title code (
+0x35a4245, reading-1, no VIctory frames on the stack); the other two didn't, so I take it to be unrelated.Not tested on Windows. The change only turns away free memory, so there it should only mean fewer
VirtualProtectcalls that fail anyway.AI-assisted (Claude Code). No game data attached.