startup: prove slot 133 placements without walking the allocation #1759

Merged
rasptum merged 9 commits from upstream-pr/1766 into main 2026-11-24 21:46:59 +00:00
rasptum commented 2026-11-24 18:15:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T18:15:37Z.


Problem

Device slot 133 (device_place_resource_x in src/startup_stubs/d3d12_xs_device.cpp) aliases a buffer at a title address only if the memory is private and every byte from the base of the allocation holding the address to the end of the buffer is committed in that allocation. To decide this, it measured the whole committed run from the base, one VirtualQuery per region, and compared the buffer with that length.

VirtualQuery reports RegionSize by scanning page-table entries from the queried address to the end of the run of identical attributes. On a large private region with touched pages, each call therefore costs milliseconds.

Synthetic measurements, Windows 10 19045, ms per call:

Block (one touched page per 64 KiB) at the base from the middle last 64 KiB
1 GiB 5.5 2.4 0.002
2 GiB 11.9 6.0 0.002
4 GiB 26.0 12.9 0.002
1 GiB, every 4 KiB page touched 22.7 12.3 0.002
untouched, any size about 0.01 about 0 about 0

The cost follows the distance to the next attribute change, so even a walk that stops at the end of the buffer pays it in full when the buffer starts inside a large region.

Change

src/startup_stubs/placed_buffer_range.h (new, testable without a device) proves each placement at call time and keeps nothing between calls:

  1. QueryVirtualMemoryInformation(MemoryRegionInfo) (Windows 10 1607 and later, resolved with GetProcAddress) reports the base, size and committed bytes of the allocation holding the address. These come from the allocation's bookkeeping, without the scan: about 0.0004 ms per call on the blocks above. When the allocation is private and its committed bytes equal its size, every page is committed, so the full walk's committed run is the whole allocation. The decision then follows exactly from base and size.
  2. Anything else takes the original walk from the base, stopped at the end of the buffer, because regions after it cannot change the answer. "Anything else" means a partly committed or mapped allocation, a free address, or the export missing (older systems, compatibility layers).

The decision equals the full walk's in every case. A page decommitted, released or replaced directly through the Windows API is seen by the next placement. Unchanged: 64 KiB offset alignment, MEM_PRIVATE only, the acceleration-structure refusal, existing-heap reuse, and slot 133's log lines.

The five-second x2w-d3d12 views noted line in stderr.txt ends with placed buffers <n> (region-information proofs <n>, region queries <n>). docs/startup-runtime.md describes this.

Committed-bytes exactness: for private allocations, the committed-bytes value matched a full VirtualQuery count of committed pages in every case tried:

  • decommit and recommit of 64 KiB and 4 KiB, each repeated;
  • commit of already committed pages;
  • PAGE_NOACCESS and PAGE_GUARD;
  • MEM_RESET;
  • reserve-then-commit;
  • a private allocation replacing a placeholder piece.

A mapped view reports flags 0x8 with no committed bytes, and a free address makes the call fail. Both take the walk.

History: the first version of this PR cached measured extents and validated hits with VirtualQuery at the buffer's first and last byte. Review showed that this does not prove a contiguous committed prefix, so the cache was removed. A walk stopped at the buffer end was exact, but slower than the original code in a startup run, for the reason above. This version keeps that walk only as the fallback.

Measured in a run

In a local startup run on Windows 10 (RTX 3060), the time from launch to the first interactive screen was 72.6 s, against 81 to 94 s with the earlier cache and 197 to 252 s with the bounded walk alone. Of 3,388 placements, 3,259 were proven by region information and 129 fell back to the walk (343 VirtualQuery calls in total).

Tests

