Copies beside the guards open a block without the guards' lock, as a fault does (VICTORY_COPY_OPEN_UNLOCKED, on) #4027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4027"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-11-30T14:52:44Z.
[pr-performance]
What it changes
With
VICTORY_COPY_BESIDE=1, the title'smemcpy/memmove/memsetinto a guarded 64 KiB block is done through the layer's own view of the page, until the block has had its share (titlewrite::MOST). After that,watch::opened_for_writingopens the block, and it always took the guards' lock to do it. That's the same lock the refresh threads hold while they scan and re-guard ranges (guard,publish).Write faults stopped taking that lock long ago (
VICTORY_FAULT_UNLOCKED,open_unlockedplussettle). This makes the copies' open do the same thing:opened_for_writingcallsopen_unlocked(block)and returns.VICTORY_COPY_OPEN_UNLOCKED=0brings back the locked path (toggled!).How it was tested
VICTORY_COPY_BESIDE=1, same shader cache.opened_for_writingwas called 764 times on the title's threads and spent 346 ms waiting for the lock, up to 17 ms at a time. The change of protection itself took 0.2 ms in all.cargo test --locked -p victory-gpu:watch::tests::stores_and_copies_of_the_title_leave_the_guardandfaults_that_take_no_lock_tell_the_samepass. The latter runs the copy tests with faults taking no lock, so it goes through this path.ask_rest_falls_back_per_piece_when_touching_unwatched_neighbourfails now and then in the full parallel run, with or without this change (1 in 5 without it), and passes on its own.victory-gpuadds no warnings.Checked for overlap
open_unlocked's internals andpublishin the same file, notopened_for_writing, so the two should merge without conflict).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-12-01T02:03:58Z.
Race review of #4027 (head
e5cefb5f): it holds. I found no crash and no lost write, but the worst single wait got much longer in a stress test. That may be worth a look at the frame-time tail in your runs.Why it holds.
opened_for_writingnow does what a write fault already does onmain:open_unlocked, thensettleby the next holder of the lock. Ifopen_unlockeddeclines, the copy's write faults and the handler takes over. So no new protocol is added, only one more caller of the existing one.Test. This is the stress test from my #3760 review (one 16 MiB view, four threads guarding it in a loop,
writing()on another thread, 48 writer threads for 20 s), with one change. Before half of the writes, the writer callssuper::opened_for_writing(at + page * PAGE)first, ascrate::titlewritedoes.Results with this PR merged onto
main7d93ee07(clean merge). Debug test build, Ryzen 9 5950X (16 cores, 32 threads), Windows 11,VICTORY_FAULT_UNLOCKEDdefault:VICTORY_COPY_OPEN_UNLOCKED1(default)0watch::: 69 passed, 0 failed, 3 runs.The two ranges don't overlap. This load is artificial: random pages, 48 threads on 16 cores, and
opened_for_writingfar more often than a title calls it. It measures the worst single wait, while your numbers are the total lock wait per frame, so it doesn't contradict them. But it points one way: with the switch on, a single write or refresh can wait much longer, here up to about 0.1–0.3 s. I didn't trace where that time goes. The unlocked opens are settled in batches by whoever takes the lock next, and a write that finds a block another thread is opening waits for it, so either is a candidate.Not tested: the game, release builds, and
VICTORY_COPY_BESIDE=1end to end (the test callsopened_for_writingdirectly).(The
ask_rest_falls_back_per_piece_when_touching_unwatched_neighbourflake you noted is a test-isolation bug onmain, fixed by #4619.)Tested with the help of Claude Code (Claude Opus 5.5).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-12-01T15:46:31Z.
Thanks for the review, and for testing the worst single wait and not just the totals. Those ranges don't overlap, so it's worth checking in the game rather than arguing from the load. I keep this switch on in my play build, and a 30-minute run there today had 5 frames over 100 ms (longest 364 ms) out of 68,710. I'll run 10 minutes with
VICTORY_COPY_OPEN_UNLOCKED=0and 10 with=1on the same scene and post the long-frame counts and the longest frame here. If=0takes the tail away, the default should change.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-12-01T16:15:01Z.
In-game result. In the game it goes the other way from the stress test.
RTX 5080, Ryzen 7 9800X3D. Series X, DLSS Balanced, frame generation 4x (Reflex low latency off,
frameLimitUs6,500). 10 minutes each standing on the pier after a warm-up, about 5,000-5,700 draws a frame. Same build and switches apart from this one:VICTORY_COPY_OPEN_UNLOCKED=0=1That's one run of each, so it doesn't prove
=1is better at the tail, but there's no sign in the game of the waits you measured. My guess is that the stress test's density (48 writer threads, random pages, an open before half the writes) builds up a backlog of unsettled opens that the title never produces. I'm keeping the default as it is. If anyone sees a long-frame tail with it on, aVICTORY_COPY_OPEN_UNLOCKED=0run beside it would show it quickly.