startup: system commit, job limit and page-pool counters in the budget line #2833

Manually merged
github merged 3 commits from github-bot/gh-2833 into gh-pr/2833/base 2026-11-27 19:32:24 +00:00 AGit
Owner

@⁠tedin7 on GitHub · 2026-11-26 12:42 UTC · original
tedin7:x2w-commit-counters-main → main · +267 −5 · 8 files · 3 commits · merged 2026-11-27 19:31 UTC

Part of #870

Fixes #2832

Related: #1199 (physical-page sections and commit; not changed here).

What this unblocks: a run that ends on error 1455 or 8 can be attributed from its log to the job memory limit, the system commit or the physical-page pool.

What changed

  • src/startup_stubs/commit_state.h (new, header only): system_commit() (GlobalMemoryStatusEx), job_memory() (QueryInformationJobObject, JobObjectExtendedLimitInformation: JobMemoryLimit, PeakJobMemoryUsed), job_limit_reached() (limited job whose peak is within 256 MiB of its limit; a refused request never reaches the limit itself), and the formatting of the new text.
  • report_budget() (d3d12_xs_device.cpp): the x2w-budget line ends with commit=<used>/<limit> avail=<free> (MiB), sections=<n> slabs=<n> slots=<in use>/<free> (from the existing x2w_xmem_page_stats / x2w_xmem_slab_stats) and job_peak=<MiB> job_limit=<MiB|none>. Each is n/a when unreadable.
  • log_apply_failure() (xmem_mapped_pages.cpp): the first three commit failures (error 1455 or 8) also log x2w-xmem commit exhausted at <call> (error N): job memory limit N GiB reached (run.ps1 -MemoryGiB); ... (or job memory limit not reached), then the job numbers, the system commit, the pool counters and the X2W_XMEM_LAZY_COMMIT=1 (run.ps1 -LazyMemory) hint. The caller already holds the pool mutex.
  • tools/startup/triage_run.py: the budget line is read with or without the new fields (all-or-nothing group).
  • docs/startup-runtime.md: the new fields and the failure line.

What stays the same

No allocation, mapping or release behaviour changes; only text is added.

Tests

  • tests/startup_commit_state_check.cpp (new, CTest startup_commit_state): text of the commit, job and failure lines (known and unknown values; job limit reached, roomy, unlimited, no job), which error codes count, the system commit is consistent (used + avail = limit to a MiB), and a real job with a 4 GiB memory limit read back (skipped only under Wine, which does not keep the limit).
  • tests/startup_triage_run_check.py: budget lines with the commit, pool and job fields (known and n/a) are read; a malformed field or a trailing path is still rejected. The extended case fails against the previous triage_run.py.

Verification

  • python3 -B tests/startup_triage_run_check.py: 0 failed
  • x86_64-w64-mingw32-g++ -std=c++17 -static -Wall -Wextra -Isrc tests/startup_commit_state_check.cpp + wine: PASS
  • Win2025 (Stage-2 on a branch carrying the same three commits): MSVC builds xmem_shim, d3d12_xs_device_obj, d3d12_xs_shim, startup_commit_state_check; startup_commit_state dev 1/1 and release 1/1; one mutant (job-limit branch dropped) caught.
  • Win2025 WARP dev+release on this PR head: pending Stage-2.

Source: Microsoft Learn, Win32 GlobalMemoryStatusEx, QueryInformationJobObject / JOBOBJECT_EXTENDED_LIMIT_INFORMATION, system error codes 8 and 1455; earlier code of this repo (x2w_xmem_page_stats, x2w_xmem_slab_stats, report_budget).

Real-hardware testing: @⁠Makto94 - thanks for the help.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 12:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833) `tedin7:x2w-commit-counters-main` → `main` · +267 −5 · 8 files · 3 commits · merged 2026-11-27 19:31 UTC Part of #870 Fixes #2832 Related: #1199 (physical-page sections and commit; not changed here). What this unblocks: a run that ends on error 1455 or 8 can be attributed from its log to the job memory limit, the system commit or the physical-page pool. ## What changed - `src/startup_stubs/commit_state.h` (new, header only): `system_commit()` (`GlobalMemoryStatusEx`), `job_memory()` (`QueryInformationJobObject`, `JobObjectExtendedLimitInformation`: `JobMemoryLimit`, `PeakJobMemoryUsed`), `job_limit_reached()` (limited job whose peak is within 256 MiB of its limit; a refused request never reaches the limit itself), and the formatting of the new text. - `report_budget()` (`d3d12_xs_device.cpp`): the `x2w-budget` line ends with `commit=<used>/<limit> avail=<free>` (MiB), `sections=<n> slabs=<n> slots=<in use>/<free>` (from the existing `x2w_xmem_page_stats` / `x2w_xmem_slab_stats`) and `job_peak=<MiB> job_limit=<MiB|none>`. Each is `n/a` when unreadable. - `log_apply_failure()` (`xmem_mapped_pages.cpp`): the first three commit failures (error 1455 or 8) also log `x2w-xmem commit exhausted at <call> (error N): job memory limit N GiB reached (run.ps1 -MemoryGiB); ...` (or `job memory limit not reached`), then the job numbers, the system commit, the pool counters and the `X2W_XMEM_LAZY_COMMIT=1` (`run.ps1 -LazyMemory`) hint. The caller already holds the pool mutex. - `tools/startup/triage_run.py`: the budget line is read with or without the new fields (all-or-nothing group). - `docs/startup-runtime.md`: the new fields and the failure line. ## What stays the same No allocation, mapping or release behaviour changes; only text is added. ## Tests - `tests/startup_commit_state_check.cpp` (new, CTest `startup_commit_state`): text of the commit, job and failure lines (known and unknown values; job limit reached, roomy, unlimited, no job), which error codes count, the system commit is consistent (used + avail = limit to a MiB), and a real job with a 4 GiB memory limit read back (skipped only under Wine, which does not keep the limit). - `tests/startup_triage_run_check.py`: budget lines with the commit, pool and job fields (known and `n/a`) are read; a malformed field or a trailing path is still rejected. The extended case fails against the previous `triage_run.py`. ## Verification - `python3 -B tests/startup_triage_run_check.py`: 0 failed - `x86_64-w64-mingw32-g++ -std=c++17 -static -Wall -Wextra -Isrc tests/startup_commit_state_check.cpp` + `wine`: PASS - Win2025 (Stage-2 on a branch carrying the same three commits): MSVC builds `xmem_shim`, `d3d12_xs_device_obj`, `d3d12_xs_shim`, `startup_commit_state_check`; `startup_commit_state` dev 1/1 and release 1/1; one mutant (job-limit branch dropped) caught. - Win2025 WARP dev+release on this PR head: pending Stage-2. Source: Microsoft Learn, Win32 `GlobalMemoryStatusEx`, `QueryInformationJobObject` / `JOBOBJECT_EXTENDED_LIMIT_INFORMATION`, system error codes 8 and 1455; earlier code of this repo (`x2w_xmem_page_stats`, `x2w_xmem_slab_stats`, `report_budget`). Real-hardware testing: @⁠Makto94 - thanks for the help. AI-assisted; commands listed were executed locally.
x2w-budget ends with commit=<used>/<limit> avail=<free> (MiB, system) and sections/slabs/slots of the
physical-page pool; the first three 1455/8 failures of the pool log the same numbers. triage_run.py reads
the line with or without the new fields.

(cherry picked from commit ffaa4643a262e61d4a9c0338cb6e102905166246)
(cherry picked from commit 24d42107a30bc791bb58adff3f1337cfab7c9c6f)
(cherry picked from commit 3c7b2a56f1c67926dc9716cc8c86962ba7e6552d)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:25:47 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 12:46 UTC · original

