memory_traps=1 does, but with no alias pool and so no mirror
(SNX_PLAT_TRAPS_IN_PLACE, plat_win32.c); memory_traps 0 and 1 both mean this there, and 2 none.
VirtualAlloc reservation with the write watch, and a view of mapped memory (MapMemory, code
memory) is a copy, so a page has one address the CPU can reach. Owned memory stays the reservation's own pages
(mem_own_prepare without the pool: one run, its "pool offset" its address). mem.c lands what it copies under its
lock first (a copy view written back, code memory mapped or unmapped), as it can't fault there.plat_trap_arm marks the pages in a bitmap (a bit per 4 KiB page of the reservation) and makes them
PAGE_NOACCESS. A vectored exception handler, first in the chain (the crash handlers leave armed pages alone),
takes an access violation on an armed page (ExceptionInformation[1] the address, [0] read or write) on the
faulting thread, posts the page to the trap thread through the same lock-free ring as Linux's signal handler, and
waits (WaitOnAddress) until a trap lets pages go; then it continues execution, and the access goes again. A
fault on a page let go between the fault and the handler goes again; the same fault again with no page opened
since is no trap's, and goes on to the crash handlers, and so does one that faults 4096 times in a row while other
traps open pages (said once, with the page's state: an inaccessible page no trap holds is a bug). The trap
thread's own fault is never waited for. plat_thread_where says which threads wait in a trap, and where.plat_trap_fill opens them a page at a time, each just before its bytes go in, and let_go wakes the waiters. A
thread that touches a page while its bytes are going in, without faulting, can see it half written: the one
difference from the mirror's landing. The window is one page's memcpy, after a wait for the GPU of milliseconds
in which every other access faults and waits, so it takes a thread that first reaches the page in that very
moment: tests/memory_own.c's stress, eight threads reading 32 pages at random as fast as they can, starting while
the landing runs, finds about 25 of its 320,000 reads there, each the owner's byte once the landing is done. Each
page opened is a system call (opening an inaccessible page takes no TLB shootdown): a 2 MiB landing makes 512 of
them. Every entry on a page a landing opens lands with it (close_pages_nl), so no opened page shows an owner's
stale bytes. A page let go is written once (an atomic OR of 0), so the write watch reports it, as Linux's tracking
reports a page let go.own_stage reads the shadow; a page without one (bytes own_drop uncovered on a page an owner keeps) lands before
own_stage reads it. Neither a shadow's copy nor its read faults with a lock of ours held: the copy is taken with
ReadProcessMemory (plat_vm_read, which fails rather than faults), and a read of it goes through a buffer of the
thread's. The write watch's scan leaves armed pages out, and the landed pages' bytes that the write tracking
compares later (vk_ww_landed) are read with plat_vm_read too, as such a page may be trapped again or given
back.ReadFile into one and WriteFile from one with
ERROR_NOACCESS, Winsock with WSAEFAULT, as Linux's with EFAULT. The runtime acquires every range it hands
the kernel (below). Code in a system DLL that reads or writes guest memory in user mode (SDL's audio queue, OpenSSL,
WideCharToMultiByte) faults into the handler like the guest does.--vk-gpu-profile=1, the same 600 presents): 16.7 frames a second without traps, 54 to 55 with them. The GPU's
frame, first pass to last, 56.0 ms against 16.1; its dispatches and copies 19.7 ms against 6.4, the GPU mirror's
harvest 11.5 ms against 1.4. With --vk-buffer-stats=1 the mirror landed 47.7 GB in 600 presents without traps
(11.6 million pages written), 40 MB with them; storage images and the mirror's pages stay GPU-owned. What still
lands, about 1,000 times in 600 presents, is the movie's pictures: the native video service writes each one into
its image on the GPU (nvdec_write, NV12 at a pitch of 2048: 2.2 MB of luma and 1.1 MB of chroma), and the game's
CPU reads it, so on a discrete GPU it comes back. A GPU that shares memory writes them in place and lands nothing.
The screenshots match the run without traps. One run in about thirty stopped during loading (no frame for 15 s,
three guest threads at one light message queue, two of them waiting in a trap whose message the trap thread never
took: it was blocked in an earlier landing). It was not seen again in about thirty more runs, with empty shader
caches as the stopped run had, or with every thread's stack dumped when a stop came; the cause is not found.mach_vm_remap gives a mirror.Made from docs/layers/gpu/ownership.md at 69237645142c. GPL-3.0-or-later.