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

Open
github-bot wants to merge 1 commit from github-bot/gh-1086 into main AGit
Owner

@⁠alexis27yt on GitHub · 2026-11-25 18:52 UTC · original
alexis27yt:remap-batch → main · +178 −12 · 2 files · 1 commits · open

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.

**@⁠alexis27yt** on GitHub · 2026-11-25 18:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/1086) `alexis27yt:remap-batch` → `main` · +178 −12 · 2 files · 1 commits · open `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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:14 +00:00
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-25 19:42 UTC · original

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).

**@⁠Proudnoob4** on GitHub · 2026-11-25 19:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/1086#issuecomment-7172667428) 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).*
Author
Owner

@⁠CuteBooty on GitHub · 2026-11-25 19:56 UTC · original

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 310c6eb6 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.

**@⁠CuteBooty** on GitHub · 2026-11-25 19:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/1086#issuecomment-7172969238) **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 310c6eb6 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.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/queue.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1086/head:github-bot/gh-1086'
git switch 'github-bot/gh-1086'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1086'
git switch 'github-bot/gh-1086'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1086'
git switch 'github-bot/gh-1086'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1086'
git switch 'main'
git merge --squash 'github-bot/gh-1086'
git switch 'main'
git merge --ff-only 'github-bot/gh-1086'
git switch 'main'
git merge 'github-bot/gh-1086'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.