GPU: takes make pages read-only outside the guard lock (VICTORY_GUARD_OUTSIDE, opt-in, draft for A/B) #3516
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3516
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3516"
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?
@KainanP on GitHub · 2026-11-27 12:21 UTC · original
KainanP:perf/guard-outside→main· +803 −18 · 1 files · 1 commits · draftRefs #3425.
What this does
Tracked::takeandTracked::takenholdwatch::GUARDSwhileprotect_notingcallsVirtualProtecton every run they take. The write-fault handler needs the same lock. #3425 measures title threads waiting about 52 ms/frame in the handler behind it (RTX 5090/Wine), and borosf's Arc B580 numbers there show 76 ms/frame. I found no open PR that moves the protection change itself out of the lock. #3343 and #2849 batch the unprotect/protect calls, #3035 moves the saved-bytes read, and #3455 turnsGUARDSinto an RwLock (the protect still runs under the write lock).With
VICTORY_GUARD_OUTSIDE=1, a take notes its runs as guarded under the lock (Guards::arming). It changes their protection after releasing the lock (Arming::finish) and before its caller copies them. Off by default: without the variable the code path is the same as before, apart from anis_empty()check.This ports the idea from our fork's fxceless/victory-fork#1315. The code there doesn't map onto this one (the fork guards 64 KiB blocks with a journal, while VIctory has
busyandalias_of), so this is a rewrite, not a cherry-pick.Why the answers stay the same
ARMED). Otherwise it could count the page as guarded, copy it, and miss a write that lands before the guard is in place.alias_of) are guarded under the lock along with their other mappings, as before.title_memory_aliasedwaits for armed pages before linking them.writingor a remap opens a page while it is being armed, the page is marked changed as before and noted asdisturbed.finishthen makes it writable again. A stale fault on such a page (the thread faulted before the opening and retries afterfinish's change) is let through by the handler.Tests (CPU only,
watch.rs)refreshes_under_writes_lose_nothing: five copies (two overlapping copies of a write-watched pool, plus copies of both mappings of twin views) are refreshed together on separate threads while 4 writers write. It checks that every word written before a refresh is in every copy covering it, and that a quiet refresh afterwards leaves each copy equal to title memory. A test-only spin before the out-of-lock protect widens the window a preempted take would leave.alias_ofcheck is removed (5/5 runs, by round 7, with "copy 2 lost a write").disturbedbranch the process crashes with an access violation.armed_pages_opened_or_unmapped_end_as_under_the_lockguard_contention(#[ignore], benchmark):cargo test -p victory-gpu --release --lib guard_contention -- --ignored --nocapture, with sizes set byBENCH_*variables (see its doc).victory-gpu --libsuite also passes withVICTORY_GUARD_OUTSIDE=1: WARP with--features diagnostics, 248/248. On an RTX 4060 Laptop, the only failures are the two that also fail onmainthere (the 1M view-heap cap:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), plus a timing flake indescriptor::hostthat shows up in both modes.-D warningspasses both default and--all-features, and xtask policy passes.Measurements (honest version: no win in the synthetic)
guard_contentionruns on a 256 MB write-watched pool split into 32-page copies. Before each refresh 1,400 pages are written, then writers keep writing random words every 20 µs during the refresh. Off and on alternate within one process, 31 rounds, medians. Machine: 24 threads, about 11–40 % foreign load (another build running).GUARDSoff → onVirtualProtect(open) under the lock. This PR doesn't touch that path.This matches what we saw in the fork. There, on a 5080, guard waits went from 23 to 0.5 ms with no change in frame time (fxceless/victory-fork#1379). The synthetic doesn't model the title's real write pattern, though, and #3425's profile puts about 49 ms/frame of
GUARDShold time on the takes. So the only real test is in-game, which is why this is a draft and off by default.A/B request. @neonbyte1 (5090/Wine) and @borosf (Arc B580): could you run the prison-yard scene with and without
VICTORY_GUARD_OUTSIDE=1, with thediagnosticsbuild soheld_times,GuardWaitUs,HandlerUsandProtectUsare in the log? Frame time is what decides it. If it doesn't move, I'll close this.AI use: written with Claude Code (Claude Opus 5.5): port design, implementation, tests, mutation checks and benchmark runs, all run on KainanP's machine.
🤖 Generated with Claude Code
@neonbyte1 on GitHub · 2026-11-27 12:37 UTC · original · edited 2026-11-27 12:39 UTC
@KainanP I'll do once my agents are done, current queue ends in ~3 hours from now. Since the game needs a bunch of VRAM, I can't run the game twice for now :/
A bit off-topic but I've spawned 4 other agents for performance analysis regarding the frametime. We went from ~900ms to ~170ms this night, so chasing this is currently my focus. As I said, once the queue ends I'll start the A/B run.
@borosf on GitHub · 2026-11-27 13:11 UTC · original
I took the Arc B580 half of the A/B. No verdict yet, and I would not want you to read a number from what I have.
What works now: I can drive the title into the prison yard unattended (a click on the PLAYER label plus Enter; its first screen is mouse-driven, which is what defeated my earlier menu-only captures). Tree:
63bcca4+ #2958 (without it the yard renders as a pink wash at ~4.7 s/frame, which would swamp a ~50 ms CPU-side effect) + your PR ata73feeb,--profile diag --features diagnostics, both arms the same binary toggled byVICTORY_GUARD_OUTSIDE=1, 240 s per arm, interleaved off/on/off/on.What happened: three of four runs ended with the device removed (
GetDeviceRemovedReason, count 4) partway through the yard — the pre-existing Arc failure tracked in #2671, unrelated to your change. Only one run sustained the yard (26 world frames,on), so I have one arm and no matched counterpart:guardshandlerprotectingThe
offrows are menu-interval lines, not yard lines — the runs died before steady state — so comparing them with theonrow would be exactly the kind of false reading I have been trying to avoid in this repo. What I can say is that the one sustainedonrun sits in the same band as the Arc numbers in #3425 (76 ms handler), i.e. your change did not visibly collapse anything, but that is not a measurement of your change.Why I am not just re-running until it works: each attempt costs 4 minutes and one in three dies on #2671's fault, so getting a matched pair is luck, and I have already burned several. Two options, your call: (a) I keep grinding until I land a paired off/on where both survive — honest but slow; (b) @neonbyte1's 5090/Wine setup is stable and already queued for this, and I contribute the harness (
press-on-prompt.ps1+run-world.sh) rather than the numbers. If you would rather have (a), say so and I will run it to completion before reporting again.One thing from the same session that is worth your attention, since it is adjacent: your contention finding on #3356 (
sync_heaps9.6 → 13.4 ms, write-watched pools) reads correctly to me —VirtualQueryis exactly the cost my own code comment warns about in the title's big pools, and my timing test used a plain allocation, which has none of that structure. I am treating that as a probable regression in my PR, not a measurement dispute.Synthetic tests only in the tree; the runs are my own dump. Machine: Windows 11 x64, Ryzen 5 5600, 32 GB, Arc B580 12 GB.
@KainanP on GitHub · 2026-11-27 13:26 UTC · original
Thanks @borosf, and agreed: with the off arm dying before the yard there's no matched pair, so no number should be read from it. The one thing I'd take from your on-run is that the
guardshandler (64 ms) and view-write wait (111 ms) are still large with the switch on, which fits the synthetic result in the body: moving the take's re-protect out of the lock doesn't help while title writes queue behind each other's fault handler (still under the lock). That's why this stays a draft. @neonbyte1 no rush — a run on a card without the #2671 device loss would settle it.AI use: Claude Code (Claude Opus 5.5).
@kilolimaVI on GitHub · 2026-11-27 15:49 UTC · original
Laptop numbers, head
a73feeb: Windows 11, Ryzen 7 8845HS (8C/16T), toolchain 1.98.1.Stability:
refreshes_under_writes_lose_nothingandarmed_pages_opened_or_unmapped_end_as_under_the_lock, 20 runs in a row: 0/20 failures.guard_contention(--release --ignored --nocapture, defaults: 4096 pages, copies of 32, 1400 dirty, 4 writers every 20 us, 11 rounds, medians):VICTORY_GUARD_OUTSIDE=0=19460 runs made read-only outside the lock, 0 kept under it. So here the lock wait drops by about a quarter and the worst writes get shorter, but total time in writes is slightly up, there are more slow writes, and the refresh is ~20% slower (it now waits ~5 ms). On this 8-core laptop the net effect looks neutral to slightly negative; one benchmark run, so treat it as one data point.
AI-assisted (Claude).
View 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.