GPU: probe 4 KiB OS pages in descriptor sync_heaps #2447

Closed
github-bot wants to merge 1 commit from github-bot/gh-2447 into main AGit
Owner

@⁠Texbirds on GitHub · 2026-11-25 13:39 UTC · original
Texbirds:fix/gpu-descriptor-sync-heaps-4k-probe → main · +134 −26 · 1 files · 1 commits · closed without merging

Problem

In crates/victory-gpu/src/descriptor.rs, sync_heaps() iterates dirty ranges returned by written.take(start as usize, usize::MAX) in crate::watch::PAGE (64 KiB) steps and probes readability once at the start of each 64 KiB block with crate::host::read_into(page as *const u8, &mut [0u8; 4]) before calling host.mirror() (which reads each 12-byte slot header directly via read_unaligned() in descriptor/host.rs).

Because Windows commits and unmaps memory at 4 KiB (0x1000) granularity, a partially committed 64 KiB block fails in both directions on main:

  • If the first 4 KiB page is committed and a later 4 KiB page in the same 64 KiB block is decommitted/unmapped, the 64 KiB probe succeeds and host.mirror() faults with an Access Violation on the unreadable tail.
  • If the first 4 KiB page is decommitted/unmapped and a later 4 KiB page holds live descriptors, the probe at offset 0 fails and sync_heaps() skips the entire 64 KiB block without mirroring those descriptors.

Change

  • Extract per-heap mirroring into sync_heap(heap: &Heap) (called by sync_heaps() under SHADER_HEAPS) and step in const OS_PAGE: usize = 4 << 10 (4 KiB) chunks.
  • Probe each 4 KiB page with a 1-byte crate::host::read_into(page as *const u8, &mut [0u8; 1]) so the probe itself can never cross a page boundary.
  • For any descriptor slot straddling a 4 KiB boundary (only possible when a placed heap's start is not aligned to the 16- or 32-byte step), guard the 12-byte record with read_into(handle, &mut [0u8; 12]) before calling host.mirror().

Test

sync_heaps_handles_partially_committed_64k_pages (Windows, synthetic write-watched pool via watch::tests::pool(1) and a 512-slot placed sampler heap spanning two 4 KiB pages within one 64 KiB block, no game data):

  • Case 1: Copies a sampler record into slot 5 (first 4 KiB page), decommits the second 4 KiB page with VirtualFree(..., MEM_DECOMMIT), runs sync_heap, and asserts slot 5 is mirrored without faulting on the decommitted second page.
  • Case 2: Re-commits the second 4 KiB page, copies a sampler record into slot 261 (inside the second 4 KiB page), decommits the first 4 KiB page, marks the range remapped via watch::title_memory_remapped, runs sync_heap, and asserts slot 261 is mirrored.
  • Serializes against parallel sync_heaps() calls using SHADER_HEAPS while decommitting/recommitting its own test pool, and skips cleanly if no host D3D12 device is present (matching the existing records_copied_as_bytes_are_made_at_the_next_sync test).
**@⁠Texbirds** on GitHub · 2026-11-25 13:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447) `Texbirds:fix/gpu-descriptor-sync-heaps-4k-probe` → `main` · +134 −26 · 1 files · 1 commits · closed without merging ### Problem In `crates/victory-gpu/src/descriptor.rs`, `sync_heaps()` iterates dirty ranges returned by `written.take(start as usize, usize::MAX)` in `crate::watch::PAGE` (64 KiB) steps and probes readability once at the start of each 64 KiB block with `crate::host::read_into(page as *const u8, &mut [0u8; 4])` before calling `host.mirror()` (which reads each 12-byte slot header directly via `read_unaligned()` in `descriptor/host.rs`). Because Windows commits and unmaps memory at 4 KiB (`0x1000`) granularity, a partially committed 64 KiB block fails in both directions on `main`: - If the first 4 KiB page is committed and a later 4 KiB page in the same 64 KiB block is decommitted/unmapped, the 64 KiB probe succeeds and `host.mirror()` faults with an Access Violation on the unreadable tail. - If the first 4 KiB page is decommitted/unmapped and a later 4 KiB page holds live descriptors, the probe at offset 0 fails and `sync_heaps()` skips the entire 64 KiB block without mirroring those descriptors. ### Change - Extract per-heap mirroring into `sync_heap(heap: &Heap)` (called by `sync_heaps()` under `SHADER_HEAPS`) and step in `const OS_PAGE: usize = 4 << 10` (4 KiB) chunks. - Probe each 4 KiB page with a 1-byte `crate::host::read_into(page as *const u8, &mut [0u8; 1])` so the probe itself can never cross a page boundary. - For any descriptor slot straddling a 4 KiB boundary (only possible when a placed heap's `start` is not aligned to the 16- or 32-byte `step`), guard the 12-byte record with `read_into(handle, &mut [0u8; 12])` before calling `host.mirror()`. ### Test `sync_heaps_handles_partially_committed_64k_pages` (Windows, synthetic write-watched pool via `watch::tests::pool(1)` and a 512-slot placed sampler heap spanning two 4 KiB pages within one 64 KiB block, no game data): - **Case 1:** Copies a sampler record into slot 5 (first 4 KiB page), decommits the second 4 KiB page with `VirtualFree(..., MEM_DECOMMIT)`, runs `sync_heap`, and asserts slot 5 is mirrored without faulting on the decommitted second page. - **Case 2:** Re-commits the second 4 KiB page, copies a sampler record into slot 261 (inside the second 4 KiB page), decommits the first 4 KiB page, marks the range remapped via `watch::title_memory_remapped`, runs `sync_heap`, and asserts slot 261 is mirrored. - Serializes against parallel `sync_heaps()` calls using `SHADER_HEAPS` while decommitting/recommitting its own test pool, and skips cleanly if no host D3D12 device is present (matching the existing `records_copied_as_bytes_are_made_at_the_next_sync` test).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:04 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:02 UTC · original