startup_placed_buffer_range runs on the CPU only, with no device. It compares every alias or refusal, base and type with the full walk (the old code, kept in the test as the reference) on the same memory at the same moment. Each case places a buffer, then changes the memory, then places again, and also asserts the expected decision.

  1. 256 buffers over a 64 MiB block whose alternating 64 KiB pages have different protections, plus misaligned, past-the-end and base placements.
  2. A middle page decommitted: a buffer after the gap, across it, before it and on it.
  3. The same page committed again.
  4. Page 1 of eight decommitted, buffer on page 6 and on pages 6 and 7.
  5. A reviewed repro: 1 MiB committed, a 64 KiB buffer at +0x80000, then 0x10000 bytes at +0x10000 decommitted. The buffer is refused.
  6. Same-base replacement: 64 MiB released, 1 MiB committed at its base. A buffer inside, one ending past the new end and one past it.
  7. A mapped view.
  8. A reservation committed in two steps.
  9. A placeholder piece replaced by committed private memory: a buffer inside it and one ending in the placeholder after it.
  10. Other private allocations:
    • MEM_WRITE_WATCH, MEM_TOP_DOWN and PAGE_EXECUTE_READWRITE allocations, proven by region information;
    • a large heap block, whose allocation starts with reserved pages, so both the proof and the full walk refuse it;
    • an AWE (MEM_PHYSICAL) reservation, with nothing committed;
    • MEM_LARGE_PAGES when the process may lock pages (otherwise reported as not run).
  11. A 512 MiB committed block with one touched page per 64 KiB: 64 placements must be proven with no VirtualQuery call. This is a call count, not a time. The check prints the time per placement: full walk 4.7 ms, bounded walk 4.6 ms, region proof 0.0004 ms (dev; release was similar).

Command (Windows 10 19045, MSVC 19.44, RTX 3060; _warp tests use WARP, _hardware tests the RTX 3060), run in both dev and release:

ctest --preset release --no-tests=error -R '^(startup_placed_buffer_range.*|startup_placed_vertex_.*|xmem_page_runs_device_.*|startup_placement_.*|cpu_placed_draw_.*)$' -V

Observed: 12 of 12 passed, 0 failed, 0 skipped, in both presets. Besides the new check and its two controls, the selection covers the existing device tests that exercise slot 133 and the neighbouring placement checks: startup_placed_vertex_{warp,hardware}, xmem_page_runs_device_{warp,hardware}, cpu_placed_draw_{warp,hardware} and startup_placement_{alloc,publish,publish_shrink_control}. They pass unchanged. tests/docs_links_check.py passes. The branch merges current main (db924b76).

Negative controls

Both controls are registered with WILL_FAIL. Each exits 1 only when it fails for its stated reason and nothing else fails, and exits 77 (a capability skip) if an allocation or mapping is refused.

  • startup_placed_buffer_range_region_only_control (--mutate region-only) trusts the allocation size without the committed-bytes check. Observed: 10 placements differ from the full walk, all in the partly committed cases (2, 4, 5, 8, the heap block and the AWE reservation), and none elsewhere.
  • startup_placed_buffer_range_walk_only_control (--mutate walk-only) never uses the region information. Observed: decisions all match, and only the call count of the 512 MiB case fails (0 of 64 region proofs, 128 VirtualQuery calls).

Not covered

  • Partly committed private allocations still take the walk and pay the VirtualQuery cost (129 of 3,388 placements in the run above).
  • MEM_LARGE_PAGES needs the lock-pages privilege and was not run here. An AWE region with physical pages mapped needs the same privilege and was not tried; an AWE reservation reports the private flag with no committed bytes and takes the walk.
  • The device tests exercise the proof only indirectly. The counter shows the split between region-information proofs and region queries in a run.
  • This change does not establish that anything starts or renders.

