audio: commit the stand-in APU heap on demand #2759

Merged
triggered02 merged 1 commit from upstream-pr/2767 into main 2026-11-26 06:56:53 +00:00
triggered02 commented 2026-11-26 06:52:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T06:52:52Z.


Reserves the stand-in APU heap up front and commits/decommits 4 KiB pages on demand, eliminating up to ~457 MiB of unused commit charge at ApuCreateHeap time. Refs #1199.

What changed

  • src/startup_stubs/acphal.cpp:
    • ApuCreateHeap now calls VirtualAlloc(nullptr, bytes, MEM_RESERVE, PAGE_READWRITE) so 0 bytes are committed until an allocation takes space in the heap.
    • heap_take computes the 4 KiB page-aligned span [page_begin, page_end) covering [block_start, block_end) and commits it via VirtualAlloc(..., MEM_COMMIT, PAGE_READWRITE) under heap_lock before modifying extents[], extent_count, or high_water. A commit failure leaves the free list untouched and returns nullptr (E_OUTOFMEMORY in ApuAlloc / AcpHalAllocateShapeContexts). Reused blocks below high_water remain zero-filled (memset(0)), including partial boundary pages.
    • heap_give coalesces adjacent free extents into [free_begin, free_end) under heap_lock, computes the strictly interior 4 KiB-aligned span [ceil_page(free_begin), floor_page(free_end)), and calls VirtualFree(..., MEM_DECOMMIT) only when decommit_end > decommit_begin, so shared boundary pages held by live adjacent allocations remain committed and untouched.
  • tests/startup_acphal_apu_free.cpp: preserves all existing unit, concurrency, mapping, shape-context, and trap checks, and adds --commit-check (spawned in a fresh child AcpHal.dll instance with a 64 MiB ApuCreateHeap) verifying: MEM_RESERVE + ~0 PagefileUsage after ApuCreateHeap; page-scoped commit on ApuAlloc; safe shared boundary page across adjacent live blocks; interior MEM_DECOMMIT + PagefileUsage drop on ApuFree without disturbing the live neighbor; zero-fill on reallocation; and clean E_OUTOFMEMORY rollback under a JOB_OBJECT_LIMIT_PROCESS_MEMORY cap.
  • docs/startup-runtime.md: updated the APU heap stand-in section for on-demand commit/decommit and the expanded fixture.

Verified (4a024bc3 on current main)

cmake --build --preset dev --target startup_stub_acphal startup_acphal_apu_free
ctest --preset dev --no-tests=error -R '^startup_acphal' --output-on-failure
  → 1/1 Test #165: startup_acphal_apu_free ..........   Passed    0.32 sec
python -B tests/docs_links_check.py   # 23 Markdown files, 535 links
python -B tests/bidi_controls_check.py # 2005 files, no bidirectional controls
git diff --check                       # clean

Fail-first mutants (temporary, reverted on 45f3da5d):

  • Restore MEM_COMMIT | MEM_RESERVE in ApuCreateHeap: fails startup_acphal_apu_free (FAIL: PagefileUsage stays near 0 growth after 64 MiB ApuCreateHeap, FAIL: entire 64 MiB heap starts in MEM_RESERVE state, plus 6 more checks).
  • Skip MEM_DECOMMIT in heap_give: fails startup_acphal_apu_free (FAIL: interior pages of freed first sub-block return to MEM_RESERVE, FAIL: PagefileUsage drops after interior freed pages are decommitted).
  • Decommit floor_page(free_begin)..ceil_page(free_end) instead of strictly interior pages: fails startup_acphal_apu_free with Exception: SegFault on shared sub-page allocations and FAIL: shared boundary page stays MEM_COMMIT while adjacent second block is live.

NOT established

  • Whether any workload accesses unallocated offsets of the ApuCreateHeap reservation directly without first calling ApuAlloc or AcpHalAllocateShapeContexts (any such access would fault on a reserved page).
  • In --commit-check, the JOB_OBJECT_LIMIT_PROCESS_MEMORY commit-failure sub-check executes when AssignProcessToJobObject succeeds (it ran and passed locally; inside a restricted nested job without breakaway that sub-check is skipped rather than failing).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6621234470 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2767). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-26T06:52:52Z. --- Reserves the stand-in APU heap up front and commits/decommits 4 KiB pages on demand, eliminating up to ~457 MiB of unused commit charge at `ApuCreateHeap` time. Refs #1199. ### What changed - **`src/startup_stubs/acphal.cpp`**: - `ApuCreateHeap` now calls `VirtualAlloc(nullptr, bytes, MEM_RESERVE, PAGE_READWRITE)` so 0 bytes are committed until an allocation takes space in the heap. - `heap_take` computes the 4 KiB page-aligned span `[page_begin, page_end)` covering `[block_start, block_end)` and commits it via `VirtualAlloc(..., MEM_COMMIT, PAGE_READWRITE)` under `heap_lock` before modifying `extents[]`, `extent_count`, or `high_water`. A commit failure leaves the free list untouched and returns `nullptr` (`E_OUTOFMEMORY` in `ApuAlloc` / `AcpHalAllocateShapeContexts`). Reused blocks below `high_water` remain zero-filled (`memset(0)`), including partial boundary pages. - `heap_give` coalesces adjacent free extents into `[free_begin, free_end)` under `heap_lock`, computes the strictly interior 4 KiB-aligned span `[ceil_page(free_begin), floor_page(free_end))`, and calls `VirtualFree(..., MEM_DECOMMIT)` only when `decommit_end > decommit_begin`, so shared boundary pages held by live adjacent allocations remain committed and untouched. - **`tests/startup_acphal_apu_free.cpp`**: preserves all existing unit, concurrency, mapping, shape-context, and trap checks, and adds `--commit-check` (spawned in a fresh child `AcpHal.dll` instance with a 64 MiB `ApuCreateHeap`) verifying: `MEM_RESERVE` + ~0 `PagefileUsage` after `ApuCreateHeap`; page-scoped commit on `ApuAlloc`; safe shared boundary page across adjacent live blocks; interior `MEM_DECOMMIT` + `PagefileUsage` drop on `ApuFree` without disturbing the live neighbor; zero-fill on reallocation; and clean `E_OUTOFMEMORY` rollback under a `JOB_OBJECT_LIMIT_PROCESS_MEMORY` cap. - **`docs/startup-runtime.md`**: updated the `APU heap stand-in` section for on-demand commit/decommit and the expanded fixture. ### Verified (`4a024bc3` on current `main`) ```powershell cmake --build --preset dev --target startup_stub_acphal startup_acphal_apu_free ctest --preset dev --no-tests=error -R '^startup_acphal' --output-on-failure → 1/1 Test #165: startup_acphal_apu_free .......... Passed 0.32 sec python -B tests/docs_links_check.py # 23 Markdown files, 535 links python -B tests/bidi_controls_check.py # 2005 files, no bidirectional controls git diff --check # clean ``` **Fail-first mutants** (temporary, reverted on `45f3da5d`): - Restore `MEM_COMMIT | MEM_RESERVE` in `ApuCreateHeap`: fails `startup_acphal_apu_free` (`FAIL: PagefileUsage stays near 0 growth after 64 MiB ApuCreateHeap`, `FAIL: entire 64 MiB heap starts in MEM_RESERVE state`, plus 6 more checks). - Skip `MEM_DECOMMIT` in `heap_give`: fails `startup_acphal_apu_free` (`FAIL: interior pages of freed first sub-block return to MEM_RESERVE`, `FAIL: PagefileUsage drops after interior freed pages are decommitted`). - Decommit `floor_page(free_begin)..ceil_page(free_end)` instead of strictly interior pages: fails `startup_acphal_apu_free` with `Exception: SegFault` on shared sub-page allocations and `FAIL: shared boundary page stays MEM_COMMIT while adjacent second block is live`. ### NOT established - Whether any workload accesses unallocated offsets of the `ApuCreateHeap` reservation directly without first calling `ApuAlloc` or `AcpHalAllocateShapeContexts` (any such access would fault on a reserved page). - In `--commit-check`, the `JOB_OBJECT_LIMIT_PROCESS_MEMORY` commit-failure sub-check executes when `AssignProcessToJobObject` succeeds (it ran and passed locally; inside a restricted nested job without breakaway that sub-check is skipped rather than failing). AI-assisted.
upstream-sync closed this pull request 2026-11-26 07:00:25 +00:00
tedin7 commented 2026-11-26 07:00:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T06:56:33Z.

Review: COMMENTED


Review of head 4a024bc3 (comment only).

Checked:

  • acphal.cpp: the heap is reserved only; heap_take commits the 4 KiB page span of the new block before touching the extent table, and a failed commit leaves the free list unchanged (clean E_OUTOFMEMORY). heap_give decommits only the strictly interior pages of the coalesced free extent, so boundary pages shared with live neighbors stay committed. Reused blocks below high_water are still zeroed. Re-committing an already committed page does not clear it, so shared boundary pages are safe.
  • tests/startup_acphal_apu_free.cpp: --commit-check in a fresh child covers reserve with ~0 commit, page-scoped commit, shared boundary page, interior decommit with the neighbor intact, zero-fill on reuse, and commit failure. It is wired into the existing startup_acphal_apu_free CTest.
  • This does not claim to advance game startup; it only lowers commit charge at ApuCreateHeap.

