Page mappings: one call's batch holds title memory still once (VICTORY_REMAP_BATCH=1) #1084
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1086"
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 fxceless/victory-fork. Originally posted by alexis27yt on 2026-11-25T18:52:54Z.
CopyPageMappingsBatchXmaps page by page, and each page takes the remapping lock (watch::title_memory_remapping) on its own: ~850 takings a frame that streams, each one waiting until every read of title memory in place under way is done. Texture refreshes are such reads, and hold it for their hash and detile (see #1078). So the title's thread queues behind the texture threads once per page.With
VICTORY_REMAP_BATCH=1(off by default) the call takes the lock once, before its first page.title_memory_remappingnow counts its holds per thread, so each page (map_alias, unchanged) finds it held by its own thread and does not wait for itself. No thread ever took it twice before (the lock is not reentrant, so that would have hung), so nothing else changes. Lock order staysMAPPING, thenxmem's physical lock, as inXMemMapPhysicalPages. The frame log counts one wait (RemapWaitUs) and one hold (RemapUs) per batch. Readers wait for the whole batch instead; withVICTORY_TEXTURE_NO_WAIT=1they read through the kernel meanwhile.Measured with the new
batch_tests::what_a_batch_of_page_mappings_waits_for_beside_texture_refreshes(ignored by default) on an i5-12400F: one call of 850 one-page mappings (5 µs of work each, about one remap's kernel calls) while 2 threads refresh textures, holding the lock forhold, then letting go for 50 µs; median of 5:The page-by-page case lands at the order of the 246 ms of remapping the README measures in a streaming frame. That makes this queueing the likely bulk of it, though not yet measured in game:
RemapWaitUsfrom a streaming scene, with and without the switch, would confirm. The two changes compound: #1078 shortens each read, this pays the wait once per call.Tests: new
a_batch_maps_the_same_pages_held_once_or_page_by_pagechecks the four range kinds map the same pages in the same order both ways, that no read in place can begin mid-batch, and (a page-by-page run after a held one) that no hold is left counted. It passes in parallel withmapping_tests::reads_in_place_and_remappings_wait_for_each_other, and all 12xmemtests pass. Clippy: no new warnings, with and withoutdiagnostics.Imported from fxceless/victory-fork. Originally posted by Proudnoob4 on 2026-11-25T19:42:46Z.
Heads-up from testing
VICTORY_REMAP_BATCH=1in-game on Windows 10 (i5-13600K + RTX 4080 16 GB, Series X,Xeltax/VIckyb18fce0d+ #1014/#1015/#1029/#1044/#1058/#1059/#1094/#1097):VICTORY_REMAP_BATCH=1: the title ran 143 menu frames at 30.0 fps, then hung for 30s at19:32:53 -> 19:33:23right afterframe-8and hit the title's 30s watchdog crash (0xC0000005write0x0at+0x2215c35after 56s).VICTORY_REMAP_BATCH=0(same binary, same switches, same cache): booted straight into the 3D world and ran cleanly for the full 420s (exit 0, reached frame 3072, peak 6.1 fps live RT).Unit tests (
xmem12/12) passed, so this looks like a live lock-ordering / contention hang betweenCopyPageMappingsBatchXholdingtitle_memory_remappingacross the batch and concurrent readers/xmem/watchon this stack.AI-assisted testing and report (Gemini 4 Neon).
Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-25T19:56:27Z.
115 heavy frame summaries from a real mission: median 44.5 ms a frame waiting for title memory to hold still, 281 ms of one 302 ms texture sample, 1.27 s in the worst
Not a test of this PR: our tree does not have it yet. A data point for why it matters. In a 103-minute run of the
first story mission (town and dense foliage, 6,000-10,000 draws a frame), the frame summaries with at least 6,000
draws had a median frame of 279.6 ms. What the "textures" share of preparing was made of in the slow ones:
The upload volume in those frames was small (16-36 MB); the heap's own texture pass took 24 ms in the second
row. So on this card the stalls in new scenery are the refresh waiting on the mapping lock, not the uploads. Once we
have this PR (or #1078) in the tree I will post the same table with it.
Setup: RTX 3070 8 GB (driver 621.24, 32-lane waves), Ryzen 5 3600, 32 GB, Windows 11, Series S mode (PR #188), 1920x1080, a diagnostics build of a tree at main
310c6eb6with a number of open PRs picked and ports of fork main's copy queue re-fetch and submit thread. Switches unless the comment says otherwise:VICTORY_QUEUE2=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_ASYNC_SUBMIT=1 VICTORY_BAKE_TEXTURES_MS=0 VICTORY_TEXTURE_DROP_MIPS=1, plus wide card hashing (our tree's form of PRs #1014 / #997). One run per configuration.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.