Skip to content

GPU: free memory is not the runtime's to watch (fixes a world-load deadlock under Wine) - #1849

Open
crashbashash wants to merge 1 commit into
Marvisak:mainfrom
crashbashash:fix/watch-free-memory
Open

crashbashash wants to merge 1 commit into
Marvisak:mainfrom
crashbashash:fix/watch-free-memory

Conversation

@crashbashash

Copy link
Copy Markdown

Under Wine/Proton, main at 70564ae stops 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

  1. shadow::loose() makes a 4 MiB window copy for an address outside every known buffer. For a null address that window is 0x0..0x400000, and Shadow::new asks watch::track(0, 4 MiB, true) to track it.
  2. runtime_memory(0, true) accepts it: GetWriteWatch fails, and the view test is "anything but committed private memory", which free memory (MEM_FREE) passes.
  3. The window's blocks get guarded. On Windows there is usually nothing committed below 4 MiB, so the VirtualProtect calls just fail (I haven't checked on Windows). Under Wine the process heap lives there (here, heap writes faulted on guarded blocks from 0x140000 to 0x260000), and its pages become read-only.
  4. From then on, any heap write faults into on_write. When the faulting thread already holds GUARDS (it allocates inside Tracked::take, writing(), or on_write itself), on_write waits 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

  • Stacks taken from outside the process (gdb; in-process dumpers hang on this lock), unwound on the Windows side and symbolized with the build's PDB: a title thread in xmem::map_alias → watch::title_memory_remapped faulting into on_write → Mutex::lock_contended; others waiting in on_write (audio) and Tracked::take (GPU submission).
  • A local diagnostic build that detects a write fault on a thread holding GUARDS logged faults at 0x1400d8 (RtlEnterCriticalSection on the process heap's lock) and 0x1de770 (ucrtbase memcpy into the heap), with the lock taken in Tracked::take, writing() and on_write. With those faults let through, the title ran 5 minutes in the world.
  • Logged at track(): 0x0+0x400000 from shadow.rs:205, VirtualQuery state 0x10000 (MEM_FREE).

The change

runtime_memory also requires State != MEM_FREE. Placeholders and views, which it is meant to accept, are reserved or mapped, never free. New test free_memory_is_not_tracked (track(0, 4 MiB, true) is None): it fails without the change and passes with it. All 7 watch tests pass under Wine.

In the title

70564ae + the watchdog hook (#454) + three of #994's Proton commits (4828716, e5a8c2f, d469fe9), shaders and pipelines precached with translate --cache --pipelines, RX 6800 XT, RADV / Mesa 26.2.6, GE-Proton11-14:

runs reached the world stalled
without this change 6 1 6 (five at the end of loading, one seconds after entering)
with this change 3 3 0 (5 min in the world each: two stopped by me, one ended in the crash below)

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 VirtualProtect calls that fail anyway.

AI-assisted (Claude Code). No game data attached.

A loose copy of title memory for a null address covers 0..4 MiB, and
`runtime_memory` took that free memory for a view or placeholder, so the
window was tracked and its blocks guarded. On Windows nothing is
committed there and the guards fail. 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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astrosteveo

Copy link
Copy Markdown

Tested on an RTX 5080, Wine 11.22, on 940d32f plus open PRs. free_memory_is_not_tracked fails without the change and passes with it, in MinGW and MSVC builds.

I forced the hang by allocating plain memory at 0x200000 after track(0, 4 MiB): it became read-only, and a write with the guard lock held never returned. With the change it stays writable.

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 checks only the first page, so private committed memory later in a range that starts in a reservation is still guarded (shown with a synthetic test; I don't know if the title hits it). Not tested: Windows, the title. AI-assisted (Claude).

crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 25, 2026
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.
@coil111

coil111 commented Nov 25, 2026

Copy link
Copy Markdown

Tested on Linux/Proton with an AMD RDNA4 card: without this PR, current main freezes at the end of loading in the same way the description says; with it, the title reaches the world and keeps running.

Setup: RX 9070 XT (RDNA4), Mesa RADV, Gentoo, kernel 7.3.4, 64 GB RAM. Proton Experimental experimental-11.0-20261112 (its Wine; vkd3d-proton 2576c0b4a; DXVK dxgi). Diagnostics build of main 940d32f, cross-built with cargo-xwin (x86_64-pc-windows-msvc). Title 1.0.2.1, Series X, pipelines prebuilt with translate --cache --pipelines.

What the freeze looked like here (940d32f alone):

  • The log stops mid-load, with no error, no exception and no GPU fault. The kernel log shows no amdgpu reset either.
  • The process is still alive: ~22 GB resident, 96 threads, all of them idle (no CPU time over several seconds).
  • The window title (frame rate and draw count) stopped updating at the same moment the log did.
  • winedbg could not attach to the process (error 87), so I have no stacks of my own. The symptoms match the description, but I have not shown it is the same lock.

With this pr the 7 watch tests pass under this Wine (cargo xwin test -p victory-gpu -- watch, Wine as the runner), including the new free_memory_is_not_tracked. In the title, the run went from loading into the world without stopping.

crashbashash added a commit to crashbashash/VIctory-proton that referenced this pull request Nov 25, 2026
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.
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
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>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

runtime_memory in crates/victory-gpu/src/watch.rs now also rejects MEM_FREE. Before, free memory passed the "anything but committed private" view test. So a loose shadow window around a null address (0..4 MiB) got guarded, and under Wine that is where the process heap sits. Heap writes from a thread already holding GUARDS then deadlock in on_write. The trace in the description matches the code. Placeholders and views are reserved or mapped, never free, so the memory this is meant to track still passes. A window that is free when tracked is now copied whole each time instead of watched, which is slower but correct. The test checks the track(0, 4 MiB, true) case. CI: not run on this head.


Generated by Claude Code

@crashbashash

Copy link
Copy Markdown
Author

Thanks for testing this on NVIDIA, and for the gap.

You're right: runtime_memory looks only at the first page, so a range that starts in a reservation with plain committed memory further in is still guarded. That's older than this PR, so I've kept the fix separate to leave this one as reviewed: #2345 checks every region of the range, with your case as a test (a reserved block plus a committed one is refused; the reserved block alone is still tracked).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants