memory: reserve mapped-page slabs and commit 64 KiB slots on first use #1958

Manually merged
github merged 3 commits from gh-pr/1958/head into gh-pr/1958/base 2026-11-26 23:45:28 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 22:07 UTC · original
tedin7:x2w-frontier-1199-commit → main · +174 −26 · 5 files · 3 commits · merged 2026-11-24 23:11 UTC

Part of #1199

What this unblocks: startup runs on machines with limited free commit no longer pay 256 MiB of commit per physical-page slab up front, so loading gets further before ERROR_COMMITMENT_LIMIT.

Slabs are now created with SEC_RESERVE. A 64 KiB slot is committed when its page is first mapped or written (commit_slot in src/xmem_mapped_pages.cpp). Pages that are granted but never used cost nothing. A slot that cannot be committed fails the call with the system error and leaves the slab bookkeeping unchanged. Freed slots stay committed, so reuse cannot fail for lack of commit.

Not covered: pages that are mapped but never touched still count, and the DirectStorage worker stack overflow on bad_alloc (item 3 of the issue) is a separate change.

Verification:

  • git diff --stat origin/main...HEAD: 4 files (CMakeLists.txt, src/xmem_mapped_pages.cpp, src/xmem_slab_slots.h, tests/xmem_mapped_pages_commit_check.py).
  • Linux: python -B -c "import ast; ast.parse(...)" on the new check passes; x86_64-w64-mingw32-g++ -fsyntax-only src/xmem_mapped_pages.cpp reports no error in the changed lines (the MSVC-only code elsewhere in the file does not build with MinGW).
  • Win2025: NOT RUN yet (the node needs a pushed PR). To run after push: x2w_pipe.py win2025 <PR> --targets xmem_shim --regex '^xmem_(mapped_pages_commit|page_stats|slab_slots|shim_mapped_pages|shim_page_runs)$'.
  • New check xmem_mapped_pages_commit: maps 16 pages and asserts system commit grows by under 32 MiB (before the change it grows by about 256 MiB, one whole slab), then checks the pages are zero-filled and writable. Numbers before/after still to be filled in from the Win2025 run.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 22:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958) `tedin7:x2w-frontier-1199-commit` → `main` · +174 −26 · 5 files · 3 commits · merged 2026-11-24 23:11 UTC Part of #1199 What this unblocks: startup runs on machines with limited free commit no longer pay 256 MiB of commit per physical-page slab up front, so loading gets further before `ERROR_COMMITMENT_LIMIT`. Slabs are now created with `SEC_RESERVE`. A 64 KiB slot is committed when its page is first mapped or written (`commit_slot` in `src/xmem_mapped_pages.cpp`). Pages that are granted but never used cost nothing. A slot that cannot be committed fails the call with the system error and leaves the slab bookkeeping unchanged. Freed slots stay committed, so reuse cannot fail for lack of commit. Not covered: pages that are mapped but never touched still count, and the DirectStorage worker stack overflow on `bad_alloc` (item 3 of the issue) is a separate change. Verification: - `git diff --stat origin/main...HEAD`: 4 files (CMakeLists.txt, src/xmem_mapped_pages.cpp, src/xmem_slab_slots.h, tests/xmem_mapped_pages_commit_check.py). - Linux: `python -B -c "import ast; ast.parse(...)"` on the new check passes; `x86_64-w64-mingw32-g++ -fsyntax-only src/xmem_mapped_pages.cpp` reports no error in the changed lines (the MSVC-only code elsewhere in the file does not build with MinGW). - Win2025: NOT RUN yet (the node needs a pushed PR). To run after push: `x2w_pipe.py win2025 <PR> --targets xmem_shim --regex '^xmem_(mapped_pages_commit|page_stats|slab_slots|shim_mapped_pages|shim_page_runs)$'`. - New check `xmem_mapped_pages_commit`: maps 16 pages and asserts system commit grows by under 32 MiB (before the change it grows by about 256 MiB, one whole slab), then checks the pages are zero-filled and writable. Numbers before/after still to be filled in from the Win2025 run. AI-assisted; commands listed were executed locally.
Slabs were created committed, so every 256 MiB slab counted against system
commit as soon as its first page was used. They are now reserved, and a 64 KiB
slot is committed when its page is first mapped or written. A slot that cannot
be committed fails the call with the system error and leaves the slab state
unchanged.

Part of #1199
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:45:27 +00:00
github manually merged commit 21e8f5c07f into gh-pr/1958/base 2026-11-26 23:45:28 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:39 UTC · original · edited 2026-11-24 22:45 UTC

Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T22:45:31.948383Z 0478a38 Draft marked ready
ℹ️ 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 22:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#issuecomment-7146490018) · edited 2026-11-24 22:45 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0478a3864036fc4c397cc68bf10fd88dd1676d62","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T22:45:31.948383Z">2026-11-24T22:45:31.948383Z</relative-time> | `0478a38` | Draft marked ready | <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>
@ -0,0 +62,4 @@
assert mapped == base, C.get_last_error()
grown = commit_bytes() - before
print(f"commit grew by {grown >> 20} MiB for {MAPPED_PAGES} mapped pages (a slab is {SLAB_BYTES >> 20} MiB)")
assert grown < LIMIT_BYTES, f"mapping {MAPPED_PAGES} pages committed {grown >> 20} MiB: the slab is charged whole"
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:45 UTC · original

P1 Badge Add a negative control or failure case for the commit fixture

CMakeLists.txt registers this new fixture only against the production shim, and a repository-wide search for the fixture name, commit_slot, and SEC_COMMIT found no negative-control or injected-failure run. Consequently, the fixture is never demonstrated to reject an eagerly committed slab, and the new commitment-failure path is not exercised. AGENTS.md requires “a negative control or failure case for a new fixture”; add an eager-commit control that must fail this assertion, or force a commitment failure and verify the returned error and accounting.

AGENTS.md reference: AGENTS.md:L192-L192

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 22:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#discussion_r4687561936) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Add a negative control or failure case for the commit fixture** `CMakeLists.txt` registers this new fixture only against the production shim, and a repository-wide search for the fixture name, `commit_slot`, and `SEC_COMMIT` found no negative-control or injected-failure run. Consequently, the fixture is never demonstrated to reject an eagerly committed slab, and the new commitment-failure path is not exercised. `AGENTS.md` requires “a negative control or failure case for a new fixture”; add an eager-commit control that must fail this assertion, or force a commitment failure and verify the returned error and accounting. AGENTS.md reference: [AGENTS.md:L192-L192](https://github.com/R0Y00/Xbox2Windows/blob/0478a3864036fc4c397cc68bf10fd88dd1676d62/AGENTS.md#L192-L192) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:45 UTC · original

P2 Badge Preserve the retry error after a successful placeholder split

When mapping a subrange of a larger placeholder, the first mapping fails because the placeholder has the wrong size. If splitting succeeds but the subsequent map() fails—for example, because Windows cannot allocate resources for the view—this unconditional reset discards the retry’s error and reports the earlier size-mismatch error. map_pages propagates that stale error through both public mapping exports, obscuring the actual resource failure. Restore the saved error only when VirtualFree refuses the split; otherwise preserve the failed retry’s GetLastError().

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 22:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#discussion_r4687561946) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the retry error after a successful placeholder split** When mapping a subrange of a larger placeholder, the first mapping fails because the placeholder has the wrong size. If splitting succeeds but the subsequent `map()` fails—for example, because Windows cannot allocate resources for the view—this unconditional reset discards the retry’s error and reports the earlier size-mismatch error. `map_pages` propagates that stale error through both public mapping exports, obscuring the actual resource failure. Restore the saved error only when `VirtualFree` refuses the split; otherwise preserve the failed retry’s `GetLastError()`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 23:07 UTC · original

Restored the mapper-owned split check and retained the actual retry error. The new source-built failure control forces ERROR_COMMITMENT_LIMIT, verifies the reserved region and slab counts remain unchanged, and retries the same grant successfully. The external placeholder shape also stays intact. Windows Release passed all six focused checks. The local commit comparison was 256 MiB on the eager-commit baseline versus 1 MiB for the same 16 mapped pages on this branch. This is a system-wide counter sample, with a separate deterministic failure control.

**@⁠R0Y00** on GitHub · 2026-11-24 23:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#issuecomment-7147047767) Restored the mapper-owned split check and retained the actual retry error. The new source-built failure control forces ERROR_COMMITMENT_LIMIT, verifies the reserved region and slab counts remain unchanged, and retries the same grant successfully. The external placeholder shape also stays intact. Windows Release passed all six focused checks. The local commit comparison was 256 MiB on the eager-commit baseline versus 1 MiB for the same 16 mapped pages on this branch. This is a system-wide counter sample, with a separate deterministic failure control.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 22:19 UTC · original · requested changes

The slot and mapped-page fixture checks pass locally. Please keep the lazy-commit patch within the existing placeholder ownership contract. In map_split, the new unconditional MEM_PRESERVE_PLACEHOLDER can split a caller-owned reservation. If that split succeeds and the retry fails, the caller receives the first map error and is left with a split reservation. Keep the registered-reservation check and preserve the actual retry error when a retry runs. Please add a source-built failure check that observes the placeholder shape with VirtualQuery. The commit test can use a reservation made through XMem or an exactly shaped caller placeholder. Please also update the upfront-commit paragraph in docs/startup-runtime.md, fix the final three PERFORMANCE_INFORMATION fields to DWORD, and make the commit probe catch the eager-commit version without depending solely on a single system-wide delta moving in one direction. Windows placeholder semantics

**@⁠R0Y00** on GitHub · 2026-11-24 22:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#pullrequestreview-6048303497) · **requested changes** The slot and mapped-page fixture checks pass locally. Please keep the lazy-commit patch within the existing placeholder ownership contract. In `map_split`, the new unconditional `MEM_PRESERVE_PLACEHOLDER` can split a caller-owned reservation. If that split succeeds and the retry fails, the caller receives the first map error and is left with a split reservation. Keep the registered-reservation check and preserve the actual retry error when a retry runs. Please add a source-built failure check that observes the placeholder shape with `VirtualQuery`. The commit test can use a reservation made through XMem or an exactly shaped caller placeholder. Please also update the upfront-commit paragraph in `docs/startup-runtime.md`, fix the final three `PERFORMANCE_INFORMATION` fields to DWORD, and make the commit probe catch the eager-commit version without depending solely on a single system-wide delta moving in one direction. [Windows placeholder semantics](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualfree)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 22:45 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0478a38640

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 22:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#pullrequestreview-6048581156) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `0478a38640` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 23:10 UTC · original · approved these changes

Verified the scoped ownership and retry fixes and the injected commit failure on this exact head. Windows Release passed the six focused tests. The external reservation retains its shape, and a failed fresh commit preserves the counts and can be retried.

**@⁠R0Y00** on GitHub · 2026-11-24 23:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1958#pullrequestreview-6048877082) · **approved these changes** Verified the scoped ownership and retry fixes and the injected commit failure on this exact head. Windows Release passed the six focused tests. The external reservation retains its shape, and a failed fresh commit preserves the counts and can be retried.
This discussion has been locked. Commenting is limited to contributors.
No description provided.