Reviewed — the 4 KiB probing is right and fixes a real fault path:

  • Mappings/commits change per 4 KiB OS page; probing only the 64 KiB block start both faults on a decommitted tail and skips committed pages behind a decommitted lead. Per-page probe + continue handles both.
  • The straddling-descriptor 12-byte probe covers the one case a descriptor can cross a page boundary (unaligned heap start) — defensive, zero cost otherwise.
  • written.take ranges unchanged; mirror calls now skip indices in unmapped sub-pages, which is the point.
  • The test is real verification: actual MEM_DECOMMIT/MEM_COMMIT inside the pool in both directions, and it serializes against parallel sync_heaps via the SHADER_HEAPS lock.
**@⁠kotekompotek** on GitHub · 2026-11-25 14:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7164656285) Reviewed — the 4 KiB probing is right and fixes a real fault path: - Mappings/commits change per 4 KiB OS page; probing only the 64 KiB block start both faults on a decommitted tail and skips committed pages behind a decommitted lead. Per-page probe + `continue` handles both. - The straddling-descriptor 12-byte probe covers the one case a descriptor can cross a page boundary (unaligned heap start) — defensive, zero cost otherwise. - `written.take` ranges unchanged; `mirror` calls now skip indices in unmapped sub-pages, which is the point. - The test is real verification: actual `MEM_DECOMMIT`/`MEM_COMMIT` inside the pool in both directions, and it serializes against parallel `sync_heaps` via the `SHADER_HEAPS` lock.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 16:30 UTC · original

Rebased onto main (67e8ae1) in dac5a4f. main now batches each page's slots through HostHeap::sync_slots (one lock per page instead of two per slot). The fix keeps that: each 4 KiB OS page is probed and its slots go to sync_slots in one call. Only the at most two edge slots that can straddle a 4 KiB boundary (an unaligned placed heap) get the 12-byte probe before mirror. The SyncSlots diagnostics count is unchanged, and so is sync_heaps_handles_partially_committed_64k_pages.

