RADV/Wine: world frame CPU-bound on title-memory traffic — copies in at ~107 MB/s, shader write-back at ~26 MB/s, GPU 2-6% busy #118

Open
opened 2026-11-26 03:36:26 +00:00 by github-bot · 4 comments
Owner

@⁠DaviTostes on GitHub · 2026-11-24 21:38 UTC · original

RADV/Wine: the world frame is CPU-bound on title-memory traffic — copies in at ~107 MB/s, shader write-back at ~26 MB/s, GPU 2–6% busy

Setup: RX 9060 XT (RDNA4, GFX1200, 16 GB), Mesa 26.3.1 RADV, Arch kernel 7.3.5, Ryzen 5 5500, 16 GB RAM. System Wine 11.22 with Proton Experimental's vkd3d-proton 3.2.0 and DXVK 3.1.1 dxgi, WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n", VICTORY_NO_WATCHDOG=1 (upstream #454), VICTORY_TEXTURE_NO_WAIT=1.

Build: main 4e17478 + #20 (DXC fallback) + #454. DXC is required: without it Wine's d3dcompiler_47 refuses InterlockedMax/Load4 on RWByteAddressBuffer, every indirect execution is dropped and the world stays black. With it the prologue presents a lit scene (6 100–8 400 draws/frame), so this is about speed, not the picture.

Numbers from the frame line

Five world samples (>=500 draws) in one run:

median max
frame 4 183 ms 7 219 ms
preparing 2 436 ms 3 057 ms
copies into title memory 1 346 ms / 137.7 MB (107 MB/s) 2 221 ms / 184.8 MB
textures 215 ms / 13.8 MB 1 191 ms / 85.5 MB
GPU time 163 ms 207 ms
copying back (shader-written ranges compared and written into title memory) 1 314 ms / 34.2 MB (26 MB/s) 1 702 ms / 46.3 MB

The card clock agrees that the card is not the limit:

INFO victory_gpu::host: the card's clock per frame: nothing of ours queued 7070.5 ms (the card about 2% busy by this count),
  4577.1 ms of that while the submitting thread was working (the card idle behind us)

Where it fits

  • This is the same shape as #41's RDNA3 numbers (copies at 60–100 MB/s), and it is roughly one order of magnitude below the ~1 GB/s Windows numbers in #10.
  • The write-back path is the worse half: 26 MB/s, and it runs while the card stands still (nothing of ours queued).
  • Threading the copies does not obviously help: VICTORY_WIDE_REFRESH=1 spreads a submission's refreshes but the flush still waits for all of them.
  • 16 GB of RAM here means the title's 2 GB storage plus windows are under pressure; the run is stable, it is just slow.

What I have not separated: whether the 107 MB/s is Wine's page-fault/ReadProcessMemory-style read of title memory, the vkd3d-proton mapping, or RADV's per-page cost. The write-back side looks like page faults on first touch of a mapped range.

If there is a switch worth trying (VICTORY_WIDE_REFRESH, VICTORY_JOIN_COPIES, VICTORY_TEXTURE_COPY, …) or a counter you would like captured, tell me and I will run it on this card and report back. Happy to test patches.

**@⁠DaviTostes** on GitHub · 2026-11-24 21:38 UTC · [original](https://github.com/fxceless/victory-fork/issues/118) RADV/Wine: the world frame is CPU-bound on title-memory traffic — copies in at ~107 MB/s, shader write-back at ~26 MB/s, GPU 2–6% busy **Setup:** RX 9060 XT (RDNA4, GFX1200, 16 GB), Mesa 26.3.1 RADV, Arch kernel 7.3.5, Ryzen 5 5500, 16 GB RAM. System Wine 11.22 with Proton Experimental's vkd3d-proton 3.2.0 and DXVK 3.1.1 `dxgi`, `WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"`, `VICTORY_NO_WATCHDOG=1` (upstream #454), `VICTORY_TEXTURE_NO_WAIT=1`. **Build:** `main` 4e17478 + #20 (DXC fallback) + #454. DXC is required: without it Wine's `d3dcompiler_47` refuses `InterlockedMax`/`Load4` on `RWByteAddressBuffer`, every indirect execution is dropped and the world stays black. With it the prologue presents a lit scene (6 100–8 400 draws/frame), so this is about speed, not the picture. ## Numbers from the frame line Five world samples (>=500 draws) in one run: | | median | max | |---|---:|---:| | frame | 4 183 ms | 7 219 ms | | preparing | 2 436 ms | 3 057 ms | | copies into title memory | 1 346 ms / 137.7 MB (**107 MB/s**) | 2 221 ms / 184.8 MB | | textures | 215 ms / 13.8 MB | 1 191 ms / 85.5 MB | | GPU time | 163 ms | 207 ms | | `copying back` (shader-written ranges compared and written into title memory) | 1 314 ms / 34.2 MB (**26 MB/s**) | 1 702 ms / 46.3 MB | The card clock agrees that the card is not the limit: ``` INFO victory_gpu::host: the card's clock per frame: nothing of ours queued 7070.5 ms (the card about 2% busy by this count), 4577.1 ms of that while the submitting thread was working (the card idle behind us) ``` ## Where it fits - This is the same shape as #41's RDNA3 numbers (copies at 60–100 MB/s), and it is roughly one order of magnitude below the ~1 GB/s Windows numbers in #10. - The write-back path is the worse half: 26 MB/s, and it runs while the card stands still (nothing of ours queued). - Threading the copies does not obviously help: `VICTORY_WIDE_REFRESH=1` spreads a submission's refreshes but the flush still waits for all of them. - 16 GB of RAM here means the title's 2 GB storage plus windows are under pressure; the run is stable, it is just slow. What I have not separated: whether the 107 MB/s is Wine's page-fault/`ReadProcessMemory`-style read of title memory, the vkd3d-proton mapping, or RADV's per-page cost. The write-back side looks like page faults on first touch of a mapped range. If there is a switch worth trying (`VICTORY_WIDE_REFRESH`, `VICTORY_JOIN_COPIES`, `VICTORY_TEXTURE_COPY`, …) or a counter you would like captured, tell me and I will run it on this card and report back. Happy to test patches.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:26 +00:00
Author
Owner

@⁠HenriqueSBueno on GitHub · 2026-11-24 21:44 UTC · original

A likely reason these two rates are so low under Wine specifically: the copy paths go through the kernel's cross-process memory API even though source and destination are in our own process. host.rs:5418 reads with ReadProcessMemory(GetCurrentProcess(), …) and host.rs:5454 writes with WriteProcessMemory, piece by piece. On Windows that is a syscall per piece. Under Wine, NtReadVirtualMemory/NtWriteVirtualMemory are served by a round trip through wineserver, which then reads or writes the target process's memory itself. So every 64 KiB piece costs an IPC round trip plus a server-side copy, which fits ~107 MB/s in and ~26 MB/s back with the GPU 2–6 % busy.

On native Windows (RTX 3080) we measured the same two terms at roughly 270 MB in ~440 ms and ~12 MB back in ~330 ms per world frame. They are slow there too, but several times faster than your numbers.

What we'd try, in order (they are H-1.2, H-2.1, H-2.3 and H-7.7 in the dossier linked from Marvisak/VIctory#1317):

  1. Copy in-process directly, guarded by SEH or a vectored handler for pages that may be unmapped, instead of Read/WriteProcessMemory. This removes the per-piece syscall, and under Wine the wineserver round trip.
  2. Copy disjoint dirty ranges instead of one [min, max] span per shadow.
  3. Copy back only buffers the CPU actually reads, lazily, through read guards.

Item 1 alone should show up directly in your copies and copying back MB/s, and more on Wine than on Windows.

AI-assisted (Claude Code)

**@⁠HenriqueSBueno** on GitHub · 2026-11-24 21:44 UTC · [original](https://github.com/fxceless/victory-fork/issues/118#issuecomment-7145332314) A likely reason these two rates are so low under Wine specifically: the copy paths go through the kernel's cross-process memory API even though source and destination are in our own process. `host.rs:5418` reads with `ReadProcessMemory(GetCurrentProcess(), …)` and `host.rs:5454` writes with `WriteProcessMemory`, piece by piece. On Windows that is a syscall per piece. Under Wine, `NtReadVirtualMemory`/`NtWriteVirtualMemory` are served by a round trip through `wineserver`, which then reads or writes the target process's memory itself. So every 64 KiB piece costs an IPC round trip plus a server-side copy, which fits ~107 MB/s in and ~26 MB/s back with the GPU 2–6 % busy. On native Windows (RTX 3080) we measured the same two terms at roughly 270 MB in ~440 ms and ~12 MB back in ~330 ms per world frame. They are slow there too, but several times faster than your numbers. What we'd try, in order (they are H-1.2, H-2.1, H-2.3 and H-7.7 in the dossier linked from Marvisak/VIctory#1317): 1. Copy in-process directly, guarded by SEH or a vectored handler for pages that may be unmapped, instead of `Read/WriteProcessMemory`. This removes the per-piece syscall, and under Wine the wineserver round trip. 2. Copy disjoint dirty ranges instead of one `[min, max]` span per shadow. 3. Copy back only buffers the CPU actually reads, lazily, through read guards. Item 1 alone should show up directly in your `copies` and `copying back` MB/s, and more on Wine than on Windows. AI-assisted (Claude Code)
Author
Owner

@⁠BitWuehler on GitHub · 2026-11-24 21:56 UTC · original

Opened PR #154 implementing item 1 (AddVectoredExceptionHandler + in-process x86_64 rep movsb for read/read_into/copy_mapped and write_mapped, falling back cleanly on unmapped/PAGE_NOACCESS/PAGE_READONLY pages and delegating write faults through watch when a block is guarded; VICTORY_DIRECT_COPY=0 toggles it off).

Microbenchmark on 4e17478 under CachyOS Linux + GE-Proton11-14 wine (ntsync, Ryzen 7 9800X3D, release test binary, benchmark_direct_copy_vs_kernel_calls):

  • 256 MiB bulk read: ReadProcessMemory 12.66 ms (20,227 MB/s) vs direct_copy 10.55 ms (24,270 MB/s)
  • 1,000 x 64 KiB writes (62.5 MiB): NtWriteVirtualMemory 16.57 ms (3,771 MB/s) vs direct_copy 0.68 ms (91,241 MB/s, 24.4x faster)

All host::tests (13/13), watch::tests (6/6), shadow:: (19/19), and texture:: (2/2) pass under GE-Proton11-14. (Full in-world run and native Windows/RADV timing still pending; AI-assisted.)

**@⁠BitWuehler** on GitHub · 2026-11-24 21:56 UTC · [original](https://github.com/fxceless/victory-fork/issues/118#issuecomment-7145591853) Opened PR #154 implementing item 1 (`AddVectoredExceptionHandler` + in-process `x86_64` `rep movsb` for `read`/`read_into`/`copy_mapped` and `write_mapped`, falling back cleanly on unmapped/`PAGE_NOACCESS`/`PAGE_READONLY` pages and delegating write faults through `watch` when a block is guarded; `VICTORY_DIRECT_COPY=0` toggles it off). Microbenchmark on `4e17478` under CachyOS Linux + `GE-Proton11-14` `wine` (`ntsync`, Ryzen 7 9800X3D, release test binary, `benchmark_direct_copy_vs_kernel_calls`): - `256 MiB` bulk read: `ReadProcessMemory` `12.66 ms` (`20,227 MB/s`) vs `direct_copy` `10.55 ms` (`24,270 MB/s`) - `1,000 x 64 KiB` writes (`62.5 MiB`): `NtWriteVirtualMemory` `16.57 ms` (`3,771 MB/s`) vs `direct_copy` `0.68 ms` (`91,241 MB/s`, **24.4x faster**) All `host::tests` (`13/13`), `watch::tests` (`6/6`), `shadow::` (`19/19`), and `texture::` (`2/2`) pass under `GE-Proton11-14`. *(Full in-world run and native Windows/RADV timing still pending; AI-assisted.)*
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-25 01:00 UTC · original

Two experiments on that path, on the same card (RX 9060 XT, Mesa 26.3.1 RADV, Wine 11.22, main 4e17478 + #20 + #454):

1. Direct copy without the guard crashes, as the code's comments warned. VICTORY_COPY_MODE=plain (in-process memcpy) runs the menus but dies in the world and the title writes a Breakpad dump: the ranges being copied do contain unmapped pages, so a faster path cannot just memcpy.

2. Skipping holes a run at a time is not the lever. I reworked the fallback so a failed bulk read/write uses the kernel's own "how far did I get" count plus one VirtualQuery for the hole, instead of falling to 64 KiB (then 4 KiB) pieces. Result, world frames only:

copies copying back
before 738 MB in 6 890 ms = 107 MB/s 165 MB in 4 986 ms = 33 MB/s
holes skipped 906 MB in 18 816 ms = 48 MB/s 115 MB in 3 031 ms = 38 MB/s

The copy figures moved the wrong way and the write-back is inside the noise; the samples come from different scenes, so this is not a clean A/B, but it does say the time is per byte moved through wineserver, not per 64 KiB call. Skipping pieces saves round trips, and there were not enough of them to matter.

So item 1 looks like the only one that can matter here, and it needs a fault-safe guard. The clean one on this side may be the runtime's own page map rather than SEH: victory-hle's xmem keeps views: BTreeMap<usize, (usize, Slice)> for exactly the pages the title has mapped. If victory-gpu could ask it "where does the mapped run at this address end", the copy could memcpy run by run with no kernel call and no fault at all — under Wine that is the difference between a wineserver round trip per run and one per byte.

Would a small hook in that direction be something you would take? victory-gpu cannot depend on victory-hle, so it would be a registration (victory_hle hands victory_gpu a fn(start, len) -> Option<Vec<(usize, usize)>> at startup), used only by the copy paths. I can write it and measure it on this card.

**@⁠DaviTostes** on GitHub · 2026-11-25 01:00 UTC · [original](https://github.com/fxceless/victory-fork/issues/118#issuecomment-7149103491) Two experiments on that path, on the same card (RX 9060 XT, Mesa 26.3.1 RADV, Wine 11.22, `main` 4e17478 + #20 + #454): **1. Direct copy without the guard crashes, as the code's comments warned.** `VICTORY_COPY_MODE=plain` (in-process `memcpy`) runs the menus but dies in the world and the title writes a Breakpad dump: the ranges being copied do contain unmapped pages, so a faster path cannot just `memcpy`. **2. Skipping holes a run at a time is not the lever.** I reworked the fallback so a failed bulk read/write uses the kernel's own "how far did I get" count plus one `VirtualQuery` for the hole, instead of falling to 64 KiB (then 4 KiB) pieces. Result, world frames only: | | copies | copying back | |---|---:|---:| | before | 738 MB in 6 890 ms = **107 MB/s** | 165 MB in 4 986 ms = **33 MB/s** | | holes skipped | 906 MB in 18 816 ms = 48 MB/s | 115 MB in 3 031 ms = 38 MB/s | The copy figures moved the wrong way and the write-back is inside the noise; the samples come from different scenes, so this is not a clean A/B, but it does say the time is per byte moved through `wineserver`, not per 64 KiB call. Skipping pieces saves round trips, and there were not enough of them to matter. So item 1 looks like the only one that can matter here, and it needs a fault-safe guard. The clean one on this side may be the runtime's own page map rather than SEH: `victory-hle`'s xmem keeps `views: BTreeMap<usize, (usize, Slice)>` for exactly the pages the title has mapped. If `victory-gpu` could ask it "where does the mapped run at this address end", the copy could `memcpy` run by run with no kernel call and no fault at all — under Wine that is the difference between a wineserver round trip per run and one per byte. Would a small hook in that direction be something you would take? `victory-gpu` cannot depend on `victory-hle`, so it would be a registration (`victory_hle` hands `victory_gpu` a `fn(start, len) -> Option<Vec<(usize, usize)>>` at startup), used only by the copy paths. I can write it and measure it on this card.
Author
Owner

@⁠Ortomanic on GitHub · 2026-11-26 10:17 UTC · original

A Wine-side cause of slow title-memory traffic, with a patch: on this machine it took the world frame from 105–113 ms to 76–91 ms.

Setup: RTX 5080 16 GB, Ryzen 7 9800X3D, 60 GB RAM, CachyOS kernel 7.3.5, NVIDIA 620.73.04, vkd3d-proton 3.1, Wine 11.22 built from source. Series S profile. The build measured is the Neptune VE tree (a descendant of this fork by way of avatarmanz/VIctory-7900XTX), not main, so treat the numbers as that tree's.

What the profile showed. perf (user space) over 40 s of a settled world scene:

  • wineserver took 7.7 % of all samples, about half a core of a single-threaded process.
  • 94.5 % of that was in two functions of server/mapping.c: is_valid_view_addr (49.3 %) and req_unmap_view (45.2 %).
  • Both walk the process's list of memory views from the start. The process had about 37,000 mappings, and the runtime maps and unmaps views of title memory all the time, so every such call paid a walk of that list while the calling thread waited for the server.

The patch keeps the views in a red-black tree by base address beside the existing list (the list stays for load order). Lookup by base, lookup by an address inside a view, and the overlap check for a new view become tree descents. It is against Wine 11.22 and touches only server/.

Result, alternating runs from the same restored save, 5,000–7,000 draws a frame:

Wine frame (two runs) copying back
11.22 105 ms, 113 ms 57 ms, 61 ms
11.22 + patch 76 ms, 91 ms 25 ms, 30 ms

After the patch wineserver no longer shows among the busy threads. A 9-minute run with it had no fault. Runs at the same settings still spread by about 15 ms, so two runs a side is a direction, not a precise figure.

Two related notes.

  • Wine 11.22 already answers GetWriteWatch through userfaultfd (USE_UFFD_WRITEWATCH in dlls/ntdll/unix/virtual.c), so write-watch askings are not a signal storm here: virtual_handle_fault was 0.04 % of samples.
  • On NVIDIA, VKD3D_CONFIG=no_upload_hvv (upload heaps in system memory instead of host-visible VRAM) gave 104 ms against 125 ms in one pair of runs, and halved the copy-back time. One pair only.

Not checked: main itself, RADV, and Proton's Wine (which may differ in server/mapping.c). If someone on RADV can try the patch, the question in this issue is whether the same list walk is behind the 26 MB/s write-back.

The patch (Wine 11.22, server/)
--- a/server/mapping.c	2026-11-26 04:28:21.431230445 +0100
+++ b/server/mapping.c	2026-11-26 04:28:40.103389606 +0100
@@ -98,6 +98,7 @@
 struct memory_view
 {
     struct list     entry;           /* entry in per-process view list */
+    struct rb_entry tree_entry;      /* entry in per-process tree of views by base (compat-lab) */
     struct fd      *fd;              /* fd for mapped file */
     struct ranges  *committed;       /* list of committed ranges in this mapping */
     struct shared_map *shared;       /* temp file for shared PE mapping */
@@ -384,13 +385,49 @@
     return fd;
 }
 
+/* compat-lab: a process with tens of thousands of section views (a console title's memory,
+ * remapped all the time) spent half a core of the server walking the list for every map and
+ * unmap. The views are also kept in a tree by base address; they never overlap. */
+static int view_compare( const void *key, const struct rb_entry *entry )
+{
+    const struct memory_view *view = RB_ENTRY_VALUE( entry, const struct memory_view, tree_entry );
+    client_ptr_t base = *(const client_ptr_t *)key;
+
+    if (base < view->base) return -1;
+    if (base > view->base) return 1;
+    return 0;
+}
+
+void init_mapped_views( struct process *process )
+{
+    rb_init( &process->views_tree, view_compare );
+}
+
+/* the view with the highest base address not above addr */
+static struct memory_view *find_view_below( struct process *process, client_ptr_t addr )
+{
+    struct rb_entry *entry = process->views_tree.root;
+    struct memory_view *best = NULL;
+
+    while (entry)
+    {
+        struct memory_view *view = RB_ENTRY_VALUE( entry, struct memory_view, tree_entry );
+        if (addr < view->base) entry = entry->left;
+        else
+        {
+            best = view;
+            entry = entry->right;
+        }
+    }
+    return best;
+}
+
 /* find a memory view from its base address */
 struct memory_view *find_mapped_view( struct process *process, client_ptr_t base )
 {
-    struct memory_view *view;
+    struct rb_entry *entry = rb_get( &process->views_tree, &base );
 
-    LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry )
-        if (view->base == base) return view;
+    if (entry) return RB_ENTRY_VALUE( entry, struct memory_view, tree_entry );
 
     set_error( STATUS_NOT_MAPPED_VIEW );
     return NULL;
@@ -399,10 +436,9 @@
 /* find a memory view from any address inside it */
 static struct memory_view *find_mapped_addr( struct process *process, client_ptr_t addr )
 {
-    struct memory_view *view;
+    struct memory_view *view = find_view_below( process, addr );
 
-    LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry )
-        if (addr >= view->base && addr < view->base + view->size) return view;
+    if (view && addr < view->base + view->size) return view;
 
     set_error( STATUS_NOT_MAPPED_VIEW );
     return NULL;
@@ -417,13 +453,10 @@
     if (addr & (process->page_size - 1)) return 0;
     if (addr + size < addr) return 0;  /* overflow */
 
-    /* check for overlapping view */
-    LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry )
-    {
-        if (view->base + view->size <= addr) continue;
-        if (view->base >= addr + size) continue;
-        return 0;
-    }
+    /* check for overlapping view: views do not overlap one another, so only the last one
+     * that starts before the end of the range can reach into it */
+    view = find_view_below( process, addr + size - 1 );
+    if (view && view->base + view->size > addr) return 0;
     return 1;
 }
 
@@ -462,15 +495,19 @@
                 process->imagelen = name.len;
             process->image_info = view->image;
             list_add_head( &process->views, &view->entry );
+            rb_put( &process->views_tree, &view->base, &view->tree_entry );
             return 1;
         }
     }
     list_add_tail( &process->views, &view->entry );
+    rb_put( &process->views_tree, &view->base, &view->tree_entry );
     return 0;
 }
 
