Stop reading title memory on the card with the CPU (hitches), stop VRAM creep #93

Manually merged
github merged 4 commits from github-bot/gh-93 into main 2026-12-01 20:58:42 +00:00 AGit
Owner

@⁠prinzjo on GitHub · 2026-12-01 18:41 UTC · original
prinzjo:perf/card-reads → main · +603 −19 · 8 files · 4 commits · merged 2026-12-01 20:55 UTC

The CPU reads VRAM through the BAR at ~100 MB/s (RX 7900 XTX + i7-13700K); texture/buffer refreshes doing that caused 100-3400 ms frames.

  • residency: our reads take pages back down; speculative 'seen' promotion opt-in (VICTORY_PAGES_SEEN=1), it filled VRAM at 8 MB/s
  • safecopy: rep movsb vs movntdqa picked by timing at startup
  • pull: reads >= 32 KiB on the card go by a GPU copy (40-65x faster, tests in pull::tests)
  • run.sh: warn when the RAM cap is under 12 GiB
    Measured: world frames 11 -> 36 fps, copy_ms 122 -> 11 ms (960p). Details in each commit.

Generated with assistance of Claude Code (Opus 5.5 xhigh)

**@⁠prinzjo** on GitHub · 2026-12-01 18:41 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93) `prinzjo:perf/card-reads` → `main` · +603 −19 · 8 files · 4 commits · merged 2026-12-01 20:55 UTC The CPU reads VRAM through the BAR at ~100 MB/s (RX 7900 XTX + i7-13700K); texture/buffer refreshes doing that caused 100-3400 ms frames. - residency: our reads take pages back down; speculative 'seen' promotion opt-in (VICTORY_PAGES_SEEN=1), it filled VRAM at 8 MB/s - safecopy: rep movsb vs movntdqa picked by timing at startup - pull: reads >= 32 KiB on the card go by a GPU copy (40-65x faster, tests in pull::tests) - run.sh: warn when the RAM cap is under 12 GiB Measured: world frames 11 -> 36 fps, copy_ms 122 -> 11 ms (960p). Details in each commit. Generated with assistance of Claude Code (Opus 5.5 xhigh)
The translator's own reads of title memory on the card (texture refreshes,
copies of buffers, through crate::host::read) never reached the residency:
pages it read kept their place on the card, and every read went through the
BAR at about 100 MB/s. read_through now marks each page of such a read (not
only the first) and is called from host::read's card path; write-combined
pools count too, and a page of one that comes down waits out its strikes
before it goes up again. At most 512 pages go down a wave (a wave holds
lazy::moving, which the title's first touches wait for), and only those
moved are struck.

Pages the card was shown and the title never touched (4442ec5) go up only
with VICTORY_PAGES_SEEN=1: "shown" takes in whole spans from what the card
reads by address (lazy::want_onward, up to 1 GiB). Run play-1201 (RX 7900
XTX) took 46,000 of them up, 2.9 GB at 8 MB/s for as long as it ran, while
the processor read 13.4 GB of title memory on the card in eight minutes, and
the budget left to textures' host copies shrank from 20.4 to 17.6 GB.

With the next commit, on an RX 7900 XTX and i7-13700K at 960p (the run
before also swapped, its RAM cap at 8.2 GiB): world frames 11.0 -> 35.8 fps,
copy_ms 122 -> 11, 5 s windows averaging over 100 ms a frame 41/64 -> 5/98.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
read_wc read title memory on the card by streaming loads (movntdqa) only.
On an i7-13700K with an RX 7900 XTX those read 59 MB/s on one thread and
24-28 MB/s with seven at once (the refreshes of shadow::wide_each), where
rep movsb read 87 and 97. How each fares depends on the processor, so
um::load times both on 2 MiB of card memory (four threads, three rounds
taking turns, best of each) and keeps the faster; a tie goes to rep movsb.
Said in the log: "the CPU reads the card's memory by ...".

safecopy::tests::both_ways_of_reading_card_memory_copy_alike checks that
both copy the same bytes at every length and alignment;
um::tests::card_read_speed (ignored) times them on the card.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
host::read read title memory on the card through the BAR, at about
100 MB/s however it is read. Reads of 32 KiB or more now go by a copy on a
copy queue of our own (beside the host's, so a copy waits for nothing its
lists do), from the mirror that shows the card title memory (um::mirror_at)
into a read-back buffer of the reading thread, 4 MiB at a time, and are
read from there. A part the card is not shown, a failed copy or a copy
that takes over 2 s leaves the read to the processor as before (the last
turns the copies off for the run). Pages read so stay where they are: the
card wanted them there. VICTORY_CARD_PULL=0 turns it off.

Measured on an RX 7900 XTX (pull::tests, ignored: it needs the card): a
copy waited for takes 0.05 ms however short, where the processor took
0.3 ms for 32 KiB, 89 ms for 4 MiB (copy 0.7 ms) and 126 ms for 12 MiB
(copy 2.5 ms); with another thread reading at the same time the
processor took 309 ms for 4 MiB, the copy 1.1 ms.

Why: after the residency took pages down once read, run play-1201-1751
still read 4.9 GB of title memory on the card by the processor. The
card asked for the pages again and they went up again (45,761 moves up and
37,894 down in fifteen minutes), and frames that read 20-60 MB of it took
100-370 ms.

The memory line says it: "... MiB copied back by the card (... s)".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cap is what is available less KEEP_FREE (8 GiB). With a desktop that
held much (a file indexer at 7 GB) it came to 8.2 GiB: both sessions of
play-1201 reached it and used all 2 GiB of their swap, and frames took
seconds. Play now says so before it starts, with the five largest users of
RAM, and that KEEP_FREE can go lower in run.conf (WANT_RAM sets the line).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 18:46:22 +00:00
Author
Owner

@⁠Daniel-Engelmann on GitHub · 2026-12-01 20:31 UTC · original

Tested this on an 9060 xt 16gb, 14600kf and it works great.
copy_ms 107ms -> 0.72-2.59ms.
worst frame 341 -> 32ms.
in world ~15 fps with constant hitches -> 27-42.

Thanks for the fix!

**@⁠Daniel-Engelmann** on GitHub · 2026-12-01 20:31 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93#issuecomment-7324837335) Tested this on an 9060 xt 16gb, 14600kf and it works great. copy_ms 107ms -> 0.72-2.59ms. worst frame 341 -> 32ms. in world ~15 fps with constant hitches -> 27-42. Thanks for the fix!
github-bot referenced this pull request from a commit 2026-12-01 20:58:42 +00:00
github manually merged commit 64d9aca407 into main 2026-12-01 20:58:42 +00:00
github-bot referenced this pull request from a commit 2026-12-01 21:04:22 +00:00
Author
Owner

@⁠EdouardSence on GitHub · 2026-12-01 21:22 UTC · original

Tested on RDNA 4 with Resizable BAR, A/B against main. Short version: on this machine main has no slow-readback problem to fix, and this branch adds dips.

Setup: Ryzen 7 7800X3D, 32 GB, RX 9070 XT 16 GB (Resizable BAR on, 16 GB BAR), CachyOS, Proton-CachyOS, the repo's Mesa 26.3.1 build. ./run.sh play defaults: 1706x960 -> 2560x1440, RT on. Both builds are release and use the same warm caches. Each one ran 10 minutes, loading the same checkpoint and idling there.

main 37bb30f PR #93 (4 commits)
world samples (stats: frame, fps < 95) 92 111
mean fps 32.5 32.5
median fps 32.9 32.4
10th percentile 29.1 27.4
worst sample after load 25.4 9.2
samples < 24 fps after load 0 5
mean copy_ms 1.1 6.8 (peak 85)

On main, copy_ms stays around 0.3-1 ms with Resizable BAR, so the CPU-reads-VRAM cost this PR targets (122 ms on 7900 XTX + i7-13700K) does not show up here. With the branch, copy_ms goes up to 5-14 ms with an 85 ms spike, and that is where the fps dips fall.

My guess, untested: on a large-BAR system, the GPU-copy path for reads of 32 KiB or more (pull) costs more than the direct read it replaces. If so, the switch could depend on the readback speed safecopy measures at startup, rather than applying everywhere.

Caveat: one run per build, with idle sampling at the same checkpoint (no scripted movement, so the scene is not frame-identical).

AI-assisted (Claude Code); measured on the hardware above.

**@⁠EdouardSence** on GitHub · 2026-12-01 21:22 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93#issuecomment-7326145759) Tested on RDNA 4 with Resizable BAR, A/B against main. Short version: on this machine main has no slow-readback problem to fix, and this branch adds dips. **Setup:** Ryzen 7 7800X3D, 32 GB, RX 9070 XT 16 GB (Resizable BAR on, 16 GB BAR), CachyOS, Proton-CachyOS, the repo's Mesa 26.3.1 build. `./run.sh play` defaults: 1706x960 -> 2560x1440, RT on. Both builds are release and use the same warm caches. Each one ran 10 minutes, loading the same checkpoint and idling there. | | main 37bb30f | PR #93 (4 commits) | |---|---|---| | world samples (`stats: frame`, fps < 95) | 92 | 111 | | mean fps | 32.5 | 32.5 | | median fps | 32.9 | 32.4 | | 10th percentile | 29.1 | 27.4 | | worst sample after load | 25.4 | 9.2 | | samples < 24 fps after load | 0 | 5 | | mean `copy_ms` | 1.1 | 6.8 (peak 85) | On main, `copy_ms` stays around 0.3-1 ms with Resizable BAR, so the CPU-reads-VRAM cost this PR targets (122 ms on 7900 XTX + i7-13700K) does not show up here. With the branch, `copy_ms` goes up to 5-14 ms with an 85 ms spike, and that is where the fps dips fall. My guess, untested: on a large-BAR system, the GPU-copy path for reads of 32 KiB or more (`pull`) costs more than the direct read it replaces. If so, the switch could depend on the readback speed `safecopy` measures at startup, rather than applying everywhere. Caveat: one run per build, with idle sampling at the same checkpoint (no scripted movement, so the scene is not frame-identical). AI-assisted (Claude Code); measured on the hardware above.
Author
Owner

@⁠marduuhin on GitHub · 2026-12-01 21:46 UTC · original

Cut CPU reads of VRAM a lot (1.7 GB/min -> 0.35 GB/min) and reduced page shuffling (2.7s/min->1.7s/min).
VICTORY_CARD_PULL=0 is about 5 ms/frame faster on a 5800X3D + 7800 XT, because the CPU reads VRAM faster than the copies do on a busy card (240 vs ~92 MB/s).

**@⁠marduuhin** on GitHub · 2026-12-01 21:46 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93#issuecomment-7326753052) Cut CPU reads of VRAM a lot (1.7 GB/min -> 0.35 GB/min) and reduced page shuffling (2.7s/min->1.7s/min). VICTORY_CARD_PULL=0 is about 5 ms/frame faster on a 5800X3D + 7800 XT, because the CPU reads VRAM faster than the copies do on a busy card (240 vs ~92 MB/s).
Author
Owner

@⁠EdouardSence on GitHub · 2026-12-01 22:22 UTC · original

Follow-up with VICTORY_CARD_PULL=0, which @⁠marduuhin pointed at. Same RX 9070 XT + 7800X3D with Resizable BAR (16 GB BAR). This time I used diag builds with scripted input (VICTORY_KEYS), so all three runs load the same save the same way. 7 minutes each:

main 37bb30f PR #93 PR #93 + VICTORY_CARD_PULL=0
world samples 71 72 71
mean / median fps 38.1 / 37.3 36.3 / 35.1 34.3 / 34.0
10th percentile 33.9 32.1 32.8
mean copy_ms 1.2 10.2 2.0
max copy_ms (after load) 2.6 15.7 2.9

What is consistent across both rounds:

  • With a large BAR, the GPU-copy pull makes copy_ms worse: 1.2 → 10.2 ms here, and 1.1 → 6.8 ms in the first round. VICTORY_CARD_PULL=0 brings it back to about main's level. This matches the 7800 XT report above.
  • The fps differences in this round (34-38) are within what I'd expect from run-to-run noise with one run each. The first round's dips did not reproduce with scripted input. So I would not read anything into the fps column beyond "no gain here".

Together with the 9060 XT result (107 → ~1 ms), it looks like the pull only pays off where CPU reads through the BAR are slow. Could the default come from the safecopy timing the branch already takes at startup? Enable the pull when the measured read speed is low, keep the direct read otherwise. That would keep the 9060 XT / 7900 XTX wins without the extra ~9 ms per frame on large-BAR systems.

**@⁠EdouardSence** on GitHub · 2026-12-01 22:22 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93#issuecomment-7327721345) Follow-up with `VICTORY_CARD_PULL=0`, which @⁠marduuhin pointed at. Same RX 9070 XT + 7800X3D with Resizable BAR (16 GB BAR). This time I used **diag builds with scripted input** (`VICTORY_KEYS`), so all three runs load the same save the same way. 7 minutes each: | | main 37bb30f | PR #93 | PR #93 + `VICTORY_CARD_PULL=0` | |---|---|---|---| | world samples | 71 | 72 | 71 | | mean / median fps | 38.1 / 37.3 | 36.3 / 35.1 | 34.3 / 34.0 | | 10th percentile | 33.9 | 32.1 | 32.8 | | mean `copy_ms` | **1.2** | **10.2** | **2.0** | | max `copy_ms` (after load) | 2.6 | 15.7 | 2.9 | What is consistent across both rounds: - With a large BAR, the GPU-copy pull makes `copy_ms` worse: 1.2 → 10.2 ms here, and 1.1 → 6.8 ms in the first round. `VICTORY_CARD_PULL=0` brings it back to about main's level. This matches the 7800 XT report above. - The fps differences in this round (34-38) are within what I'd expect from run-to-run noise with one run each. The first round's dips did not reproduce with scripted input. So I would not read anything into the fps column beyond "no gain here". Together with the 9060 XT result (107 → ~1 ms), it looks like the pull only pays off where CPU reads through the BAR are slow. Could the default come from the `safecopy` timing the branch already takes at startup? Enable the pull when the measured read speed is low, keep the direct read otherwise. That would keep the 9060 XT / 7900 XTX wins without the extra ~9 ms per frame on large-BAR systems.
Author
Owner

@⁠Widget9337 on GitHub · 2026-12-02 01:45 UTC · original

A data point from a card where this change costs more than it saves: RX 9070 XT 16 GB (Resizable BAR, 16 GB BAR), Ryzen 9 7950X3D, 64 GB DDR5, CachyOS. Series X profile, 1080p output, PC FSR 4, ray tracing on, 30 fps cap. I tried it twice: on its own, and as part of main at f7f0360.

On this machine the CPU's reads of VRAM aren't slow. The startup calibration picks streaming loads here:

unified memory: the CPU reads the card's memory by streaming loads rep_movsb_mb_s=70 streaming_mb_s=1453

So with movntdqa the CPU reads the card at about 1.4 GB/s, not the ~100 MB/s measured on the 7900 XTX. Taking pages down after our reads then costs more than it saves.

1. #93 alone, on top of #67/#47/#45, against the same branch without it (about 2–3 min each, similar area):

without #93 with #93
fps (median) 27.5 27.6
copy_ms (median / peak) 1.2 / 2.2 4.1 / 13.7
preparing_ms (median) 5.8 9.5
"down when the processor touched them" 1,731 6,021
"seen by the card" moved up 2,581 0

2. On main (f7f0360, so with #83) plus #126, in about 4 min sessions:

  • With "seen" promotion off (the new default), the card fell behind what the GPU read. In the big pool, 537 MB was read lately with 423 MB of it on the card. GPU wait went to a 12.8–13.9 ms median. VICTORY_PAGES_SEEN=1 was needed to get the card to fill again.
  • With VICTORY_PAGES_CPU_QUIET=75 (#126), copy time was fine (1.5 ms), but "down when the processor touched them" still reached 10,327 in about 2 min.
  • Without #126, it got worse: copy time 5.7 ms median, fps 28.3, and 12,065 take-downs in about 1.5 min. Pages went down after a read, the GPU needed them, and they came back up.

3. main with this PR reverted (everything else the same, paging at 1000 ms / 8 MiB): copy time back to 1.1–1.2 ms, take-downs back to the pre-#93 level, and no pages bouncing between RAM and the card.

The new read_through behaviour (every card page our CPU reads goes down at the next wave and is struck for a while) seems to be the costly part. pull takes reads of 32 KiB and up off the CPU, but the smaller reads and the safecopy path still take pages down. On a card where streaming reads of the BAR are fast, those pages are better left on the card. Two suggestions:

  • Gate the take-down on the calibration result (for example, skip it when streaming_mb_s is well above the ~100 MB/s case), or put it behind a switch like VICTORY_CARD_PULL.
  • Consider keeping "seen" promotion on by default, or tie it to the same check. With it off, a 16 GB card filled too slowly here.

I only have this one machine and played by hand, so take the numbers as directional. I'm happy to run a build with a switch for the take-down and post A/B numbers.

**@⁠Widget9337** on GitHub · 2026-12-02 01:45 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/93#issuecomment-7332064944) A data point from a card where this change costs more than it saves: **RX 9070 XT 16 GB (Resizable BAR, 16 GB BAR), Ryzen 9 7950X3D, 64 GB DDR5, CachyOS.** Series X profile, 1080p output, PC FSR 4, ray tracing on, 30 fps cap. I tried it twice: on its own, and as part of `main` at `f7f0360`. **On this machine the CPU's reads of VRAM aren't slow.** The startup calibration picks streaming loads here: ``` unified memory: the CPU reads the card's memory by streaming loads rep_movsb_mb_s=70 streaming_mb_s=1453 ``` So with `movntdqa` the CPU reads the card at about 1.4 GB/s, not the ~100 MB/s measured on the 7900 XTX. Taking pages down after our reads then costs more than it saves. **1. #93 alone, on top of #67/#47/#45, against the same branch without it** (about 2–3 min each, similar area): | | without #93 | with #93 | |---|---|---| | fps (median) | 27.5 | 27.6 | | `copy_ms` (median / peak) | 1.2 / 2.2 | **4.1 / 13.7** | | `preparing_ms` (median) | 5.8 | 9.5 | | "down when the processor touched them" | 1,731 | 6,021 | | "seen by the card" moved up | 2,581 | 0 | **2. On `main` (`f7f0360`, so with #83) plus #126,** in about 4 min sessions: - **With "seen" promotion off** (the new default), the card fell behind what the GPU read. In the big pool, 537 MB was read lately with 423 MB of it on the card. GPU wait went to a 12.8–13.9 ms median. **`VICTORY_PAGES_SEEN=1` was needed** to get the card to fill again. - **With `VICTORY_PAGES_CPU_QUIET=75` (#126),** copy time was fine (1.5 ms), but "down when the processor touched them" still reached 10,327 in about 2 min. - **Without #126,** it got worse: copy time 5.7 ms median, fps 28.3, and 12,065 take-downs in about 1.5 min. Pages went down after a read, the GPU needed them, and they came back up. **3. `main` with this PR reverted** (everything else the same, paging at 1000 ms / 8 MiB): copy time back to 1.1–1.2 ms, take-downs back to the pre-#93 level, and no pages bouncing between RAM and the card. The new `read_through` behaviour (every card page our CPU reads goes down at the next wave and is struck for a while) seems to be the costly part. `pull` takes reads of 32 KiB and up off the CPU, but the smaller reads and the `safecopy` path still take pages down. On a card where streaming reads of the BAR are fast, those pages are better left on the card. Two suggestions: - Gate the take-down on the calibration result (for example, skip it when `streaming_mb_s` is well above the ~100 MB/s case), or put it behind a switch like `VICTORY_CARD_PULL`. - Consider keeping "seen" promotion on by default, or tie it to the same check. With it off, a 16 GB card filled too slowly here. I only have this one machine and played by hand, so take the numbers as directional. I'm happy to run a build with a switch for the take-down and post A/B numbers.
This discussion has been locked. Commenting is limited to contributors.
No description provided.