runtime: report peak commit and physical-page sections in the startup heartbeat #1270

Manually merged
github merged 2 commits from gh-pr/1270/head into gh-pr/1270/base 2026-11-26 22:53:57 +00:00
Owner

@⁠triggered02 on GitHub · 2026-11-24 06:22 UTC · original
triggered02:runtime/startup-commit-heartbeat → main · +318 −5 · 7 files · 2 commits · merged 2026-11-24 06:40 UTC

What changed

Issue #1199 item 1: make startup runs comparable by memory spent. The DirectStorage stand-in's 10 s heartbeat now reports this process's peak and current commit charge and the number of live 64 KiB physical-page sections, and reports again when either memory value changes even while the request counters are static (so a stalled load still shows what it holds).

  • src/xmem_mapped_pages.cpp / src/xmem_shim.def: experimental x2w_xmem_page_stats export returning the number of live sections (memory.backings.size()). A section exists from a page's first use (a mapping or a page-token write) until its grant is released.
  • src/startup_stubs/xcrdapi.cpp: memory_sample() reads PeakPagefileUsage/PagefileUsage via GetProcessMemoryInfo and the section count through GetProcAddress on the already-loaded xmem.dll, and the heartbeat line gains
    ; commit peak=<MiB> current=<MiB>, live physical-page sections=<n>.
    The line keeps its previous fields; a missing reading prints unknown.
  • CMakeLists.txt: link psapi for the stand-in; register the two new CTest cases.
  • docs/startup-runtime.md: short "Startup memory accounting" section.
  • tests/xmem_page_stats_check.py, tests/startup_heartbeat_check.py: source-built checks.

No allocator, SEC_RESERVE or mapping behaviour changed; this is read-only accounting and does not overlap denn0x's experiments or PR #1264. src/startup_stubs/d3d12_xs_device.cpp is untouched (the DirectStorage heartbeat is the one extended).

Verification (release preset)

Before the change, both checks fail for the right reason:

$ python -B tests/xmem_page_stats_check.py out/build/release/xmem.dll
AttributeError: function 'x2w_xmem_page_stats' not found

$ python -B tests/startup_heartbeat_check.py out/build/release/xmem.dll out/build/release/XCRDAPI.dll
x2w-dstorage heartbeat 10 s: requests done=0 inflated=0 failed=0 bcpack-blank=0; page tokens 0 at enqueue=0, still 0 at run=0
AssertionError: no heartbeat line with commit peak and physical-page sections

After the change:

test 37: xmem_page_stats
37: live physical-page sections: grant=0 mapped=2 unmapped=2 released=0; page-token write created and released 1
37: Passed  0.11 sec

test 38: startup_heartbeat_commit
38: x2w-dstorage heartbeat 10 s: requests done=0 inflated=0 failed=0 bcpack-blank=0; page tokens 0 at enqueue=0, still 0 at run=0; commit peak=9 MiB current=9 MiB, live physical-page sections=2
38: heartbeat at 10 s: commit peak=9 MiB current=9 MiB, live physical-page sections=2
38: Passed  10.18 sec

The heartbeat check maps two synthetic pages, starts the real heartbeat through DStorageGetFactory, waits for the first 10 s report, asserts the reported section count is 2, and checks the reported peak against GetProcessMemoryInfo in the same process.

Neighbouring tests, all passing:

ctest --preset release --no-tests=error -R '^(xmem_shim_mapped_pages|era_physical_(controls|lifetime)|xmem_commit_protection)$'
100% tests passed, 0 tests failed out of 4

ctest --preset release --no-tests=error -R '^(xmem_shim_(exports|physical_pages|allocation|default_allocation|tools_memory|transfer_memory|query)|startup_stubs)$'
100% tests passed, 0 tests failed out of 7

Not verified

No run of the title image was made (none is needed for this slice): the actual peak-commit reduction / stall comparison on a real startup run, and the section count it reports, are for a follow-up run by someone with the package. The heartbeat also starts only when the title calls DStorageGetFactory, so its extra fields appear from the DirectStorage phase onward.

**@⁠triggered02** on GitHub · 2026-11-24 06:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270) `triggered02:runtime/startup-commit-heartbeat` → `main` · +318 −5 · 7 files · 2 commits · merged 2026-11-24 06:40 UTC ## What changed Issue #1199 item 1: make startup runs comparable by memory spent. The DirectStorage stand-in's 10 s heartbeat now reports this process's peak and current commit charge and the number of live 64 KiB physical-page sections, and reports again when either memory value changes even while the request counters are static (so a stalled load still shows what it holds). - `src/xmem_mapped_pages.cpp` / `src/xmem_shim.def`: experimental `x2w_xmem_page_stats` export returning the number of live sections (`memory.backings.size()`). A section exists from a page's first use (a mapping or a page-token write) until its grant is released. - `src/startup_stubs/xcrdapi.cpp`: `memory_sample()` reads `PeakPagefileUsage`/`PagefileUsage` via `GetProcessMemoryInfo` and the section count through `GetProcAddress` on the already-loaded `xmem.dll`, and the heartbeat line gains `; commit peak=<MiB> current=<MiB>, live physical-page sections=<n>`. The line keeps its previous fields; a missing reading prints `unknown`. - `CMakeLists.txt`: link `psapi` for the stand-in; register the two new CTest cases. - `docs/startup-runtime.md`: short "Startup memory accounting" section. - `tests/xmem_page_stats_check.py`, `tests/startup_heartbeat_check.py`: source-built checks. No allocator, `SEC_RESERVE` or mapping behaviour changed; this is read-only accounting and does not overlap denn0x's experiments or PR #1264. `src/startup_stubs/d3d12_xs_device.cpp` is untouched (the DirectStorage heartbeat is the one extended). ## Verification (release preset) Before the change, both checks fail for the right reason: ``` $ python -B tests/xmem_page_stats_check.py out/build/release/xmem.dll AttributeError: function 'x2w_xmem_page_stats' not found $ python -B tests/startup_heartbeat_check.py out/build/release/xmem.dll out/build/release/XCRDAPI.dll x2w-dstorage heartbeat 10 s: requests done=0 inflated=0 failed=0 bcpack-blank=0; page tokens 0 at enqueue=0, still 0 at run=0 AssertionError: no heartbeat line with commit peak and physical-page sections ``` After the change: ``` test 37: xmem_page_stats 37: live physical-page sections: grant=0 mapped=2 unmapped=2 released=0; page-token write created and released 1 37: Passed 0.11 sec test 38: startup_heartbeat_commit 38: x2w-dstorage heartbeat 10 s: requests done=0 inflated=0 failed=0 bcpack-blank=0; page tokens 0 at enqueue=0, still 0 at run=0; commit peak=9 MiB current=9 MiB, live physical-page sections=2 38: heartbeat at 10 s: commit peak=9 MiB current=9 MiB, live physical-page sections=2 38: Passed 10.18 sec ``` The heartbeat check maps two synthetic pages, starts the real heartbeat through `DStorageGetFactory`, waits for the first 10 s report, asserts the reported section count is 2, and checks the reported peak against `GetProcessMemoryInfo` in the same process. Neighbouring tests, all passing: ``` ctest --preset release --no-tests=error -R '^(xmem_shim_mapped_pages|era_physical_(controls|lifetime)|xmem_commit_protection)$' 100% tests passed, 0 tests failed out of 4 ctest --preset release --no-tests=error -R '^(xmem_shim_(exports|physical_pages|allocation|default_allocation|tools_memory|transfer_memory|query)|startup_stubs)$' 100% tests passed, 0 tests failed out of 7 ``` ## Not verified No run of the title image was made (none is needed for this slice): the actual peak-commit reduction / stall comparison on a real startup run, and the section count it reports, are for a follow-up run by someone with the package. The heartbeat also starts only when the title calls `DStorageGetFactory`, so its extra fields appear from the DirectStorage phase onward.
The DirectStorage stand-in's 10 s heartbeat now prints this process's peak and
current commit charge (GetProcessMemoryInfo) and the number of live 64 KiB
physical-page sections, and it reports again when either memory value changes
even while the request counters are static. That makes runs that stop at
different points comparable by what they spent (#1199).

xmem.dll publishes the section count through the experimental
x2w_xmem_page_stats export; a section exists from a page's first use (a mapping
or a page-token write) until its grant is released.

Verification (release preset):
- tests/xmem_page_stats_check.py fails on the previous xmem.dll with
  "function 'x2w_xmem_page_stats' not found" and passes now: grant=0 mapped=2
  unmapped=2 released=0; page-token write created and released 1.
- tests/startup_heartbeat_check.py fails on the previous XCRDAPI.dll (the
  heartbeat line carried no commit or section fields) and passes now,
  reporting "commit peak=9 MiB current=9 MiB, live physical-page sections=2".
- Neighbouring tests pass: xmem_shim_exports/allocation/default_allocation/
  physical_pages/tools_memory/transfer_memory/query, xmem_commit_protection,
  xmem_shim_mapped_pages, era_physical_controls/lifetime, startup_stubs.