AI-assisted (Claude Code).
🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588443212 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T18:15:37Z. --- ## Problem Device slot 133 (`device_place_resource_x` in `src/startup_stubs/d3d12_xs_device.cpp`) aliases a buffer at a title address only if the memory is private and every byte from the base of the allocation holding the address to the end of the buffer is committed in that allocation. To decide this, it measured the whole committed run from the base, one `VirtualQuery` per region, and compared the buffer with that length. `VirtualQuery` reports `RegionSize` by scanning page-table entries from the queried address to the end of the run of identical attributes. On a large private region with touched pages, each call therefore costs milliseconds. Synthetic measurements, Windows 10 19045, ms per call: | Block (one touched page per 64 KiB) | at the base | from the middle | last 64 KiB | |---|---|---|---| | 1 GiB | 5.5 | 2.4 | 0.002 | | 2 GiB | 11.9 | 6.0 | 0.002 | | 4 GiB | 26.0 | 12.9 | 0.002 | | 1 GiB, every 4 KiB page touched | 22.7 | 12.3 | 0.002 | | untouched, any size | about 0.01 | about 0 | about 0 | The cost follows the distance to the next attribute change, so even a walk that stops at the end of the buffer pays it in full when the buffer starts inside a large region. ## Change `src/startup_stubs/placed_buffer_range.h` (new, testable without a device) proves each placement at call time and keeps nothing between calls: 1. **`QueryVirtualMemoryInformation(MemoryRegionInfo)`** (Windows 10 1607 and later, resolved with `GetProcAddress`) reports the base, size and committed bytes of the allocation holding the address. These come from the allocation's bookkeeping, without the scan: about 0.0004 ms per call on the blocks above. When the allocation is private and its committed bytes equal its size, every page is committed, so the full walk's committed run is the whole allocation. The decision then follows exactly from base and size. 2. **Anything else** takes the original walk from the base, stopped at the end of the buffer, because regions after it cannot change the answer. "Anything else" means a partly committed or mapped allocation, a free address, or the export missing (older systems, compatibility layers). The decision equals the full walk's in every case. A page decommitted, released or replaced directly through the Windows API is seen by the next placement. Unchanged: 64 KiB offset alignment, `MEM_PRIVATE` only, the acceleration-structure refusal, existing-heap reuse, and slot 133's log lines. The five-second `x2w-d3d12 views noted` line in `stderr.txt` ends with `placed buffers <n> (region-information proofs <n>, region queries <n>)`. `docs/startup-runtime.md` describes this. **Committed-bytes exactness:** for private allocations, the committed-bytes value matched a full `VirtualQuery` count of committed pages in every case tried: - decommit and recommit of 64 KiB and 4 KiB, each repeated; - commit of already committed pages; - `PAGE_NOACCESS` and `PAGE_GUARD`; - `MEM_RESET`; - reserve-then-commit; - a private allocation replacing a placeholder piece. A mapped view reports flags 0x8 with no committed bytes, and a free address makes the call fail. Both take the walk. **History:** the first version of this PR cached measured extents and validated hits with `VirtualQuery` at the buffer's first and last byte. Review showed that this does not prove a contiguous committed prefix, so the cache was removed. A walk stopped at the buffer end was exact, but slower than the original code in a startup run, for the reason above. This version keeps that walk only as the fallback. ## Measured in a run In a local startup run on Windows 10 (RTX 3060), the time from launch to the first interactive screen was 72.6 s, against 81 to 94 s with the earlier cache and 197 to 252 s with the bounded walk alone. Of 3,388 placements, 3,259 were proven by region information and 129 fell back to the walk (343 `VirtualQuery` calls in total). ## Tests `startup_placed_buffer_range` runs on the CPU only, with no device. It compares every alias or refusal, base and type with the full walk (the old code, kept in the test as the reference) on the same memory at the same moment. Each case places a buffer, then changes the memory, then places again, and also asserts the expected decision. 1. 256 buffers over a 64 MiB block whose alternating 64 KiB pages have different protections, plus misaligned, past-the-end and base placements. 2. A middle page decommitted: a buffer after the gap, across it, before it and on it. 3. The same page committed again. 4. Page 1 of eight decommitted, buffer on page 6 and on pages 6 and 7. 5. A reviewed repro: 1 MiB committed, a 64 KiB buffer at +0x80000, then 0x10000 bytes at +0x10000 decommitted. The buffer is refused. 6. Same-base replacement: 64 MiB released, 1 MiB committed at its base. A buffer inside, one ending past the new end and one past it. 7. A mapped view. 8. A reservation committed in two steps. 9. A placeholder piece replaced by committed private memory: a buffer inside it and one ending in the placeholder after it. 10. Other private allocations: - `MEM_WRITE_WATCH`, `MEM_TOP_DOWN` and `PAGE_EXECUTE_READWRITE` allocations, proven by region information; - a large heap block, whose allocation starts with reserved pages, so both the proof and the full walk refuse it; - an AWE (`MEM_PHYSICAL`) reservation, with nothing committed; - `MEM_LARGE_PAGES` when the process may lock pages (otherwise reported as not run). 11. A 512 MiB committed block with one touched page per 64 KiB: 64 placements must be proven with no `VirtualQuery` call. This is a call count, not a time. The check prints the time per placement: full walk 4.7 ms, bounded walk 4.6 ms, region proof 0.0004 ms (`dev`; `release` was similar). Command (Windows 10 19045, MSVC 19.44, RTX 3060; `_warp` tests use WARP, `_hardware` tests the RTX 3060), run in both `dev` and `release`: ``` ctest --preset release --no-tests=error -R '^(startup_placed_buffer_range.*|startup_placed_vertex_.*|xmem_page_runs_device_.*|startup_placement_.*|cpu_placed_draw_.*)$' -V ``` Observed: 12 of 12 passed, 0 failed, 0 skipped, in both presets. Besides the new check and its two controls, the selection covers the existing device tests that exercise slot 133 and the neighbouring placement checks: `startup_placed_vertex_{warp,hardware}`, `xmem_page_runs_device_{warp,hardware}`, `cpu_placed_draw_{warp,hardware}` and `startup_placement_{alloc,publish,publish_shrink_control}`. They pass unchanged. `tests/docs_links_check.py` passes. The branch merges current main (db924b76). ## Negative controls Both controls are registered with `WILL_FAIL`. Each exits 1 only when it fails for its stated reason and nothing else fails, and exits 77 (a capability skip) if an allocation or mapping is refused. - `startup_placed_buffer_range_region_only_control` (`--mutate region-only`) trusts the allocation size without the committed-bytes check. Observed: 10 placements differ from the full walk, all in the partly committed cases (2, 4, 5, 8, the heap block and the AWE reservation), and none elsewhere. - `startup_placed_buffer_range_walk_only_control` (`--mutate walk-only`) never uses the region information. Observed: decisions all match, and only the call count of the 512 MiB case fails (0 of 64 region proofs, 128 `VirtualQuery` calls). ## Not covered - Partly committed private allocations still take the walk and pay the `VirtualQuery` cost (129 of 3,388 placements in the run above). - `MEM_LARGE_PAGES` needs the lock-pages privilege and was not run here. An AWE region with physical pages mapped needs the same privilege and was not tried; an AWE reservation reports the private flag with no committed bytes and takes the walk. - The device tests exercise the proof only indirectly. The counter shows the split between region-information proofs and region queries in a run. - This change does not establish that anything starts or renders. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-11-24 19:01:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T18:38:02Z.


