Page-mapping copies: the locks taken once a call (VICTORY_MAP_ONCE, opt-in): worst frame while the world streams 170-210 ms where it was 300-555 ms #3850
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3850
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3850"
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?
@duckey-dev on GitHub · 2026-11-30 09:18 UTC · original
duckey-dev:page-mapping-once→main· +289 −14 · 4 files · 1 commits · merged 2026-11-30 14:12 UTCWhat was wrong
While the open world streams, the title's render thread spends a long time in our
CopyPageMappings(queue.rscopy_page_mappings, thenxmem::map_aliases, thenaliasfor each range). One call took up to 64 ms, and these calls took 433 ms in 3.2 s of a timeline capture. Every other title thread was waiting on the render thread meanwhile.On the one-mapping-thread path, each range of a call took these again, one after another:
victory_gpu::title_memory_remapping(or_ofwithVICTORY_RANGE_LOCK=1) waits for every read of title memory in place to end.PHYSICAL, the views.title_memory_remapped/title_memory_unmapping.REMAPPED, the texture pass's queue, taken once for each note. The 16 DirectStorage workers take the same lock for every request they write (watch::writing).Constant-source ranges (kind 1 in
CopyPageMappingsBatchX: n destination pages that all show one pool page) arrive as n ranges of one page each. Each of those pages went through the whole sequence on its own: the locks, one unmapping and one mapping.The one-mapping-thread path is the one players use. It runs when
VICTORY_MAP_THREADS=1, whichscripts/play.ps1,Play-VIctory.cmdand the foxhound settings set, or whenever soft views are on (side_by_side()returns 1 then).What changes
Everything is behind
VICTORY_MAP_ONCE=1. Off (the default), the code paths are exactly as before.crates/victory-hle/src/modules/xmem.rs:map_aliases, one-thread path (one_after_another): calls the newalias_allinstead ofaliasfor each range.alias_all:PHYSICALonce for all of them, throughremapping_and_views(&wanted). That is the same helper and the same order one range uses.alias_asdid it alone. The first range that fails ends the call, as before.alias_held: the body ofalias_as, moved out unchanged, with the locks taken by the caller.alias_asnow takes the locks and calls it, so the path with the switch off is the same code.aliases_of: joins pages that sit side by side and are mapped from one and the same pool page into one "constant" range. It has a unit test.alias_constant:VICTORY_REMAP_SAME).alias_held.map_aliases, several-thread path (VICTORY_MAP_THREADSover 1): only the notes are gathered. The groups take their locks as before.VICTORY_REMAP_TIMING=1: also logs the new path's lock wait (locks_us) and mapping time (map_us) for calls over 5 ms. This is next to the existing whole-call line inqueue.rs.crates/victory-gpu/src/descriptor/host.rs,watch.rs,lib.rs:remapped_gathered(f): whilefruns on this thread,remappedkeeps its ranges in a thread-local list instead of takingREMAPPED.heap_hooks::changed, which takes no lock).record_ranges).remapped_ranges: split into theheap_hooks::changedstep andrecord_ranges. Its behaviour is unchanged.victory_gpu::title_memory_notes_gathered: the public wrapper forremapped_gathered, re-exported fromlib.rs.Why opt-in
Lock order
alias_alltakes the locks throughremapping_and_views: the change of mapping first, thenPHYSICAL. That is whatalias_asandXMemMapPhysicalPagesdo, so no new order is introduced. It is the same pair, taken once and held longer.VICTORY_RANGE_LOCK=1, the change is taken for what the views say every destination of the call touches, re-checked afterPHYSICALis held, exactly as for one range. A reader outside every destination still does not wait.REMAPPED. While gathering,REMAPPEDis taken once at the end, with the change andPHYSICALstill held. That is the same place it was taken before (insidetitle_memory_remapped/title_memory_unmapping, under the same locks), only once instead of once a range.remappedwas already documented as being called with the runtime's locks held and calling nothing.watch::writing,land) still record directly.How it was tested
VICTORY_MAP_THREADS=1(the launcher'splaysettings). A scripted walk in the open world right after loading a save. 6 runs with the switch, 5 without.VICTORY_MAP_ONCE=1The ranges do not overlap, but the limits are real:
11 runs in all.
One machine.
One route.
Measured on a branch that combined this change with other open pull requests, not on main alone.
cargo testpassed for the crates it touches: no failure that main does not have on this machine (main failsa_read_by_range_waits_only_for_a_remapping_that_meets_itand threebcpackoracle tests here, with or without this change). Both of CI's clippy runs add no warning over main.Not tested
map_aliasestests run with the switch off, so they cover only the unchanged path andalias_held(which now holds the moved body).alias_all,alias_constantandremapped_gatheredare not unit-tested. Onlyaliases_of, the joining rule, has a test.alias_heldandplacewithSoft::NotedCopies, as before, and their notes are gathered.Checked for overlap
None of these replaces this change. As far as I can tell, each one changes something else that the same calls contend on. I test-merged each against this branch with
git merge-tree: #2439, #2650, #3292, #3480, #3553, #3603, #3621, #3650, #3733 and #3760 merge cleanly.RemapQueue::recordunderREMAPPEDcheaper. This PR takesREMAPPEDfewer times during a page-mapping copy. The two fit together. Theirs helps every writer of the queue (DirectStorage, landing), which this PR does not touch: for queue cost in general, theirs is the broader fix. This PR's gathering matters only for the page-mapping thread.REMAPPEDonce for many ranges", on the landing threads' side. Independent and complementary.PHYSICALfor a whole call, #3553 is all the more useful on the soft-view path.RangeLockitself cheaper; with it, unrelated readers are not woken by the one range-lock write this PR holds for a call.set_range_lockthat came in meanwhile): a correctness fix to the switch this PR's lock path reads. Independent.VirtualProtectmoved outside theGUARDSmutex): makes the guard work this PR still does for each range cheaper. Complementary; it is the larger change to the guards themselves.VICTORY_MAP_ONCE, so it does not change what those tests see. With the switch on,alias_allholds the remap lock for a whole call, which is the situation those PRs isolate the test from.🤖 Generated with Claude Code
@akimfomin on GitHub · 2026-11-30 09:28 UTC · original
@duckey-dev Thanks for publishing both A/B ranges and the failure-path difference. Our native 1440p Series X walk with original RT on RTX 4070 Ti SUPER still has long frames and a heavily occupied submit thread. Did you capture the split between
locks_usandmap_us, or try gatheringREMAPPEDnotes while keeping the original per-page map/unmap order? That variant would help us isolate lock contention with the existing partial-failure behavior. We can cross-check the timing on RTX once we have that comparison pinned.@duckey-dev on GitHub · 2026-11-30 10:41 UTC · original
@akimfomin I had not captured the split: my measuring script filtered that log target out, so the runs in the description only compared whole-run frame times. I have now run the walk once each way with
VICTORY_REMAP_TIMING=1(same machine, RX 7900 XTX, ray tracing off, 164 s each, calls of 5 ms and over):VICTORY_MAP_ONCE=1So on this machine the wait for the change of mapping and
PHYSICALis next to nothing (6 ms of 1,724), and the time is in the map/unmap work itself (map_ushere covers everything after the locks are held: the unmappings, the views, the guards' notes). What the switch saves is about a sixth of the total in this pair, which fits fewer unmappings for constant-source runs and one taking ofREMAPPED, not less lock waiting. The description leans on the locks more than this supports; I'll correct it.Two more caveats from this pair. It ran on a branch with about 30 more open PRs merged than the runs in the description (#3733 among them), and there the worst frame was 181 ms off against 143 ms on, far closer than the 300-555 against 170-210 in the description. So treat the size of the gain as unsettled until I have repeats on one tree.
The variant you describe exists here only on the several-thread path (
VICTORY_MAP_THREADSover 1 with the switch on gathers just the notes and keeps the per-page order and locks); I have not measured it by itself. Given the split above I would expect little from notes alone on one thread, but if it helps your RTX cross-check I can add it as a second value of the switch.