Skip to content

Page mappings: one call's batch holds title memory still once (VICTORY_REMAP_BATCH=1) - #1086

Open
alexis27yt wants to merge 1 commit into
fxceless:mainfrom
alexis27yt:remap-batch
Open

alexis27yt wants to merge 1 commit into
fxceless:mainfrom
alexis27yt:remap-batch

Conversation

@alexis27yt

Copy link
Copy Markdown

CopyPageMappingsBatchX maps 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_remapping now 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 stays MAPPING, then xmem's physical lock, as in XMemMapPhysicalPages. The frame log counts one wait (RemapWaitUs) and one hold (RemapUs) per batch. Readers wait for the whole batch instead; with VICTORY_TEXTURE_NO_WAIT=1 they 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 for hold, then letting go for 50 µs; median of 5:

refresh holds page by page (today) held once
~2 ms (hash + detile of a 5 MB texture today) 261 / 217 ms (two runs) 4.3 ms 50-60×
~0.3 ms (with #1078's short hold) 41 ms 4.3 ms 9.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: RemapWaitUs from 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_page checks 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 with mapping_tests::reads_in_place_and_remappings_wait_for_each_other, and all 12 xmem tests pass. Clippy: no new warnings, with and without diagnostics.

…Y_REMAP_BATCH=1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ExoCalibra added a commit to ExoCalibra/victory-exo that referenced this pull request Nov 25, 2026
@Proudnoob4

Copy link
Copy Markdown

Heads-up from testing VICTORY_REMAP_BATCH=1 in-game on Windows 10 (i5-13600K + RTX 4080 16 GB, Series X, Xeltax/VIcky b18fce0d + #1014/#1015/#1029/#1044/#1058/#1059/#1094/#1097):

  • With VICTORY_REMAP_BATCH=1: the title ran 143 menu frames at 30.0 fps, then hung for 30s at 19:32:53 -> 19:33:23 right after frame-8 and hit the title's 30s watchdog crash (0xC0000005 write 0x0 at +0x2215c35 after 56s).
  • With 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 (xmem 12/12) passed, so this looks like a live lock-ordering / contention hang between CopyPageMappingsBatchX holding title_memory_remapping across the batch and concurrent readers/xmem/watch on this stack.

AI-assisted testing and report (Gemini 4 Neon).

@CuteBooty

Copy link
Copy Markdown

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:

Draws a frame Frame Preparing of it textures of that, waiting for mappings
7,640 1,575 ms 1,483 1,324 1,266
9,296 543 ms 441 302.5 281.5
6,372 346 ms 250 97.8 86.8

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 310c6eb with 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.

rcioletti added a commit to rcioletti/victory-gta6 that referenced this pull request Nov 25, 2026
…xceless#1117, fxceless#1081 (zero-copy section windows, lock-free mirror, Thin LTO, streaming locks, standalone gather, Series S UI)
CernyMuzCZ pushed a commit to CernyMuzCZ/vitezstvi-fork that referenced this pull request Nov 25, 2026
…Y_REMAP_BATCH=1)

Port of fxceless PR fxceless#1086 (a0c1352): reentrant thread-local title_memory_remapping() guard so CopyPageMappingsBatchX holds watch::MAPPING once per batch while preserving watch::MAPPING -> xmem::PHYSICAL lock order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants