runtime: keep the physical-page slab bookkeeping in a portable header and report slab counts #1756

Manually merged
github merged 2 commits from gh-pr/1756/head into gh-pr/1756/base 2026-11-26 23:31:27 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 18:09 UTC · original
tedin7:x2w-frontier-1199a-slabs → main · +386 −47 · 7 files · 2 commits · merged 2026-11-24 21:37 UTC

Splits the slab bookkeeping of the physical pages out of xmem_mapped_pages.cpp into a header that needs no Windows, and reports it. Refs #1199 (item 2 stays open).

Changes

  • src/xmem_slab_slots.h (standard C++17 only): x2w_xmem::SlabSlots<Handle> keeps the slabs, how many slots of the newest slab were handed out, and an ordered set of released slots. Released slots are reused lowest first. A new slab of 4096 slots is opened through a callback; if the callback fails nothing changes, and if recording the slab throws the new slab is discarded and the exception continues. Counters: slabs, slots in use, slots free.
  • src/xmem_mapped_pages.cpp uses it. The Windows calls (CreateFileMappingW, MapViewOfFile) are unchanged and stay in this file. One difference: released slots are ordered by (slab creation order, offset) instead of (handle value, offset); the handle order was arbitrary, this one is deterministic.
  • x2w_xmem_page_stats is unchanged. New export x2w_xmem_slab_stats(slabs, in_use, free), listed in xmem_shim.def as @⁠16.
  • tests/xmem_slab_slots_check.cpp (registered as xmem_slab_slots): a fake slab factory checks the 4096-slot boundary, lowest-first adjacent reuse, reuse preferring the older slab, freeing everything keeping the slabs open, a failing factory leaving state unchanged (first and second slab), unwinding a fresh slot (including slot 0 of a new slab), refused invalid releases, and exact counters throughout. tests/xmem_page_stats_check.py also checks the slab counters through grant, map, unmap, release and a page-token write.
  • docs/startup-runtime.md explains the units and updates the build/test snippet (xmem_slab_slots_check + xmem_slab_slots). The heartbeat label (sections) is left alone; the doc says what it counts now.

Not claimed

This does not reduce commit. A slab is still charged in full when it is created (default CreateFileMappingW flags, untouched) and closed only at process exit, so freeing pages returns slots, not commit. The new counters are the before/after units for later work.

Verified (Windows Server 2025, MSVC 14.44.35207, Debug & Release /O2)

  • Debug (--preset dev): built all 42 direct targets (xmem_shim, xmem_shim_test_controls, xmem_slab_slots_check, startup_stub_*, xgameruntime_*, cpu_*); ctest --preset dev 22/22 passed (30.31s), including xmem_slab_slots (0.03s), xmem_page_stats (0.08s), xmem_shim_mapped_pages (0.18s), xmem_shim_page_runs (9.92s), startup_heartbeat_commit (30.21s).
  • Release /O2 (--preset release): built all 42 direct targets; ctest --preset release 22/22 passed (30.28s), including xmem_slab_slots (0.02s), xmem_page_stats (0.10s), xmem_shim_mapped_pages (0.22s), xmem_shim_page_runs (9.74s), startup_heartbeat_commit (30.20s). Covers ctest --preset release -R "^(xmem_slab_slots|xmem_page_stats)$" -V.
  • Mutation checks on Windows:
    1. src/xmem_slab_slots.h (slots_in_use() ignoring free_.size()): killed by both xmem_slab_slots and xmem_page_stats ((1, 2, 4094) vs expected (1, 0, 4096)).
    2. src/xmem_mapped_pages.cpp (free_pages() skipping memory.slots.release(...)): killed by xmem_page_stats ((1, 2, 4094) vs expected (1, 0, 4096)).

Verified (Linux)

  • g++ -std=c++17 -O2 -Wall -Wextra -Wpedantic -Wconversion -fsanitize=address,undefined -Isrc tests/xmem_slab_slots_check.cpp: no warnings, passes.
  • git diff --check origin/main...HEAD, tests/docs_links_check.py, tests/bidi_controls_check.py: pass.
  • git merge-tree --write-tree origin/main HEAD: clean, no conflicts with main.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 18:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1756) `tedin7:x2w-frontier-1199a-slabs` → `main` · +386 −47 · 7 files · 2 commits · merged 2026-11-24 21:37 UTC Splits the slab bookkeeping of the physical pages out of `xmem_mapped_pages.cpp` into a header that needs no Windows, and reports it. Refs #1199 (item 2 stays open). ### Changes - `src/xmem_slab_slots.h` (standard C++17 only): `x2w_xmem::SlabSlots<Handle>` keeps the slabs, how many slots of the newest slab were handed out, and an ordered set of released slots. Released slots are reused lowest first. A new slab of 4096 slots is opened through a callback; if the callback fails nothing changes, and if recording the slab throws the new slab is discarded and the exception continues. Counters: slabs, slots in use, slots free. - `src/xmem_mapped_pages.cpp` uses it. The Windows calls (`CreateFileMappingW`, `MapViewOfFile`) are unchanged and stay in this file. One difference: released slots are ordered by (slab creation order, offset) instead of (handle value, offset); the handle order was arbitrary, this one is deterministic. - `x2w_xmem_page_stats` is unchanged. New export `x2w_xmem_slab_stats(slabs, in_use, free)`, listed in `xmem_shim.def` as @⁠16. - `tests/xmem_slab_slots_check.cpp` (registered as `xmem_slab_slots`): a fake slab factory checks the 4096-slot boundary, lowest-first adjacent reuse, reuse preferring the older slab, freeing everything keeping the slabs open, a failing factory leaving state unchanged (first and second slab), unwinding a fresh slot (including slot 0 of a new slab), refused invalid releases, and exact counters throughout. `tests/xmem_page_stats_check.py` also checks the slab counters through grant, map, unmap, release and a page-token write. - `docs/startup-runtime.md` explains the units and updates the build/test snippet (`xmem_slab_slots_check` + `xmem_slab_slots`). The heartbeat label (`sections`) is left alone; the doc says what it counts now. ### Not claimed This does not reduce commit. A slab is still charged in full when it is created (default `CreateFileMappingW` flags, untouched) and closed only at process exit, so freeing pages returns slots, not commit. The new counters are the before/after units for later work. ### Verified (Windows Server 2025, MSVC 14.44.35207, Debug & Release `/O2`) - **Debug (`--preset dev`)**: built all 42 direct targets (`xmem_shim`, `xmem_shim_test_controls`, `xmem_slab_slots_check`, `startup_stub_*`, `xgameruntime_*`, `cpu_*`); `ctest --preset dev` **22/22 passed** (`30.31s`), including `xmem_slab_slots` (`0.03s`), `xmem_page_stats` (`0.08s`), `xmem_shim_mapped_pages` (`0.18s`), `xmem_shim_page_runs` (`9.92s`), `startup_heartbeat_commit` (`30.21s`). - **Release `/O2` (`--preset release`)**: built all 42 direct targets; `ctest --preset release` **22/22 passed** (`30.28s`), including `xmem_slab_slots` (`0.02s`), `xmem_page_stats` (`0.10s`), `xmem_shim_mapped_pages` (`0.22s`), `xmem_shim_page_runs` (`9.74s`), `startup_heartbeat_commit` (`30.20s`). Covers `ctest --preset release -R "^(xmem_slab_slots|xmem_page_stats)$" -V`. - **Mutation checks on Windows**: 1. `src/xmem_slab_slots.h` (`slots_in_use()` ignoring `free_.size()`): killed by both `xmem_slab_slots` and `xmem_page_stats` (`(1, 2, 4094)` vs expected `(1, 0, 4096)`). 2. `src/xmem_mapped_pages.cpp` (`free_pages()` skipping `memory.slots.release(...)`): killed by `xmem_page_stats` (`(1, 2, 4094)` vs expected `(1, 0, 4096)`). ### Verified (Linux) - `g++ -std=c++17 -O2 -Wall -Wextra -Wpedantic -Wconversion -fsanitize=address,undefined -Isrc tests/xmem_slab_slots_check.cpp`: no warnings, passes. - `git diff --check origin/main...HEAD`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: pass. - `git merge-tree --write-tree origin/main HEAD`: clean, no conflicts with `main`. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:31:26 +00:00
github manually merged commit dca7a4accc into gh-pr/1756/base 2026-11-26 23:31:27 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 19:02 UTC · original · edited 2026-11-24 19:05 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-24T19:05:29.628305Z dca7a4a 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 19:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1756#issuecomment-7141513982) · edited 2026-11-24 19:05 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"dca7a4accc9ad6f7a0e9fdfb190e4209bca11f4b","has_any_findings":false,"has_unresolved_findings":false,"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-24T19:05:29.628305Z">2026-11-24T19:05:29.628305Z</relative-time> | `dca7a4a` | 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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.