**@⁠Texbirds** on GitHub · 2026-11-25 16:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7168096934) Rebased onto `main` (`67e8ae1`) in `dac5a4f`. `main` now batches each page's slots through `HostHeap::sync_slots` (one lock per page instead of two per slot). The fix keeps that: each 4 KiB OS page is probed and its slots go to `sync_slots` in one call. Only the at most two edge slots that can straddle a 4 KiB boundary (an unaligned placed heap) get the 12-byte probe before `mirror`. The `SyncSlots` diagnostics count is unchanged, and so is `sync_heaps_handles_partially_committed_64k_pages`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:41 UTC · original · edited 2026-11-26 00:23 UTC

Automated triage for the maintainers.

Needs work (unchanged). The head (dac5a4f) has not changed since the last review. sync_heap in crates/victory-gpu/src/descriptor.rs still reads correctly, and CI (check) passes.

On your reply: thanks for checking the VirtualAlloc2 behaviour. It confirms that a 64 KiB reservation can be committed in 4 KiB pieces, which was not in doubt. The missing piece is still a title run or trace that shows a placed shader-visible heap on such a reservation with uncommitted pages, or a fault in sync_slots/mirror. With that, this becomes a fix for an observed case. Without it, it stays a guard that makes every written range's probe 16 times finer.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7168371199) · edited 2026-11-26 00:23 UTC <!-- victory-triage v1 head=dac5a4ff029724656a2db322377bfa96c86902f0 verdict=needs-work at=2026-11-26T00:23:42Z --> Automated triage for the maintainers. **Needs work (unchanged).** The head (`dac5a4f`) has not changed since the last review. `sync_heap` in `crates/victory-gpu/src/descriptor.rs` still reads correctly, and CI (`check`) passes. On your reply: thanks for checking the `VirtualAlloc2` behaviour. It confirms that a 64 KiB reservation can be committed in 4 KiB pieces, which was not in doubt. The missing piece is still a title run or trace that shows a placed shader-visible heap on such a reservation with uncommitted pages, or a fault in `sync_slots`/`mirror`. With that, this becomes a fix for an observed case. Without it, it stays a guard that makes every written range's probe 16 times finer. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 17:13 UTC · original

Thanks for the question about where this layout can come from. The physical mapping path uses 64 KiB pages. There’s also a path through XMemVirtualAlloc. An ordinary reservation is write-watched, and a later MEM_COMMIT at a non-null address forwards the requested size to VirtualAlloc2. Placed shader-visible heaps accept caller-provided memory, and watch::track can track that reservation.

I checked the Windows calls directly with a 64 KiB reservation. Committing just the first or second 4 KiB page made only that page readable in each case. That confirms the allocation path can produce the layout. The remaining evidence is a retail trace showing a placed shader-visible heap backed by such a reservation, or a crash trace in sync_slots.

**@⁠Texbirds** on GitHub · 2026-11-25 17:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7169179948) Thanks for the question about where this layout can come from. The physical mapping path uses 64 KiB pages. There’s also a path through `XMemVirtualAlloc`. An ordinary reservation is write-watched, and a later `MEM_COMMIT` at a non-null address forwards the requested size to `VirtualAlloc2`. Placed shader-visible heaps accept caller-provided memory, and `watch::track` can track that reservation. I checked the Windows calls directly with a **64 KiB reservation**. Committing just the first or second **4 KiB page** made only that page readable in each case. That confirms the allocation path can produce the layout. The remaining evidence is a retail trace showing a placed shader-visible heap backed by such a reservation, or a crash trace in `sync_slots`.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-25 22:38 UTC · original

Leaving dac5a4f as-is (still merges cleanly onto f3578e3 with CI green) while waiting to see if anyone hits a placed shader-visible heap on a partially committed XMemVirtualAlloc reservation or a sync_slots/mirror fault in a retail trace.

**@⁠Texbirds** on GitHub · 2026-11-25 22:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7176604165) Leaving `dac5a4f` as-is (still merges cleanly onto `f3578e3` with CI green) while waiting to see if anyone hits a placed shader-visible heap on a partially committed `XMemVirtualAlloc` reservation or a `sync_slots`/`mirror` fault in a retail trace.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 13:57 UTC · original · approved these changes

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Probing 4 KiB OS pages in descriptor::sync_heaps cleanly avoids reading unmapped pages inside a partially committed descriptor heap.
  • cargo test -p victory-gpu descriptor::tests: 6/6 passed on RTX 5090, 6/6 passed on WARP.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 13:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#pullrequestreview-6058933929) · **approved these changes** Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Probing 4 KiB OS pages in `descriptor::sync_heaps` cleanly avoids reading unmapped pages inside a partially committed descriptor heap. - `cargo test -p victory-gpu descriptor::tests`: 6/6 passed on RTX 5090, 6/6 passed on WARP. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 14:11 UTC · original · reviewed