-static void free_memory_view( struct memory_view *view )
+static void free_memory_view( struct process *process, struct memory_view *view )
 {
+    if (rb_get( &process->views_tree, &view->base ) == &view->tree_entry)
+        rb_remove( &process->views_tree, &view->tree_entry );
     if (view->fd) release_object( view->fd );
     if (view->committed) release_object( view->committed );
     if (view->shared) release_object( view->shared );
@@ -484,7 +521,7 @@
     struct list *ptr;
 
     while ((ptr = list_head( &process->views )))
-        free_memory_view( LIST_ENTRY( ptr, struct memory_view, entry ));
+        free_memory_view( process, LIST_ENTRY( ptr, struct memory_view, entry ));
 }
 
 /* find the shared PE mapping for a given mapping */
@@ -1797,7 +1834,7 @@
 
     if (!view) return;
     generate_dll_event( current, DbgUnloadDllStateChange, view );
-    free_memory_view( view );
+    free_memory_view( current->process, view );
 }
 
 /* get information about a mapped image view */
--- a/server/process.h	2026-11-26 04:28:21.431632251 +0100
+++ b/server/process.h	2026-11-26 04:28:40.102284845 +0100
@@ -21,6 +21,7 @@
 #ifndef __WINE_SERVER_PROCESS_H
 #define __WINE_SERVER_PROCESS_H
 