The first and last VirtualQuery results do not establish a contiguous committed range. For example, after caching a private three-page allocation, the middle page can be decommitted while the first and last pages remain committed with the same AllocationBase. The uncached walk stops at the gap, but still_valid accepts both endpoints and returns the old extent. A gap before the requested start also changes the original walk's answer. Before using a hit, prove the full committed prefix needed by slot 133 or use reliable invalidation tied to the allocator lifecycle. Please add a source-built middle-page decommit/recommit control and compare the alias/refusal decision with the uncached path. Keep the same-base replacement controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7140919088 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766#issuecomment-7140919088). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T18:38:02Z. --- The first and last VirtualQuery results do not establish a contiguous committed range. For example, after caching a private three-page allocation, the middle page can be decommitted while the first and last pages remain committed with the same AllocationBase. The uncached walk stops at the gap, but still_valid accepts both endpoints and returns the old extent. A gap before the requested start also changes the original walk's answer. Before using a hit, prove the full committed prefix needed by slot 133 or use reliable invalidation tied to the allocator lifecycle. Please add a source-built middle-page decommit/recommit control and compare the alias/refusal decision with the uncached path. Keep the same-base replacement controls.
tedin7 commented 2026-11-24 20:00:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:05:41Z.

Review: COMMENTED


Peer review of head 229f7b1350f3057bc75c3f5d0eacf11d422376fc (PRODUCTION_REVIEW_ONLY, technical comment only).

One P2 finding (a documented limitation that is wider than documented). No P1.