Probe 4 KiB OS pages in descriptor sync_heaps. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

**@⁠catminou4** on GitHub · 2026-11-25 14:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#pullrequestreview-6059178729) · **reviewed** Probe 4 KiB OS pages in descriptor sync_heaps. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Author
Owner

@⁠imjustprism on GitHub · 2026-11-26 19:59 UTC · original · reviewed

ran dac5a4f in the title to get the two things the triage asks for: whether the world ever shows a heap block with only some of its 4 KiB pages readable, and what the finer probe costs. rx 9070 xt, world, medians per frame:

per frame without, 6 runs with this pr, run 1 run 2
4 KiB probes 2,715 2,348
probes that failed 0 0
64 KiB blocks with both readable and unreadable pages 0 0
slots that took the edge path (straddling) not counted 0
time in the probes, ms not timed 1.1
heap sync (sync_heaps), ms 10.6 to 14.3 16.4 12.0
slots scanned 308,000 to 379,000 347,000 301,000
heap sync, ms per 100,000 slots 3.0 to 3.9 4.7 4.0

63bcca4 plus #2122 (this card needs it) plus local timers and counters, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run. of the six runs without, two are plain, three have #2051 and one has #3139 merged in; neither changes how often this path probes. no errors and no device removed in any run.

so, in 24 minutes of world here: no probe failed and no block was partly readable, the edge path never ran (so the heap starts on a slot boundary), and the 16 times finer probe costs about 1.1 ms a frame in the probes alone. the whole sync per slot was above every run without in both runs, by 3% and by 21% over the highest of them; the two runs differ from each other as much as that, so beyond the probes' 1.1 ms i would not put a number on it.

i also read the title's executable for where such a layout could come from. in what a static read shows, its own calls that free memory release whole regions and none decommits part of one, and its XMemVirtualAlloc calls reserve and commit in one call or re-reserve the pieces of a split reservation; none commits pieces inside a reservation it already holds. calls through pointers are not resolved by that, so it is not proof, but it agrees with the runs: i found nothing in this title that makes the layout.

what i checked from the description:

  • sync_heaps_handles_partially_committed_64k_pages and the other descriptor tests pass here (hardware adapter).
  • "the SyncSlots diagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above.
  • "faults on main" for case 1: by reading, yes (sync_slots reads the decommitted page raw). i did not run the test on main.
  • case 2, "skips the entire block without mirroring those descriptors": fixed for the first sync only, see the first point.

points from reading the diff:

  • case 2 holds for one sync, watch.rs:666 and :701. when guarding a block fails, unmapped asks about the block's first byte only. with the first 4 KiB decommitted the block is counted as taken, dropped from the changed set and never guarded, so no later write to its other pages is seen. i added a second write and a second sync at the end of your test (same state, slot 262, then sync_heap, then assert!(host.made(262))): it fails here. the cause is older than this pr, but it means the second half of the fix needs watch to keep such a block changed (or count it unmapped only when all of it is), and the test should pin the second sync. title_memory_remapped in the test (descriptor.rs:1118) also stands in for a report the runtime does not make on a 4 KiB decommit.
  • cost, descriptor.rs:174 to :208. a fully readable 64 KiB block went from one probe and one sync_slots call to 16 of each, and each call allocates two vectors and takes VIEWS and made, all under SHADER_HEAPS. take already knows which blocks are whole: a block it guarded had VirtualProtect succeed over all 64 KiB, which fails if any page is not committed. if take handed those back apart, they could keep one call with no probe, and only the blocks it could not guard would need the 4 KiB walk. that keeps your safety and takes the cost off the common case.
  • the edge path, descriptor.rs:185 to :202, has no test (every test heap starts on a 64 KiB boundary, so straddling returns at its first check) and this title never takes it. two things in it: a slot whose record ends before base is still treated as straddling, so with an unaligned start it is mirrored and counted a second time; and the closure is named like a check but probes, mirrors and counts. a heap at pool + 8 with the second page decommitted would cover it.
  • the comment at descriptor.rs:169 says mappings and commits change per 4 KiB page. the runtime maps and unmaps physical pages in whole 64 KiB pages; only a commit at an address through XMemVirtualAlloc or the title's own VirtualFree can be finer. worth saying which, since that is the whole case for the change.
  • not this pr's, but on the same premise: watch.rs:450 gives write access back with one VirtualProtect over the 64 KiB block and ignores the result. if a guarded block loses one 4 KiB page, the next write to another page of it faults, the reopen fails, the write faults again and is passed on (by reading; i did not run that one). so a title that did decommit this way would hit the write guard before it hit sync_heaps.

nothing in sync_heap itself is a wrong result: for an aligned heap the same slots reach sync_slots in the same order as on main, and the index arithmetic and casts hold.

**@⁠imjustprism** on GitHub · 2026-11-26 19:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#pullrequestreview-6079890574) · **reviewed** ran dac5a4f in the title to get the two things the triage asks for: whether the world ever shows a heap block with only some of its 4 KiB pages readable, and what the finer probe costs. rx 9070 xt, world, medians per frame: | per frame | without, 6 runs | with this pr, run 1 | run 2 | |---|---|---|---| | 4 KiB probes | | 2,715 | 2,348 | | probes that failed | | 0 | 0 | | 64 KiB blocks with both readable and unreadable pages | | 0 | 0 | | slots that took the edge path (`straddling`) | | not counted | 0 | | time in the probes, ms | | not timed | 1.1 | | heap sync (`sync_heaps`), ms | 10.6 to 14.3 | 16.4 | 12.0 | | slots scanned | 308,000 to 379,000 | 347,000 | 301,000 | | heap sync, ms per 100,000 slots | 3.0 to 3.9 | 4.7 | 4.0 | 63bcca4 plus #2122 (this card needs it) plus local timers and counters, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run. of the six runs without, two are plain, three have #2051 and one has #3139 merged in; neither changes how often this path probes. no errors and no device removed in any run. so, in 24 minutes of world here: no probe failed and no block was partly readable, the edge path never ran (so the heap starts on a slot boundary), and the 16 times finer probe costs about 1.1 ms a frame in the probes alone. the whole sync per slot was above every run without in both runs, by 3% and by 21% over the highest of them; the two runs differ from each other as much as that, so beyond the probes' 1.1 ms i would not put a number on it. i also read the title's executable for where such a layout could come from. in what a static read shows, its own calls that free memory release whole regions and none decommits part of one, and its `XMemVirtualAlloc` calls reserve and commit in one call or re-reserve the pieces of a split reservation; none commits pieces inside a reservation it already holds. calls through pointers are not resolved by that, so it is not proof, but it agrees with the runs: i found nothing in this title that makes the layout. what i checked from the description: - `sync_heaps_handles_partially_committed_64k_pages` and the other `descriptor` tests pass here (hardware adapter). - "the `SyncSlots` diagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above. - "faults on main" for case 1: by reading, yes (`sync_slots` reads the decommitted page raw). i did not run the test on main. - case 2, "skips the entire block without mirroring those descriptors": fixed for the first sync only, see the first point. points from reading the diff: - case 2 holds for one sync, `watch.rs:666` and `:701`. when guarding a block fails, `unmapped` asks about the block's first byte only. with the first 4 KiB decommitted the block is counted as taken, dropped from the changed set and never guarded, so no later write to its other pages is seen. i added a second write and a second sync at the end of your test (same state, slot 262, then `sync_heap`, then `assert!(host.made(262))`): it fails here. the cause is older than this pr, but it means the second half of the fix needs `watch` to keep such a block changed (or count it unmapped only when all of it is), and the test should pin the second sync. `title_memory_remapped` in the test (`descriptor.rs:1118`) also stands in for a report the runtime does not make on a 4 KiB decommit. - cost, `descriptor.rs:174` to `:208`. a fully readable 64 KiB block went from one probe and one `sync_slots` call to 16 of each, and each call allocates two vectors and takes `VIEWS` and `made`, all under `SHADER_HEAPS`. `take` already knows which blocks are whole: a block it guarded had `VirtualProtect` succeed over all 64 KiB, which fails if any page is not committed. if `take` handed those back apart, they could keep one call with no probe, and only the blocks it could not guard would need the 4 KiB walk. that keeps your safety and takes the cost off the common case. - the edge path, `descriptor.rs:185` to `:202`, has no test (every test heap starts on a 64 KiB boundary, so `straddling` returns at its first check) and this title never takes it. two things in it: a slot whose record ends before `base` is still treated as straddling, so with an unaligned start it is mirrored and counted a second time; and the closure is named like a check but probes, mirrors and counts. a heap at `pool + 8` with the second page decommitted would cover it. - the comment at `descriptor.rs:169` says mappings and commits change per 4 KiB page. the runtime maps and unmaps physical pages in whole 64 KiB pages; only a commit at an address through `XMemVirtualAlloc` or the title's own `VirtualFree` can be finer. worth saying which, since that is the whole case for the change. - not this pr's, but on the same premise: `watch.rs:450` gives write access back with one `VirtualProtect` over the 64 KiB block and ignores the result. if a guarded block loses one 4 KiB page, the next write to another page of it faults, the reopen fails, the write faults again and is passed on (by reading; i did not run that one). so a title that did decommit this way would hit the write guard before it hit `sync_heaps`. nothing in `sync_heap` itself is a wrong result: for an aligned heap the same slots reach `sync_slots` in the same order as on main, and the index arithmetic and casts hold.
github-bot closed this pull request 2026-11-26 20:15:08 +00:00
Author
Owner

