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

Merged
tedin7 merged 3 commits from upstream-pr/2833 into main 2026-11-27 19:31:49 +00:00
tedin7 commented 2026-11-26 12:42:56 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5510225015 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T12:42:56Z. --- 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 commented 2026-11-26 13:03:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T12:46:46Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7192448626 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192448626). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T12:46:46Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-26 13:03:13 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7192451284 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192451284). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T12:46:53Z. --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-26 13:03:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T12:46:55Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7192451915 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7192451915). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T12:46:55Z. --- 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).
SimSalabimse commented 2026-11-26 16:07:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T16:07:04Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7197204233 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833#issuecomment-7197204233). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T16:07:04Z. --- 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
pigalot commented 2026-11-27 19:31:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T19:31:11Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6092608111 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2833#pullrequestreview-6092608111). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T19:31:11Z. **Review:** APPROVED --- 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.
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!2825
No description provided.