Independent review of head 83828d2498: PASS.

Verification:

  • Windows Server 2025 (D3D12 WARP), ctest -R '^startup_commit_state$': dev 1/1 and release 1/1. tests/startup_triage_run_check.py passes there too.
  • Control: the slack of job_limit_reached set from 256 MiB to 0 makes startup_commit_state fail on "the job limit is the cause only for a limited job near its limit" and on the exhausted line with the job limit reached (peak 14250 of 14336 MiB), so the test sees the limit rule.
  • Linux: python3 -B tests/startup_triage_run_check.py: 0 failed.
  • Reviewed commit_state.h: text only, no allocation, mapping or release change.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 12:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192448626) Independent review of head 83828d2498f79bb73021b0add6c4016794d94a09: PASS. Verification: - Windows Server 2025 (D3D12 WARP), `ctest -R '^startup_commit_state$'`: dev 1/1 and release 1/1. `tests/startup_triage_run_check.py` passes there too. - Control: the slack of `job_limit_reached` set from 256 MiB to 0 makes `startup_commit_state` fail on "the job limit is the cause only for a limited job near its limit" and on the exhausted line with the job limit reached (peak 14250 of 14336 MiB), so the test sees the limit rule. - Linux: `python3 -B tests/startup_triage_run_check.py`: 0 failed. - Reviewed `commit_state.h`: text only, no allocation, mapping or release change. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 12:46 UTC · original

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-26T12:46:51.576783Z
We couldn’t complete this review. Comment @codex review to try again.
83828d2 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-26 12:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192451284) <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"83828d2498f79bb73021b0add6c4016794d94a09","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-26T12:46:51.576783Z">2026-11-26T12:46:51.576783Z</relative-time><br/>We couldn’t complete this review. Comment `@codex review` to try again. | `83828d2` | 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 12:46 UTC · original

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, add credits to your account and enable them for code reviews in your settings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 12:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192451915) 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, add credits to your account and enable them for code reviews in your [settings](https://chatgpt.com/settings/code-review).
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 16:07 UTC · original

Hardware and WARP result for head 83828d2498f79bb73021b0add6c4016794d94a09: all pass. Part of #870.

Environment: Windows 11 25H2 (26200), MSVC 19.42, dev preset, NVIDIA GeForce RTX 4070 Ti, driver 621.35 (32.0.16.2135). Tests run serially, one ctest process.

Command

ctest --preset dev --no-tests=error -R "startup_commit_state|xmem_mapped_pages|xmem_shim_mapped_pages|startup_resource_budget|startup_resource_retire|startup_triage|runtime_startup_triage"

Result (measured): 40/40 passed, exit code 0.

  • New: startup_commit_state.
  • xmem_mapped_pages_commit, xmem_mapped_pages_commit_failure and xmem_shim_mapped_pages (the PR edits xmem_mapped_pages.cpp).
  • startup_triage_run and runtime_startup_triage_run_cli_check.
  • The tests that go through the changed budget line in d3d12_xs_device.cpp: startup_resource_budget (WARP and hardware, debug layer 0 and 1, with the inline controls) and startup_resource_retire* (WARP and hardware variants).

What this shows: the changes to the commit-state text and the budget line do not break the budget and retire device tests on an NVIDIA adapter, and startup_commit_state passes.

What this does not show: I did not run a game, so I did not read the new commit, job and page-pool fields from a real x2w-budget line.

AI-Assisted

**@⁠SimSalabimse** on GitHub · 2026-11-26 16:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7197204233) Hardware and WARP result for head `83828d2498f79bb73021b0add6c4016794d94a09`: all pass. Part of #870. **Environment:** Windows 11 25H2 (26200), MSVC 19.42, `dev` preset, NVIDIA GeForce RTX 4070 Ti, driver 621.35 (32.0.16.2135). Tests run serially, one ctest process. **Command** ``` ctest --preset dev --no-tests=error -R "startup_commit_state|xmem_mapped_pages|xmem_shim_mapped_pages|startup_resource_budget|startup_resource_retire|startup_triage|runtime_startup_triage" ``` **Result (measured):** 40/40 passed, exit code 0. - New: `startup_commit_state`. - `xmem_mapped_pages_commit`, `xmem_mapped_pages_commit_failure` and `xmem_shim_mapped_pages` (the PR edits `xmem_mapped_pages.cpp`). - `startup_triage_run` and `runtime_startup_triage_run_cli_check`. - The tests that go through the changed budget line in `d3d12_xs_device.cpp`: `startup_resource_budget` (WARP and hardware, debug layer 0 and 1, with the inline controls) and `startup_resource_retire*` (WARP and hardware variants). **What this shows:** the changes to the commit-state text and the budget line do not break the budget and retire device tests on an NVIDIA adapter, and `startup_commit_state` passes. **What this does not show:** I did not run a game, so I did not read the new commit, job and page-pool fields from a real `x2w-budget` line. AI-Assisted
github-bot changed target branch from main to gh-pr/2833/base 2026-11-27 19:32:17 +00:00
github manually merged commit 83828d2498 into gh-pr/2833/base 2026-11-27 19:32:19 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 19:31 UTC · original · approved these changes