@⁠Texbirds on GitHub · 2026-11-26 20:11 UTC · original

ran dac5a4f in the title to get the two things the triage asks for: whether the world ever shows a heap block with only some of its 4 KiB pages readable, and what the finer probe costs. rx 9070 xt, world, medians per frame:

per frame without, 6 runs with this pr, run 1 run 2
4 KiB probes 2,715 2,348
probes that failed 0 0
64 KiB blocks with both readable and unreadable pages 0 0
slots that took the edge path (straddling) not counted 0
time in the probes, ms not timed 1.1
heap sync (sync_heaps), ms 10.6 to 14.3 16.4 12.0
slots scanned 308,000 to 379,000 347,000 301,000
heap sync, ms per 100,000 slots 3.0 to 3.9 4.7 4.0
63bcca4 plus #2122 (this card needs it) plus local timers and counters, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run. of the six runs without, two are plain, three have #2051 and one has #3139 merged in; neither changes how often this path probes. no errors and no device removed in any run.

so, in 24 minutes of world here: no probe failed and no block was partly readable, the edge path never ran (so the heap starts on a slot boundary), and the 16 times finer probe costs about 1.1 ms a frame in the probes alone. the whole sync per slot was above every run without in both runs, by 3% and by 21% over the highest of them; the two runs differ from each other as much as that, so beyond the probes' 1.1 ms i would not put a number on it.

i also read the title's executable for where such a layout could come from. in what a static read shows, its own calls that free memory release whole regions and none decommits part of one, and its XMemVirtualAlloc calls reserve and commit in one call or re-reserve the pieces of a split reservation; none commits pieces inside a reservation it already holds. calls through pointers are not resolved by that, so it is not proof, but it agrees with the runs: i found nothing in this title that makes the layout.

what i checked from the description:

  • sync_heaps_handles_partially_committed_64k_pages and the other descriptor tests pass here (hardware adapter).
  • "the SyncSlots diagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above.
  • "faults on main" for case 1: by reading, yes (sync_slots reads the decommitted page raw). i did not run the test on main.
  • case 2, "skips the entire block without mirroring those descriptors": fixed for the first sync only, see the first point.