Commands run locally:

  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: 23 files, 538 links ok
  • python3 tests/bidi_controls_check.py: ok
  • Win2025 dev: ctest --preset dev -R startup_acphal: 1/1 passed (startup_acphal_apu_free)
  • Win2025 release: ctest --preset release -R startup_acphal: 1/1 passed (startup_acphal_apu_free)

No blocking findings.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069745685 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2767#pullrequestreview-6069745685). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T06:56:33Z. **Review:** COMMENTED --- Review of head 4a024bc3 (comment only). Checked: - `acphal.cpp`: the heap is reserved only; `heap_take` commits the 4 KiB page span of the new block before touching the extent table, and a failed commit leaves the free list unchanged (clean E_OUTOFMEMORY). `heap_give` decommits only the strictly interior pages of the coalesced free extent, so boundary pages shared with live neighbors stay committed. Reused blocks below `high_water` are still zeroed. Re-committing an already committed page does not clear it, so shared boundary pages are safe. - `tests/startup_acphal_apu_free.cpp`: `--commit-check` in a fresh child covers reserve with ~0 commit, page-scoped commit, shared boundary page, interior decommit with the neighbor intact, zero-fill on reuse, and commit failure. It is wired into the existing `startup_acphal_apu_free` CTest. - This does not claim to advance game startup; it only lowers commit charge at `ApuCreateHeap`. Commands run locally: - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: 23 files, 538 links ok - `python3 tests/bidi_controls_check.py`: ok - Win2025 dev: `ctest --preset dev -R startup_acphal`: 1/1 passed (`startup_acphal_apu_free`) - Win2025 release: `ctest --preset release -R startup_acphal`: 1/1 passed (`startup_acphal_apu_free`) No blocking findings. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 07:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T06:53:00Z.


Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T06:52:57.123292Z
We couldn’t complete this review. Comment @codex review to try again.
4a024bc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7184876849 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2767#issuecomment-7184876849). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T06:53:00Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4a024bc35d5712a3f05b32b4a6d2aefa25741538","has_any_findings":true,"has_unresolved_findings":true,"status":"failed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ❌ Failed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ❌ **Failed** <relative-time datetime="2026-11-26T06:52:57.123292Z">2026-11-26T06:52:57.123292Z</relative-time><br/>We couldn’t complete this review. Comment `@codex review` to try again. | `4a024bc` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-26 07:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T06:53:02Z.


You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7184877458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2767#issuecomment-7184877458). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T06:53:02Z. --- You have reached your Codex usage limits for code reviews. You can see your limits in the [Codex usage dashboard](https://chatgpt.com/codex/cloud/settings/usage). To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your [settings](https://chatgpt.com/settings/code-review).
tedin7 commented 2026-11-26 07:00:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T06:56:40Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 4a024bc35d5712a3f05b32b4a6d2aefa25741538:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_acphal_apu_free startup_stub_acphal -- -j 2): 1.32s (configure 1.82s)
    • Test (ctest --preset dev -R 'startup_acphal' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.39s: startup_acphal_apu_free 0.27s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_acphal_apu_free startup_stub_acphal -- -j 2): 1.46s (configure 1.82s)
    • Test (ctest --preset release -R 'startup_acphal' --parallel 6 --no-tests=error --output-on-failure): 1/1 passed (0.24s: startup_acphal_apu_free 0.13s)
  • sccache: 0/4 hits; wall 11.6s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7184936801 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2767#issuecomment-7184936801). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T06:56:40Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `4a024bc35d5712a3f05b32b4a6d2aefa25741538`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_acphal_apu_free startup_stub_acphal -- -j 2`): `1.32s` (configure `1.82s`) - Test (`ctest --preset dev -R 'startup_acphal' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.39s`: `startup_acphal_apu_free` `0.27s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_acphal_apu_free startup_stub_acphal -- -j 2`): `1.46s` (configure `1.82s`) - Test (`ctest --preset release -R 'startup_acphal' --parallel 6 --no-tests=error --output-on-failure`): **1/1 passed** (`0.24s`: `startup_acphal_apu_free` `0.13s`) - `sccache`: 0/4 hits; wall `11.6s` AI-assisted; commands listed were executed locally.
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!2759
No description provided.