Independently reviewed 83828d24 integrated over main 88cddb09 (tree ef21d6cb, clean merge).

What I traced.

  • The new block in log_apply_failure runs with memory.mutex held. It doesn't lock again: slab_count(), slots_in_use() and slots_free() are plain getters, and logf only writes.
  • The two exports report_budget calls, x2w_xmem_page_stats and x2w_xmem_slab_stats, take the mutex themselves, so the d3d12_xs side calls them unlocked, which is correct.
  • The GetModuleHandleExW(0, ...) reference is released.
  • The longest line the test formats is well under the 384-byte buffer, and snprintf truncates safely.

What I ran. I built startup_commit_state_check, xmem_shim, xmem_shim_test_controls and d3d12_xs_shim in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_commit_state|xmem_mapped_pages_commit|xmem_mapped_pages_commit_failure|xmem_shim_mapped_pages|xmem_shim_page_runs|startup_triage_run|runtime_startup_triage_run_cli_check)$'

  • Result: 7/7 passed in Debug and Release /O2, with no skips.
  • The real-job case ran: there was no note: line.

End to end. No registered test reaches the new xmem_mapped_pages.cpp line. xmem_mapped_pages_commit_failure takes the strict XMemMapPhysicalPages path, which doesn't call log_apply_failure. I ran the same check with X2W_XMEM_PERMISSIVE=1 added, so the refused commit goes through local_apply_locked:

X2W_XMEM_TEST_COMMIT_FAILURE=1 X2W_XMEM_PERMISSIVE=1 out/pe-env/Scripts/python.exe -B tests/xmem_mapped_pages_commit_check.py out/build/dev/xmem-test-controls/xmem.dll failure
  • It passes, and logs once after the stage=section-backing ... error=1455 line:
    x2w-xmem commit exhausted at XMemMapPhysicalPages (error 1455): job memory limit not reached; job_peak=11 job_limit=none; system commit=<used>/<limit> avail=<free>; pool sections=0 slabs=0 slots=0/0; X2W_XMEM_LAZY_COMMIT=1 ...
  • There was no hang under the held mutex.

Mutant. Reading info.ProcessMemoryLimit instead of info.JobMemoryLimit in job_memory() fails startup_commit_state at FAIL a real job is read back. Restored, it passes. startup_commit_state is new, so it is not registered on main. git diff --check is clean.