P2: src/startup_stubs/placed_allocation_cache.h, measure() / still_valid() (lines ~66-70 and ~101-113).
The uncached walk counts committed bytes contiguously from the allocation base and stops at the first hole. A cache hit only re-queries the region at the buffer's first byte and the region at its last byte. Pages decommitted between the base and the first queried region are therefore not noticed either, not only pages between the two queried regions as docs/startup-runtime.md states. The cached extent.bytes stays too large, so slot 133 accepts a placement the uncached path refuses (offset > allocation_bytes gives E_INVALIDARG).

Reproduction (local, mingw-w64 build of placed_allocation_cache.h run under wine):

  1. VirtualAlloc 1 MiB committed.
  2. measure(p+0x80000, 0x10000) remembers the extent (0x100000).
  3. VirtualFree(p+0x10000, 0x10000, MEM_DECOMMIT).
  4. measure(p+0x80000, 0x10000) is a cache hit and returns bytes=0x100000. measure_allocation() on the same address returns bytes=0x10000, so the original code returns E_INVALIDARG.

Impact: the placement then reaches CreatePlacedResource, which the code comment says throws inside D3D12Core, instead of being skipped. The comment in the docs says no stand-in decommits part of an allocation, so this is low-likelihood. Either widen the doc sentence to "anywhere before the buffer's last byte", or add a cheap guard (for example drop the entry on VirtualFree or MEM_DECOMMIT hooks, or bound the cache lifetime).

Everything else checked without findings:

  • The lookup (upper_bound, then last - base < bytes) and the overflow guard on start + span - 1.
  • remember() drops overlapping entries, so a block replaced at the same base is handled.
  • Locking: a shared lock for lookup, exclusive for change, and the OOM path falls back to measuring again.
  • The call site keeps the E_POINTER / desc checks before desc->Width is read.
  • The second query is skipped only when one region covers the whole buffer.

Local mutation (restored with git checkout -- .): on a cache hit, out = known changed to out = known; out.bytes += 0x10000;. startup_placed_allocation_cache_check fails with "258 failure(s)" ("partly committed: inside the larger extent: expected bytes=0x200000, got 0x210000"). A second mutation, last - base < bytes changed to start - base < bytes, survives. It is masked by the last-byte region query in still_valid(), so the behaviour is equivalent; I am not asking for a new test for it.