Refs #1199
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:53:55 +00:00
github manually merged commit 22709a63c4 into gh-pr/1270/base 2026-11-26 22:53:57 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 06:22 UTC · original · edited 2026-11-24 06:25 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-24T06:25:33.421827Z 46812c8 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 06:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#issuecomment-7123869089) · edited 2026-11-24 06:25 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"46812c8ed3161aad20ccb92b530d0b77145b10f0","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-24T06:25:33.421827Z">2026-11-24T06:25:33.421827Z</relative-time> | `46812c8` | 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>
Author
Owner

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

P2 Badge Track current commit when deciding to emit the heartbeat

If current commit changes by at least 1 MiB while request counts and the physical-section count stay fixed, but current commit remains below an already reached peak, this condition emits no new line. The reported current= value therefore stays stale; include the current MiB value in the change check.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 06:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#discussion_r4676283684) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Track current commit when deciding to emit the heartbeat** If current commit changes by at least 1 MiB while request counts and the physical-section count stay fixed, but current commit remains below an already reached peak, this condition emits no new line. The reported `current=` value therefore stays stale; include the current MiB value in the change check. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠triggered02 on GitHub · 2026-11-24 06:31 UTC · original

Rebased onto current main (7a691883, was 12 commits behind) — this also retriggers CI, because the last Linux job died inside actions/checkout with git ... exit code 128 before any step of the job ran (GitHub network error, not this change). I cannot rerun that job from the fork side (Must have admin rights to Repository), so a fresh push was the way to get a clean run; sorry for the extra notification.

Re-verified after the rebase on the release preset:

live physical-page sections: grant=0 mapped=2 unmapped=2 released=0; page-token write created and released 1
x2w-dstorage heartbeat 10 s: ... commit peak=9 MiB current=9 MiB, live physical-page sections=2
1/2 Test #37: xmem_page_stats .......... Passed 0.14 sec
2/2 Test #38: startup_heartbeat_commit . Passed 10.18 sec

I also checked the two new cases fail on a pre-change build for the right reasons (missing x2w_xmem_page_stats export; heartbeat line without the new fields), so they are not passing vacuously.

One honest limit, unchanged: the numbers above come from the source-built checks, not a title run, so this adds the observability the issue asks for (item 1) without yet providing the before/after peak-commit comparison — that needs a run and is what item 2 will be measured with.

**@⁠triggered02** on GitHub · 2026-11-24 06:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#issuecomment-7124029236) Rebased onto current `main` (`7a691883`, was 12 commits behind) — this also retriggers CI, because the last Linux job died inside `actions/checkout` with `git ... exit code 128` before any step of the job ran (GitHub network error, not this change). I cannot rerun that job from the fork side (`Must have admin rights to Repository`), so a fresh push was the way to get a clean run; sorry for the extra notification. Re-verified after the rebase on the `release` preset: ``` live physical-page sections: grant=0 mapped=2 unmapped=2 released=0; page-token write created and released 1 x2w-dstorage heartbeat 10 s: ... commit peak=9 MiB current=9 MiB, live physical-page sections=2 1/2 Test #37: xmem_page_stats .......... Passed 0.14 sec 2/2 Test #38: startup_heartbeat_commit . Passed 10.18 sec ``` I also checked the two new cases fail on a pre-change build for the right reasons (missing `x2w_xmem_page_stats` export; heartbeat line without the new fields), so they are not passing vacuously. One honest limit, unchanged: the numbers above come from the source-built checks, not a title run, so this adds the observability the issue asks for (item 1) without yet providing the before/after peak-commit comparison — that needs a run and is what item 2 will be measured with.
Author
Owner

@⁠triggered02 on GitHub · 2026-11-24 06:34 UTC · original

First real-run numbers from this branch (the item 1 value this PR adds), run of the title to a 120 s timeout:

heartbeat 10 s: commit peak=5482 MiB current=5290 MiB, live physical-page sections=102736
heartbeat 60 s: commit peak=7739 MiB current=7739 MiB, live physical-page sections=102736

So it reports 102,736 live physical-page sections (~6.4 GiB at 64 KiB each) against ~7.7 GiB of peak commit, with the section count flat from 10 s on while commit keeps rising. That is exactly the comparison item 2 needs, and it is the first time these numbers are available at all — the fields appear once DStorageGetFactory has run, which is the case in a title run.

**@⁠triggered02** on GitHub · 2026-11-24 06:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#issuecomment-7124075606) First real-run numbers from this branch (the item 1 value this PR adds), run of the title to a 120 s timeout: ``` heartbeat 10 s: commit peak=5482 MiB current=5290 MiB, live physical-page sections=102736 heartbeat 60 s: commit peak=7739 MiB current=7739 MiB, live physical-page sections=102736 ``` So it reports 102,736 live physical-page sections (~6.4 GiB at 64 KiB each) against ~7.7 GiB of peak commit, with the section count flat from 10 s on while commit keeps rising. That is exactly the comparison item 2 needs, and it is the first time these numbers are available at all — the fields appear once `DStorageGetFactory` has run, which is the case in a title run.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 06:37 UTC · original

I pushed a focused follow-up at 22709a63. The heartbeat now samples the currently loaded page provider while holding a module reference, and a change in current commit can trigger a report on its own. The source-built check observed unknown sections at 10 s, two after loading the provider at 20 s, then current commit falling from 25 to 9 MiB at the same 25 MiB peak. That check, the page-section lifetime test and the mapped-pages regression all passed in Release. The allocator and worker failure work in #1199 remain separate.

**@⁠R0Y00** on GitHub · 2026-11-24 06:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#issuecomment-7124130608) I pushed a focused follow-up at `22709a63`. The heartbeat now samples the currently loaded page provider while holding a module reference, and a change in current commit can trigger a report on its own. The source-built check observed unknown sections at 10 s, two after loading the provider at 20 s, then current commit falling from 25 to 9 MiB at the same 25 MiB peak. That check, the page-section lifetime test and the mapped-pages regression all passed in Release. The allocator and worker failure work in #1199 remain separate.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46812c8ed3

ℹ️ 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 06:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#pullrequestreview-6034641930) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `46812c8ed3` <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

@⁠tedin7 on GitHub · 2026-11-24 06:32 UTC · original · reviewed

Dual-platform review at commit 46812c8ed3161aad20ccb92b530d0b77145b10f0:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: passed
    • python -B tests/docs_links_check.py: passed (16 Markdown files, 284 links)
    • python -B tests/bidi_controls_check.py: passed (1067 files)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target xmem_shim startup_stub_xcrdapi startup_stub_consumer -- -j 6 + ctest --preset dev -R '^(xmem_page_stats|startup_heartbeat_commit|xmem_shim_mapped_pages|xmem_shim_physical_pages|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure -> 5/5 passed (10.27s: xmem_shim_mapped_pages, xmem_page_stats, startup_stubs, xmem_shim_physical_pages, startup_heartbeat_commit)
    • Release /O2 (--preset release): cmake --build --preset release --target xmem_shim startup_stub_xcrdapi startup_stub_consumer -- -j 6 + ctest --preset release -R '^(xmem_page_stats|startup_heartbeat_commit|xmem_shim_mapped_pages|xmem_shim_physical_pages|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure -> 5/5 passed (10.21s)

Code Notes

  • x2w_xmem_page_stats in src/xmem_mapped_pages.cpp safely guards against a null output pointer and reads memory.backings.size() under memory.mutex.
  • memory_sample() in src/startup_stubs/xcrdapi.cpp caches GetProcAddress(GetModuleHandleW(L"xmem.dll"), "x2w_xmem_page_stats") in a function-local static const — this works whenever xmem.dll is loaded before the first heartbeat tick, and gracefully falls back to unknown otherwise.
**@⁠tedin7** on GitHub · 2026-11-24 06:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1270#pullrequestreview-6034703127) · **reviewed** Dual-platform review at commit `46812c8ed3161aad20ccb92b530d0b77145b10f0`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: passed - `python -B tests/docs_links_check.py`: passed (16 Markdown files, 284 links) - `python -B tests/bidi_controls_check.py`: passed (1067 files) - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `cmake --build --preset dev --target xmem_shim startup_stub_xcrdapi startup_stub_consumer -- -j 6` + `ctest --preset dev -R '^(xmem_page_stats|startup_heartbeat_commit|xmem_shim_mapped_pages|xmem_shim_physical_pages|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure` -> **5/5 passed** (`10.27s`: `xmem_shim_mapped_pages`, `xmem_page_stats`, `startup_stubs`, `xmem_shim_physical_pages`, `startup_heartbeat_commit`) - **Release `/O2` (`--preset release`)**: `cmake --build --preset release --target xmem_shim startup_stub_xcrdapi startup_stub_consumer -- -j 6` + `ctest --preset release -R '^(xmem_page_stats|startup_heartbeat_commit|xmem_shim_mapped_pages|xmem_shim_physical_pages|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure` -> **5/5 passed** (`10.21s`) ### Code Notes - `x2w_xmem_page_stats` in `src/xmem_mapped_pages.cpp` safely guards against a null output pointer and reads `memory.backings.size()` under `memory.mutex`. - `memory_sample()` in `src/startup_stubs/xcrdapi.cpp` caches `GetProcAddress(GetModuleHandleW(L"xmem.dll"), "x2w_xmem_page_stats")` in a function-local `static const` — this works whenever `xmem.dll` is loaded before the first heartbeat tick, and gracefully falls back to `unknown` otherwise.
This discussion has been locked. Commenting is limited to contributors.
No description provided.