Linux under Wine: holes known from the runtime's placeholders, written pages asked of the kernel (PAGEMAP_SCAN) #475
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/475"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from avatarmanz/VIctory-7900XTX. Originally posted by fsrajner on 2026-11-27T16:20:36Z.
Two changes for Linux under Wine (Proton). They complement #440: that PR takes Wine's server out of mapping title pages; this one takes Wine out of asking what the title wrote. Measured on an RX 9070 XT with RADV, Proton Experimental (Wine 11) and vkd3d-proton.
Under Wine, the thread that submits the title's work spent about 30% of its time in Wine's emulation of memory queries, all under Wine's one virtual-memory lock:
1. Holes of the runtime's own placeholders are known without asking the system
Wine does not answer
NtQueryVirtualMemorywithMemoryRegionInformationEx(class 7), sowatch::placeholder()always said no under Wine. As a result:VirtualQuerycalls a frame);Three
watchtests fail under Wine for this reason:holes_are_known_until_the_runtime_tells,no_mapping_is_lost_between_askersandwhat_is_left_alone_is_no_known_hole.The fix:
xmemtells the GPU side of its placeholder reservations (title_memory_placeholder).placeholder()answers from that, plus the block's state, and asks the system only about other memory.watchtests register their placeholders the wayxmemdoes. All 51 pass under Wine.This is correct on Windows too. There, the answer is the same as the system's.
2. Written pages asked of the kernel directly (
PAGEMAP_SCAN). Wine only, opt-inProton already keeps
MEM_WRITE_WATCHmemory write-protected with userfaultfd in asynchronous mode, and answersGetWriteWatchwith thePAGEMAP_SCANioctl. The runtime now makes that ioctl itself, which avoids Wine's lock and its bookkeeping.wine.rs:WINE_HACK_NATIVE_SYSCALLS=1lets system calls through from code at 0x7001_0000_0000 and above, so a small stub is copied there.VICTORY_LINUX_SYSCALLS=1.getpidcompared with/proc/self/statread natively. Wine opens files in its server, soZ:\proc\selfis the server's, not ours.pagemap.rs:VICTORY_LINUX_SCAN=1.kernel_written()usesPAGEMAP_SCANwithPM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC, which asks and re-protects in one step.xmem,upload). Anything else is asked as before, so no scan can stop part way after re-protecting.texture::committedanswers from the views the runtime mapped, since sections are committed whole there (VICTORY_COMMITTED_BY_VIEWS).VICTORY_THREAD_TIMES), because each one is a costly trip under Wine.VICTORY_AHEAD_GAP_KIBandVICTORY_AHEAD_MAX_MIB.Everything is behind
on_wine()or a switch, so nothing changes on Windows.Measured
Setup:
VICTORY_LINUX_SYSCALLS=1 VICTORY_LINUX_SCAN=1 WINE_HACK_NATIVE_SYSCALLS=1)Hole questions dropped from about 2,500–4,300 to about 40–100 a frame.
Caveat: these runs had renderer port 1 on, which gives a black picture under RADV (#440's
VICTORY_PORT_HOMEaddresses that). Both changes are on the CPU side and do the same work either way. With port 1 off and a picture, the game ran 400 world frames at 145 ms/frame on the same machine, with ray tracing and FSR 4, while another VM was loading the host.Tests
All tests below ran under Wine (Proton Experimental):
watch::(51),pagemap::,wine::,inplace,shadow::,relay_tests,queue,texture: 134 passed, with the new switches both on and off.🤖 Generated with Claude Code
Imported from avatarmanz/VIctory-7900XTX. Originally posted by UwUCammie on 2026-11-27T16:49:42Z.
One fallback case stood out in
pagemap::written. If an earlyPAGEMAP_SCANbatch returns pages and re-protects them, a later error drops the accumulatedpagesand falls back toGetWriteWatch. The fallback can miss those pages because their written state was already reset. The kernel can also apply protection changes to part of one scan before it encounters a VMA that failsPM_SCAN_CHECK_WPASYNC.Could the fallback conservatively include the affected prefix, or refresh the entire watched span when a mutating scan fails? The Linux documentation calls out partial walks. Kernel docs
I tried the gap knob separately from the native scan. A generated fixture on this Wine 11.22 host returns the same two dirty pages with either one joined
GetWriteWatchcall or two narrow calls. At a 1 MiB clean gap, the medians were 1.14 µs joined and 2.09 µs split. At 8 MiB, they were 2.32 µs joined and 2.10 µs split. I’ve queued an 8 MiB versus 1 MiB comparison in the full cold 720p run. The generated fixture measures two sparse writes, so this leaves the gameplay effect open. Probe and setupView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.