+#include "wine/rbtree.h"
 #include "object.h"
 
 struct atom_table;
@@ -80,6 +81,7 @@
     obj_handle_t         desktop;         /* handle to desktop to use for new threads */
     struct token        *token;           /* security token associated with this process */
     struct list          views;           /* list of memory views */
+    struct rb_tree       views_tree;      /* the same views by base address (compat-lab) */
     client_ptr_t         peb;             /* PEB address in client address space */
     struct dir_cache    *dir_cache;       /* map of client-side directory cache */
     unsigned int         trace_data;      /* opaque data used by the process tracing mechanism */
--- a/server/process.c	2026-11-26 04:28:21.431981138 +0100
+++ b/server/process.c	2026-11-26 04:28:40.102476553 +0100
@@ -648,6 +648,7 @@
     list_init( &process->asyncs );
     list_init( &process->classes );
     list_init( &process->views );
+    init_mapped_views( process );
 
     process->end_time = 0;
 
--- a/server/file.h	2026-11-26 04:28:59.239321600 +0100
+++ b/server/file.h	2026-11-26 04:28:40.102557833 +0100
@@ -179,6 +179,7 @@
 extern struct file *get_view_file( const struct memory_view *view, unsigned int access, unsigned int sharing );
 extern const struct pe_image_info *get_view_image_info( const struct memory_view *view, client_ptr_t *base );
 extern int get_view_nt_name( const struct memory_view *view, struct unicode_str *name );