Non-blocking notes.

  • A permissive-mode variant of xmem_mapped_pages_commit_failure with a PASS_REGULAR_EXPRESSION on commit exhausted at would keep the xmem side of this covered. As it stands, only the formatter is tested.
  • reported uses a bare InterlockedIncrement. After 2^31 commit failures it wraps negative and logs again. x2w_local::first_calls(reported, 3) is the existing helper for this gate.

Verdict: approve on 83828d24.

Environment:

  • Windows 11 25H2 build 26200.9974
  • MSVC 19.52.37029
  • Python 3.12.10
  • the test ran inside a job with no memory limit (the shell's)

CI: Build and test on Windows passes on 83828d24. There are no review threads.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-27 19:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2833#pullrequestreview-6092608111) · **approved these changes** Independently reviewed `83828d24` integrated over `main` `88cddb09` (tree `ef21d6cb`, clean merge). **What I traced.** - The new block in `log_apply_failure` runs with `memory.mutex` held. It doesn't lock again: `slab_count()`, `slots_in_use()` and `slots_free()` are plain getters, and `logf` only writes. - The two exports `report_budget` calls, `x2w_xmem_page_stats` and `x2w_xmem_slab_stats`, take the mutex themselves, so the `d3d12_xs` side calls them unlocked, which is correct. - The `GetModuleHandleExW(0, ...)` reference is released. - The longest line the test formats is well under the 384-byte buffer, and `snprintf` truncates safely. **What I ran.** I built `startup_commit_state_check`, `xmem_shim`, `xmem_shim_test_controls` and `d3d12_xs_shim` in `dev` and `release`, then ran: `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_commit_state|xmem_mapped_pages_commit|xmem_mapped_pages_commit_failure|xmem_shim_mapped_pages|xmem_shim_page_runs|startup_triage_run|runtime_startup_triage_run_cli_check)$'` - **Result:** 7/7 passed in Debug and Release `/O2`, with no skips. - **The real-job case ran:** there was no `note:` line. **End to end.** No registered test reaches the new `xmem_mapped_pages.cpp` line. `xmem_mapped_pages_commit_failure` takes the strict `XMemMapPhysicalPages` path, which doesn't call `log_apply_failure`. I ran the same check with `X2W_XMEM_PERMISSIVE=1` added, so the refused commit goes through `local_apply_locked`: ``` X2W_XMEM_TEST_COMMIT_FAILURE=1 X2W_XMEM_PERMISSIVE=1 out/pe-env/Scripts/python.exe -B tests/xmem_mapped_pages_commit_check.py out/build/dev/xmem-test-controls/xmem.dll failure ``` - It passes, and logs once after the `stage=section-backing ... error=1455` line: `x2w-xmem commit exhausted at XMemMapPhysicalPages (error 1455): job memory limit not reached; job_peak=11 job_limit=none; system commit=<used>/<limit> avail=<free>; pool sections=0 slabs=0 slots=0/0; X2W_XMEM_LAZY_COMMIT=1 ...` - There was no hang under the held mutex. **Mutant.** Reading `info.ProcessMemoryLimit` instead of `info.JobMemoryLimit` in `job_memory()` fails `startup_commit_state` at `FAIL a real job is read back`. Restored, it passes. `startup_commit_state` is new, so it is not registered on `main`. `git diff --check` is clean. **Non-blocking notes.** - A permissive-mode variant of `xmem_mapped_pages_commit_failure` with a `PASS_REGULAR_EXPRESSION` on `commit exhausted at` would keep the xmem side of this covered. As it stands, only the formatter is tested. - `reported` uses a bare `InterlockedIncrement`. After 2^31 commit failures it wraps negative and logs again. `x2w_local::first_calls(reported, 3)` is the existing helper for this gate. **Verdict:** approve on `83828d24`. Environment: - Windows 11 25H2 build 26200.9974 - MSVC 19.52.37029 - Python 3.12.10 - the test ran inside a job with no memory limit (the shell's) CI: `Build and test on Windows` passes on `83828d24`. There are no review threads. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.