points from reading the diff:

  • case 2 holds for one sync, watch.rs:666 and :701. when guarding a block fails, unmapped asks about the block's first byte only. with the first 4 KiB decommitted the block is counted as taken, dropped from the changed set and never guarded, so no later write to its other pages is seen. i added a second write and a second sync at the end of your test (same state, slot 262, then sync_heap, then assert!(host.made(262))): it fails here. the cause is older than this pr, but it means the second half of the fix needs watch to keep such a block changed (or count it unmapped only when all of it is), and the test should pin the second sync. title_memory_remapped in the test (descriptor.rs:1118) also stands in for a report the runtime does not make on a 4 KiB decommit.
  • cost, descriptor.rs:174 to :208. a fully readable 64 KiB block went from one probe and one sync_slots call to 16 of each, and each call allocates two vectors and takes VIEWS and made, all under SHADER_HEAPS. take already knows which blocks are whole: a block it guarded had VirtualProtect succeed over all 64 KiB, which fails if any page is not committed. if take handed those back apart, they could keep one call with no probe, and only the blocks it could not guard would need the 4 KiB walk. that keeps your safety and takes the cost off the common case.
  • the edge path, descriptor.rs:185 to :202, has no test (every test heap starts on a 64 KiB boundary, so straddling returns at its first check) and this title never takes it. two things in it: a slot whose record ends before base is still treated as straddling, so with an unaligned start it is mirrored and counted a second time; and the closure is named like a check but probes, mirrors and counts. a heap at pool + 8 with the second page decommitted would cover it.
  • the comment at descriptor.rs:169 says mappings and commits change per 4 KiB page. the runtime maps and unmaps physical pages in whole 64 KiB pages; only a commit at an address through XMemVirtualAlloc or the title's own VirtualFree can be finer. worth saying which, since that is the whole case for the change.
  • not this pr's, but on the same premise: watch.rs:450 gives write access back with one VirtualProtect over the 64 KiB block and ignores the result. if a guarded block loses one 4 KiB page, the next write to another page of it faults, the reopen fails, the write faults again and is passed on (by reading; i did not run that one). so a title that did decommit this way would hit the write guard before it hit sync_heaps.

nothing in sync_heap itself is a wrong result: for an aligned heap the same slots reach sync_slots in the same order as on main, and the index arithmetic and casts hold.

Thanks a lot for running the 24-minute world measurements and checking the title's allocation paths — that gives a clear answer.

With 0 failed probes, 0 partially readable 64 KiB blocks, 0 straddling slots, and ~1.1 ms/frame of probe overhead (plus watch.rs itself assuming 64 KiB granularity on reopen/unmapped checks), this guard isn't worth the hot-path cost. Closing this PR — appreciate the thorough review and data!