+extern void init_mapped_views( struct process *process );
 extern void free_mapped_views( struct process *process );
 extern size_t get_page_size(void);
 extern struct mapping *create_fd_mapping( struct object *root, struct unicode_str name, struct fd *fd,

AI-assisted (Claude Code): profiling, the patch and this text. Counts and timings only; nothing from the game attached.

**@⁠Ortomanic** on GitHub · 2026-11-26 10:17 UTC · [original](https://github.com/fxceless/victory-fork/issues/118#issuecomment-7189169991) A Wine-side cause of slow title-memory traffic, with a patch: on this machine it took the world frame from 105–113 ms to 76–91 ms. **Setup:** RTX 5080 16 GB, Ryzen 7 9800X3D, 60 GB RAM, CachyOS kernel 7.3.5, NVIDIA 620.73.04, vkd3d-proton 3.1, Wine 11.22 built from source. Series S profile. The build measured is the Neptune VE tree (a descendant of this fork by way of avatarmanz/VIctory-7900XTX), not `main`, so treat the numbers as that tree's. **What the profile showed.** `perf` (user space) over 40 s of a settled world scene: - `wineserver` took 7.7 % of all samples, about half a core of a single-threaded process. - 94.5 % of that was in two functions of `server/mapping.c`: `is_valid_view_addr` (49.3 %) and `req_unmap_view` (45.2 %). - Both walk the process's list of memory views from the start. The process had about 37,000 mappings, and the runtime maps and unmaps views of title memory all the time, so every such call paid a walk of that list while the calling thread waited for the server. **The patch** keeps the views in a red-black tree by base address beside the existing list (the list stays for load order). Lookup by base, lookup by an address inside a view, and the overlap check for a new view become tree descents. It is against Wine 11.22 and touches only `server/`. **Result,** alternating runs from the same restored save, 5,000–7,000 draws a frame: | Wine | frame (two runs) | copying back | |---|---|---| | 11.22 | 105 ms, 113 ms | 57 ms, 61 ms | | 11.22 + patch | 76 ms, 91 ms | 25 ms, 30 ms | After the patch `wineserver` no longer shows among the busy threads. A 9-minute run with it had no fault. Runs at the same settings still spread by about 15 ms, so two runs a side is a direction, not a precise figure. **Two related notes.** - Wine 11.22 already answers `GetWriteWatch` through userfaultfd (`USE_UFFD_WRITEWATCH` in `dlls/ntdll/unix/virtual.c`), so write-watch askings are not a signal storm here: `virtual_handle_fault` was 0.04 % of samples. - On NVIDIA, `VKD3D_CONFIG=no_upload_hvv` (upload heaps in system memory instead of host-visible VRAM) gave 104 ms against 125 ms in one pair of runs, and halved the copy-back time. One pair only. **Not checked:** `main` itself, RADV, and Proton's Wine (which may differ in `server/mapping.c`). If someone on RADV can try the patch, the question in this issue is whether the same list walk is behind the 26 MB/s write-back. <details> <summary>The patch (Wine 11.22, <code>server/</code>)</summary> ```diff --- a/server/mapping.c 2026-11-26 04:28:21.431230445 +0100 +++ b/server/mapping.c 2026-11-26 04:28:40.103389606 +0100 @@ -98,6 +98,7 @@ struct memory_view { struct list entry; /* entry in per-process view list */ + struct rb_entry tree_entry; /* entry in per-process tree of views by base (compat-lab) */ struct fd *fd; /* fd for mapped file */ struct ranges *committed; /* list of committed ranges in this mapping */ struct shared_map *shared; /* temp file for shared PE mapping */ @@ -384,13 +385,49 @@ return fd; } +/* compat-lab: a process with tens of thousands of section views (a console title's memory, + * remapped all the time) spent half a core of the server walking the list for every map and + * unmap. The views are also kept in a tree by base address; they never overlap. */ +static int view_compare( const void *key, const struct rb_entry *entry ) +{ + const struct memory_view *view = RB_ENTRY_VALUE( entry, const struct memory_view, tree_entry ); + client_ptr_t base = *(const client_ptr_t *)key; + + if (base < view->base) return -1; + if (base > view->base) return 1; + return 0; +} + +void init_mapped_views( struct process *process ) +{ + rb_init( &process->views_tree, view_compare ); +} + +/* the view with the highest base address not above addr */ +static struct memory_view *find_view_below( struct process *process, client_ptr_t addr ) +{ + struct rb_entry *entry = process->views_tree.root; + struct memory_view *best = NULL; + + while (entry) + { + struct memory_view *view = RB_ENTRY_VALUE( entry, struct memory_view, tree_entry ); + if (addr < view->base) entry = entry->left; + else + { + best = view; + entry = entry->right; + } + } + return best; +} + /* find a memory view from its base address */ struct memory_view *find_mapped_view( struct process *process, client_ptr_t base ) { - struct memory_view *view; + struct rb_entry *entry = rb_get( &process->views_tree, &base ); - LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry ) - if (view->base == base) return view; + if (entry) return RB_ENTRY_VALUE( entry, struct memory_view, tree_entry ); set_error( STATUS_NOT_MAPPED_VIEW ); return NULL; @@ -399,10 +436,9 @@ /* find a memory view from any address inside it */ static struct memory_view *find_mapped_addr( struct process *process, client_ptr_t addr ) { - struct memory_view *view; + struct memory_view *view = find_view_below( process, addr ); - LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry ) - if (addr >= view->base && addr < view->base + view->size) return view; + if (view && addr < view->base + view->size) return view; set_error( STATUS_NOT_MAPPED_VIEW ); return NULL; @@ -417,13 +453,10 @@ if (addr & (process->page_size - 1)) return 0; if (addr + size < addr) return 0; /* overflow */ - /* check for overlapping view */ - LIST_FOR_EACH_ENTRY( view, &process->views, struct memory_view, entry ) - { - if (view->base + view->size <= addr) continue; - if (view->base >= addr + size) continue; - return 0; - } + /* check for overlapping view: views do not overlap one another, so only the last one + * that starts before the end of the range can reach into it */ + view = find_view_below( process, addr + size - 1 ); + if (view && view->base + view->size > addr) return 0; return 1; } @@ -462,15 +495,19 @@ process->imagelen = name.len; process->image_info = view->image; list_add_head( &process->views, &view->entry ); + rb_put( &process->views_tree, &view->base, &view->tree_entry ); return 1; } } list_add_tail( &process->views, &view->entry ); + rb_put( &process->views_tree, &view->base, &view->tree_entry ); return 0; } -static void free_memory_view( struct memory_view *view ) +static void free_memory_view( struct process *process, struct memory_view *view ) { + if (rb_get( &process->views_tree, &view->base ) == &view->tree_entry) + rb_remove( &process->views_tree, &view->tree_entry ); if (view->fd) release_object( view->fd ); if (view->committed) release_object( view->committed ); if (view->shared) release_object( view->shared ); @@ -484,7 +521,7 @@ struct list *ptr; while ((ptr = list_head( &process->views ))) - free_memory_view( LIST_ENTRY( ptr, struct memory_view, entry )); + free_memory_view( process, LIST_ENTRY( ptr, struct memory_view, entry )); } /* find the shared PE mapping for a given mapping */ @@ -1797,7 +1834,7 @@ if (!view) return; generate_dll_event( current, DbgUnloadDllStateChange, view ); - free_memory_view( view ); + free_memory_view( current->process, view ); } /* get information about a mapped image view */ --- a/server/process.h 2026-11-26 04:28:21.431632251 +0100 +++ b/server/process.h 2026-11-26 04:28:40.102284845 +0100 @@ -21,6 +21,7 @@ #ifndef __WINE_SERVER_PROCESS_H #define __WINE_SERVER_PROCESS_H +#include "wine/rbtree.h" #include "object.h" struct atom_table; @@ -80,6 +81,7 @@ obj_handle_t desktop; /* handle to desktop to use for new threads */ struct token *token; /* security token associated with this process */ struct list views; /* list of memory views */ + struct rb_tree views_tree; /* the same views by base address (compat-lab) */ client_ptr_t peb; /* PEB address in client address space */ struct dir_cache *dir_cache; /* map of client-side directory cache */ unsigned int trace_data; /* opaque data used by the process tracing mechanism */ --- a/server/process.c 2026-11-26 04:28:21.431981138 +0100 +++ b/server/process.c 2026-11-26 04:28:40.102476553 +0100 @@ -648,6 +648,7 @@ list_init( &process->asyncs ); list_init( &process->classes ); list_init( &process->views ); + init_mapped_views( process ); process->end_time = 0; --- a/server/file.h 2026-11-26 04:28:59.239321600 +0100 +++ b/server/file.h 2026-11-26 04:28:40.102557833 +0100 @@ -179,6 +179,7 @@ extern struct file *get_view_file( const struct memory_view *view, unsigned int access, unsigned int sharing ); extern const struct pe_image_info *get_view_image_info( const struct memory_view *view, client_ptr_t *base ); extern int get_view_nt_name( const struct memory_view *view, struct unicode_str *name ); +extern void init_mapped_views( struct process *process ); extern void free_mapped_views( struct process *process ); extern size_t get_page_size(void); extern struct mapping *create_fd_mapping( struct object *root, struct unicode_str name, struct fd *fd, ``` </details> AI-assisted (Claude Code): profiling, the patch and this text. Counts and timings only; nothing from the game attached.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/fxceless--victory-fork#118
No description provided.