Commands run:

  • git diff --check <merge-base>...HEAD: clean
  • tests/bidi_controls_check.py: pass
  • docs_links_check: not applicable, docs only gained a section
  • mingw-w64 g++ -std=c++17 -O2 build of tests/startup_placed_allocation_cache_check.cpp, run under wine: default run passes ("all cases match the uncached path", 256 of 256 accepted, 2 walks, 256 saved). --mutate none and --mutate address-only fail for the stated reasons.
  • Reproduction program for the finding (same build).
  • Windows Server 2025 (build 26100, MSVC 14.44, WARP) at the same commit 229f7b13, target startup_placed_allocation_cache_check, regex ^startup_placed_allocation_cache:
    • Debug (--preset dev): 3/3 tests passed
    • Release /O2 (--preset release): 3/3 tests passed
  • The PR merges cleanly with current main (git merge-tree).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045574078 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766#pullrequestreview-6045574078). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:05:41Z. **Review:** COMMENTED --- Peer review of head `229f7b1350f3057bc75c3f5d0eacf11d422376fc` (PRODUCTION_REVIEW_ONLY, technical comment only). **One P2 finding (a documented limitation that is wider than documented). No P1.** **P2: `src/startup_stubs/placed_allocation_cache.h`, `measure()` / `still_valid()` (lines ~66-70 and ~101-113).** The uncached walk counts committed bytes contiguously from the allocation base and stops at the first hole. A cache hit only re-queries the region at the buffer's first byte and the region at its last byte. Pages decommitted between the base and the first queried region are therefore not noticed either, not only pages between the two queried regions as docs/startup-runtime.md states. The cached `extent.bytes` stays too large, so slot 133 accepts a placement the uncached path refuses (`offset > allocation_bytes` gives `E_INVALIDARG`). Reproduction (local, mingw-w64 build of `placed_allocation_cache.h` run under wine): 1. `VirtualAlloc` 1 MiB committed. 2. `measure(p+0x80000, 0x10000)` remembers the extent (0x100000). 3. `VirtualFree(p+0x10000, 0x10000, MEM_DECOMMIT)`. 4. `measure(p+0x80000, 0x10000)` is a cache hit and returns bytes=0x100000. `measure_allocation()` on the same address returns bytes=0x10000, so the original code returns `E_INVALIDARG`. Impact: the placement then reaches `CreatePlacedResource`, which the code comment says throws inside D3D12Core, instead of being skipped. The comment in the docs says no stand-in decommits part of an allocation, so this is low-likelihood. Either widen the doc sentence to "anywhere before the buffer's last byte", or add a cheap guard (for example drop the entry on `VirtualFree` or `MEM_DECOMMIT` hooks, or bound the cache lifetime). Everything else checked without findings: - The lookup (`upper_bound`, then `last - base < bytes`) and the overflow guard on `start + span - 1`. - `remember()` drops overlapping entries, so a block replaced at the same base is handled. - Locking: a shared lock for lookup, exclusive for change, and the OOM path falls back to measuring again. - The call site keeps the `E_POINTER` / `desc` checks before `desc->Width` is read. - The second query is skipped only when one region covers the whole buffer. Local mutation (restored with `git checkout -- .`): on a cache hit, `out = known` changed to `out = known; out.bytes += 0x10000;`. `startup_placed_allocation_cache_check` fails with "258 failure(s)" ("partly committed: inside the larger extent: expected bytes=0x200000, got 0x210000"). A second mutation, `last - base < bytes` changed to `start - base < bytes`, survives. It is masked by the last-byte region query in `still_valid()`, so the behaviour is equivalent; I am not asking for a new test for it. Commands run: - `git diff --check <merge-base>...HEAD`: clean - `tests/bidi_controls_check.py`: pass - docs_links_check: not applicable, docs only gained a section - mingw-w64 g++ -std=c++17 -O2 build of `tests/startup_placed_allocation_cache_check.cpp`, run under wine: default run passes ("all cases match the uncached path", 256 of 256 accepted, 2 walks, 256 saved). `--mutate none` and `--mutate address-only` fail for the stated reasons. - Reproduction program for the finding (same build). - Windows Server 2025 (build 26100, MSVC 14.44, WARP) at the same commit `229f7b13`, target `startup_placed_allocation_cache_check`, regex `^startup_placed_allocation_cache`: - Debug (`--preset dev`): 3/3 tests passed - Release `/O2` (`--preset release`): 3/3 tests passed - The PR merges cleanly with current `main` (`git merge-tree`). AI-assisted; commands listed were executed locally.