**@⁠Texbirds** on GitHub · 2026-11-26 20:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2447#issuecomment-7202400762) > ran [dac5a4f](https://github.com/Marvisak/VIctory/commit/dac5a4ff029724656a2db322377bfa96c86902f0) in the title to get the two things the triage asks for: whether the world ever shows a heap block with only some of its 4 KiB pages readable, and what the finer probe costs. rx 9070 xt, world, medians per frame: > > per frame without, 6 runs with this pr, run 1 run 2 > 4 KiB probes 2,715 2,348 > probes that failed 0 0 > 64 KiB blocks with both readable and unreadable pages 0 0 > slots that took the edge path (`straddling`) not counted 0 > time in the probes, ms not timed 1.1 > heap sync (`sync_heaps`), ms 10.6 to 14.3 16.4 12.0 > slots scanned 308,000 to 379,000 347,000 301,000 > heap sync, ms per 100,000 slots 3.0 to 3.9 4.7 4.0 > [63bcca4](https://github.com/Marvisak/VIctory/commit/63bcca43c6a00a758510398fa43096ce7e4f7df0) plus #2122 (this card needs it) plus local timers and counters, with and without this pr merged in. diag build, series-x, the same scripted key presses, warm shader and pipeline caches, quiet machine, 12-minute runs, medians over 47 to 73 world frame lines per run. of the six runs without, two are plain, three have #2051 and one has #3139 merged in; neither changes how often this path probes. no errors and no device removed in any run. > > so, in 24 minutes of world here: no probe failed and no block was partly readable, the edge path never ran (so the heap starts on a slot boundary), and the 16 times finer probe costs about 1.1 ms a frame in the probes alone. the whole sync per slot was above every run without in both runs, by 3% and by 21% over the highest of them; the two runs differ from each other as much as that, so beyond the probes' 1.1 ms i would not put a number on it. > > i also read the title's executable for where such a layout could come from. in what a static read shows, its own calls that free memory release whole regions and none decommits part of one, and its `XMemVirtualAlloc` calls reserve and commit in one call or re-reserve the pieces of a split reservation; none commits pieces inside a reservation it already holds. calls through pointers are not resolved by that, so it is not proof, but it agrees with the runs: i found nothing in this title that makes the layout. > > what i checked from the description: > > * `sync_heaps_handles_partially_committed_64k_pages` and the other `descriptor` tests pass here (hardware adapter). > * "the `SyncSlots` diagnostics count is unchanged": yes for a heap that starts on a slot boundary, by reading and by the slot counts above. > * "faults on main" for case 1: by reading, yes (`sync_slots` reads the decommitted page raw). i did not run the test on main. > * case 2, "skips the entire block without mirroring those descriptors": fixed for the first sync only, see the first point. > > points from reading the diff: > > * case 2 holds for one sync, `watch.rs:666` and `:701`. when guarding a block fails, `unmapped` asks about the block's first byte only. with the first 4 KiB decommitted the block is counted as taken, dropped from the changed set and never guarded, so no later write to its other pages is seen. i added a second write and a second sync at the end of your test (same state, slot 262, then `sync_heap`, then `assert!(host.made(262))`): it fails here. the cause is older than this pr, but it means the second half of the fix needs `watch` to keep such a block changed (or count it unmapped only when all of it is), and the test should pin the second sync. `title_memory_remapped` in the test (`descriptor.rs:1118`) also stands in for a report the runtime does not make on a 4 KiB decommit. > * cost, `descriptor.rs:174` to `:208`. a fully readable 64 KiB block went from one probe and one `sync_slots` call to 16 of each, and each call allocates two vectors and takes `VIEWS` and `made`, all under `SHADER_HEAPS`. `take` already knows which blocks are whole: a block it guarded had `VirtualProtect` succeed over all 64 KiB, which fails if any page is not committed. if `take` handed those back apart, they could keep one call with no probe, and only the blocks it could not guard would need the 4 KiB walk. that keeps your safety and takes the cost off the common case. > * the edge path, `descriptor.rs:185` to `:202`, has no test (every test heap starts on a 64 KiB boundary, so `straddling` returns at its first check) and this title never takes it. two things in it: a slot whose record ends before `base` is still treated as straddling, so with an unaligned start it is mirrored and counted a second time; and the closure is named like a check but probes, mirrors and counts. a heap at `pool + 8` with the second page decommitted would cover it. > * the comment at `descriptor.rs:169` says mappings and commits change per 4 KiB page. the runtime maps and unmaps physical pages in whole 64 KiB pages; only a commit at an address through `XMemVirtualAlloc` or the title's own `VirtualFree` can be finer. worth saying which, since that is the whole case for the change. > * not this pr's, but on the same premise: `watch.rs:450` gives write access back with one `VirtualProtect` over the 64 KiB block and ignores the result. if a guarded block loses one 4 KiB page, the next write to another page of it faults, the reopen fails, the write faults again and is passed on (by reading; i did not run that one). so a title that did decommit this way would hit the write guard before it hit `sync_heaps`. > > nothing in `sync_heap` itself is a wrong result: for an aligned heap the same slots reach `sync_slots` in the same order as on main, and the index arithmetic and casts hold. Thanks a lot for running the 24-minute world measurements and checking the title's allocation paths — that gives a clear answer. With 0 failed probes, 0 partially readable 64 KiB blocks, 0 straddling slots, and ~1.1 ms/frame of probe overhead (plus `watch.rs` itself assuming 64 KiB granularity on reopen/unmapped checks), this guard isn't worth the hot-path cost. Closing this PR — appreciate the thorough review and data!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2447
No description provided.