upstream-sync changed title from [PR #1766] startup: cache placed-buffer allocation extents (slot 133) to [PR #1766] startup: prove slot 133 placements without walking the allocation 2026-11-24 22:00:43 +00:00
upstream-sync closed this pull request 2026-11-24 22:00:43 +00:00
R0Y00 commented 2026-11-24 22:00:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:32:15Z.

Review: CHANGES_REQUESTED


The endpoint checks can both pass after a middle page of the same MEM_PRIVATE allocation is decommitted. For a three-page fully committed allocation, warm the cache, decommit the middle page, then query the original full span: the old walk stops after page one, but the proposed hit still reports the old full extent. A gap can also sit before the placement start because the alias decision relies on the committed run from AllocationBase. Please require a current contiguous committed range from the base, or tie the cache to tracked allocation generations and page-state invalidation. Retain the existing walk for addresses without that lifetime contract. Add a source-built interior-decommit control with committed endpoints; both dispositions must agree with the original walk.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047754318 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766#pullrequestreview-6047754318). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:32:15Z. **Review:** CHANGES_REQUESTED --- The endpoint checks can both pass after a middle page of the same MEM_PRIVATE allocation is decommitted. For a three-page fully committed allocation, warm the cache, decommit the middle page, then query the original full span: the old walk stops after page one, but the proposed hit still reports the old full extent. A gap can also sit before the placement start because the alias decision relies on the committed run from AllocationBase. Please require a current contiguous committed range from the base, or tie the cache to tracked allocation generations and page-state invalidation. Retain the existing walk for addresses without that lifetime contract. Add a source-built interior-decommit control with committed endpoints; both dispositions must agree with the original walk.
R0Y00 commented 2026-11-24 22:00:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:46:49Z.

Review: APPROVED


Rechecked the replacement without a persistent extent cache. The Windows Release range test and both negative controls pass on this exact head. A partially committed allocation now walks from AllocationBase, so the middle decommit and gap before placement agree with the old walk.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047928662 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766#pullrequestreview-6047928662). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:46:49Z. **Review:** APPROVED --- Rechecked the replacement without a persistent extent cache. The Windows Release range test and both negative controls pass on this exact head. A partially committed allocation now walks from AllocationBase, so the middle decommit and gap before placement agree with the old walk.
rasptum commented 2026-11-24 22:01:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T21:36:25Z.


Thanks, you are right. Checking only the endpoints did not prove a contiguous committed prefix. After a private allocation was cached, decommitting a middle page left both endpoints committed with the same AllocationBase, so the cache kept accepting a buffer after the gap that the uncached walk refuses. A gap before the requested start went unseen in the same way.

What changed: the cache is gone, and nothing is kept between placements. Lifecycle invalidation cannot be made complete, because a consumer can call VirtualFree(MEM_DECOMMIT), or release and reallocate memory, directly through the Windows API, and the stand-ins never see that.

Each placement is now proven at call time (src/startup_stubs/placed_buffer_range.h):

  • First: QueryVirtualMemoryInformation(MemoryRegionInfo) reports the base, size and committed bytes of the allocation holding the address. When the allocation is private and its committed bytes equal its size, every page is committed, so the full walk's committed run is the whole allocation. The decision then follows exactly from base and size.
  • Otherwise: a partly committed or mapped allocation, a free address, or a missing export takes the original walk from the base, stopped at the end of the buffer.

In a local startup run on Windows 10 (RTX 3060), the time from launch to the first interactive screen was 72.6 s, against 81 to 94 s with the earlier cache and 197 to 252 s with the bounded walk alone. Of 3,388 placements, 3,259 were proven by region information and 129 fell back to the walk (343 VirtualQuery calls in total).

Why not only the bounded walk: in a startup run it was slower than the original code. VirtualQuery scans page-table entries up to the next attribute change, which costs milliseconds on large touched regions (synthetic: about 5 ms per GiB with one touched page per 64 KiB). The region-information call does not scan; it costs about 0.0004 ms. Its committed-bytes count matched a full VirtualQuery count for private allocations after decommit and recommit, double decommit, commit of committed pages, guard and no-access pages, MEM_RESET, reserve-then-commit and placeholder pieces.

startup_placed_buffer_range (replaces startup_placed_allocation_cache) compares every alias or refusal, base and type with the full walk on the same memory. Each case places a buffer first, then changes the memory, then places again:

  • a middle page decommitted under a buffer, before a buffer, and five pages before a buffer, then committed again;
  • the reviewed repro: 1 MiB committed, a buffer at +0x80000 for 0x10000 bytes, then +0x10000 decommitted for 0x10000 bytes;
  • the same-base replacement;
  • a mapped view;
  • a reservation committed in two steps;
  • a placeholder piece;
  • write-watch, top-down, executable, heap-block, AWE and (with the lock-pages privilege) large-page allocations;
  • a 64 MiB striped block;
  • a 512 MiB touched block, which must be proven with no VirtualQuery call.

The controls (WILL_FAIL) must fail only for their stated reason. --mutate region-only trusts the allocation size without the committed-bytes check and fails 10 placements, all in the partly committed cases. --mutate walk-only never uses the region information and fails only the call count.

@tedin7: your repro is a case in startup_placed_buffer_range with exactly those numbers. The endpoint-only cache at 229f7b13 accepted the second placement, while the current code refuses it, the same answer as the full walk. It is refused because a decommitted page makes the allocation's committed bytes smaller than its size, so the placement falls back to the walk from the base, which stops at the gap.

ctest --preset release --no-tests=error -R '^(startup_placed_buffer_range.*|startup_placed_vertex_.*|xmem_page_runs_device_.*|startup_placement_.*|cpu_placed_draw_.*)$' -V

Windows 10 19045, MSVC 19.44, RTX 3060 (WARP for _warp), dev and release, head 20f8e1d5 (merges current main): 12 of 12 passed, 0 failed, 0 skipped.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145152543 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1766#issuecomment-7145152543). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T21:36:25Z. --- Thanks, you are right. Checking only the endpoints did not prove a contiguous committed prefix. After a private allocation was cached, decommitting a middle page left both endpoints committed with the same AllocationBase, so the cache kept accepting a buffer after the gap that the uncached walk refuses. A gap before the requested start went unseen in the same way. What changed: the cache is gone, and nothing is kept between placements. Lifecycle invalidation cannot be made complete, because a consumer can call `VirtualFree(MEM_DECOMMIT)`, or release and reallocate memory, directly through the Windows API, and the stand-ins never see that. Each placement is now proven at call time (`src/startup_stubs/placed_buffer_range.h`): - **First:** `QueryVirtualMemoryInformation(MemoryRegionInfo)` reports the base, size and committed bytes of the allocation holding the address. When the allocation is private and its committed bytes equal its size, every page is committed, so the full walk's committed run is the whole allocation. The decision then follows exactly from base and size. - **Otherwise:** a partly committed or mapped allocation, a free address, or a missing export takes the original walk from the base, stopped at the end of the buffer. In a local startup run on Windows 10 (RTX 3060), the time from launch to the first interactive screen was 72.6 s, against 81 to 94 s with the earlier cache and 197 to 252 s with the bounded walk alone. Of 3,388 placements, 3,259 were proven by region information and 129 fell back to the walk (343 `VirtualQuery` calls in total). Why not only the bounded walk: in a startup run it was slower than the original code. `VirtualQuery` scans page-table entries up to the next attribute change, which costs milliseconds on large touched regions (synthetic: about 5 ms per GiB with one touched page per 64 KiB). The region-information call does not scan; it costs about 0.0004 ms. Its committed-bytes count matched a full `VirtualQuery` count for private allocations after decommit and recommit, double decommit, commit of committed pages, guard and no-access pages, `MEM_RESET`, reserve-then-commit and placeholder pieces. `startup_placed_buffer_range` (replaces `startup_placed_allocation_cache`) compares every alias or refusal, base and type with the full walk on the same memory. Each case places a buffer first, then changes the memory, then places again: - a middle page decommitted under a buffer, before a buffer, and five pages before a buffer, then committed again; - the reviewed repro: 1 MiB committed, a buffer at +0x80000 for 0x10000 bytes, then +0x10000 decommitted for 0x10000 bytes; - the same-base replacement; - a mapped view; - a reservation committed in two steps; - a placeholder piece; - write-watch, top-down, executable, heap-block, AWE and (with the lock-pages privilege) large-page allocations; - a 64 MiB striped block; - a 512 MiB touched block, which must be proven with no `VirtualQuery` call. The controls (`WILL_FAIL`) must fail only for their stated reason. `--mutate region-only` trusts the allocation size without the committed-bytes check and fails 10 placements, all in the partly committed cases. `--mutate walk-only` never uses the region information and fails only the call count. @tedin7: your repro is a case in `startup_placed_buffer_range` with exactly those numbers. The endpoint-only cache at 229f7b13 accepted the second placement, while the current code refuses it, the same answer as the full walk. It is refused because a decommitted page makes the allocation's committed bytes smaller than its size, so the placement falls back to the walk from the base, which stops at the gap. ``` ctest --preset release --no-tests=error -R '^(startup_placed_buffer_range.*|startup_placed_vertex_.*|xmem_page_runs_device_.*|startup_placement_.*|cpu_placed_draw_.*)$' -V ``` Windows 10 19045, MSVC 19.44, RTX 3060 (WARP for `_warp`), `dev` and `release`, head 20f8e1d5 (merges current main): 12 of 12 passed, 0 failed, 0 skipped. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!1759
No description provided.