A memory line at every crash and while the title runs: process and system commit, video memory, what the title asked for #191

Open
gbuyssens wants to merge 1 commit from upstream-pr/194 into main
gbuyssens commented 2026-11-23 20:02:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gbuyssens on 2026-11-23T20:02:05Z.


…stem commit, video memory, what the title asked for

A title that runs out of memory dies in an allocation of its own far from the cause (a write to address 0 in its thread start-up; the driver's E_OUTOFMEMORY on a pipeline). memstat.rs logs one line – the process's commit charge and working set, the system's commit against its limit and free RAM, local and non-local video memory in use (IDXGIAdapter3), the bytes the title asked kernelx for by kind (sparse / UMA graphics memory, Windows commits, XMemAlloc heaps, the homes of its physical pages; gross) and the sparse windows' tiles and pools – at every unhandled exception, when the process ends with an error, and from a thread whenever the commit grew by a GiB (every 30 s at most).

The crash line carries the code bytes at RIP for every exception, not only illegal instructions: the registers alone rarely say what was dereferenced.

<!-- greyfinch-sync:ivall/xcl:issue:5460275901 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/194). Originally posted by [gbuyssens](https://github.com/gbuyssens) on 2026-11-23T20:02:05Z. --- …stem commit, video memory, what the title asked for A title that runs out of memory dies in an allocation of its own far from the cause (a write to address 0 in its thread start-up; the driver's E_OUTOFMEMORY on a pipeline). memstat.rs logs one line – the process's commit charge and working set, the system's commit against its limit and free RAM, local and non-local video memory in use (IDXGIAdapter3), the bytes the title asked kernelx for by kind (sparse / UMA graphics memory, Windows commits, XMemAlloc heaps, the homes of its physical pages; gross) and the sparse windows' tiles and pools – at every unhandled exception, when the process ends with an error, and from a thread whenever the commit grew by a GiB (every 30 s at most). The crash line carries the code bytes at RIP for every exception, not only illegal instructions: the registers alone rarely say what was dereferenced.
Kalmarv commented 2026-11-24 07:04:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-23T20:41:36Z.


I tested PR head 9e79c69db8a11cebde2ef32b23f41b620c7efa6d directly on Windows 11 build 26200, with a test-only probe in the synthetic process. All three runs passed: an uncapped CPU run, a CPU process with a 1 GiB process commit limit, and a DXGI run on an RTX 5070 Ti in an 8 GiB job.

A touched 128 MiB allocation raised private commit and working set by approximately 128 MiB in each run. Both fields agreed with a separate process-counter read within 1 MiB. The no-device control omitted the video fields. With the device initialized, I independently enumerated adapters, matched the device LUID and queried node 0. The two readers agreed byte-for-byte on local usage and budget (13,488,128 / 15,966,666,752 bytes) and nonlocal usage and budget (567,066,624 / 15,913,553,920 bytes).

One portability correction: for fields labelled system commit, use GetPerformanceInfo and multiply CommitTotal and CommitLimit by PageSize. Both numbers agreed in all three runs here, but MEMORYSTATUSEX documents its limit and available commit in terms of what the calling process can commit. Its ullAvailPhys field is available RAM, which includes standby pages, so “RAM available” would also be more precise than “RAM free”. Microsoft’s field definitions

On the reporting hot path, successful tracked allocations/commits add a relaxed atomic increment, including individual physical-page operations. Rendering and presentation have no new polling calls. The sampling worker checks process counters every 30 seconds and builds the full line only on its growth threshold. This is a source-level overhead check. I did not measure frame times, trigger a real crash or run a title.

<!-- greyfinch-sync:ivall/xcl:comment:7113423521 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/194#issuecomment-7113423521). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-23T20:41:36Z. --- I tested PR head `9e79c69db8a11cebde2ef32b23f41b620c7efa6d` directly on Windows 11 build 26200, with a test-only probe in the synthetic process. All three runs passed: an uncapped CPU run, a CPU process with a 1 GiB process commit limit, and a DXGI run on an RTX 5070 Ti in an 8 GiB job. A touched 128 MiB allocation raised private commit and working set by approximately 128 MiB in each run. Both fields agreed with a separate process-counter read within 1 MiB. The no-device control omitted the video fields. With the device initialized, I independently enumerated adapters, matched the device LUID and queried node 0. The two readers agreed byte-for-byte on local usage and budget (13,488,128 / 15,966,666,752 bytes) and nonlocal usage and budget (567,066,624 / 15,913,553,920 bytes). One portability correction: for fields labelled **system commit**, use `GetPerformanceInfo` and multiply `CommitTotal` and `CommitLimit` by `PageSize`. Both numbers agreed in all three runs here, but `MEMORYSTATUSEX` documents its limit and available commit in terms of what the calling process can commit. Its `ullAvailPhys` field is available RAM, which includes standby pages, so “RAM available” would also be more precise than “RAM free”. [Microsoft’s field definitions](https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex) On the reporting hot path, successful tracked allocations/commits add a relaxed atomic increment, including individual physical-page operations. Rendering and presentation have no new polling calls. The sampling worker checks process counters every 30 seconds and builds the full line only on its growth threshold. This is a source-level overhead check. I did not measure frame times, trigger a real crash or run a title.
upipibi commented 2026-11-24 07:06:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T05:29:19Z.


One ordering point in 9e79c69, from reading the code (not run): in the crash handler, memstat::log() runs before report::write_final(Some(msg)) (eh.rs:113-114, and again at :136). Nothing calls memstat::adapter() before a crash, so the first call creates a DXGI factory and enumerates adapters inside the handler, and every call then goes into the driver with QueryVideoMemoryInfo (memstat.rs adapter / video). The crashes this line is meant to explain (out of memory, or a fault in the driver itself) are the ones where that call is most likely to block or fault again, and then the report is never written. try_lock already covers a crash in a thread that holds the lock, but not this.

Two cheap changes would keep the report safe: write the report first and log the memory line after it, and resolve the adapter when the device is created (e.g. from real::init), so the handler only does the two queries.

Also: this now conflicts with main in eh.rs and kernelx.rs.

AI-assisted (Claude Code), read-only review.

<!-- greyfinch-sync:ivall/xcl:comment:7122994417 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/194#issuecomment-7122994417). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T05:29:19Z. --- One ordering point in `9e79c69`, from reading the code (not run): in the crash handler, `memstat::log()` runs before `report::write_final(Some(msg))` (`eh.rs:113-114`, and again at `:136`). Nothing calls `memstat::adapter()` before a crash, so the first call creates a DXGI factory and enumerates adapters inside the handler, and every call then goes into the driver with `QueryVideoMemoryInfo` (`memstat.rs` `adapter` / `video`). The crashes this line is meant to explain (out of memory, or a fault in the driver itself) are the ones where that call is most likely to block or fault again, and then the report is never written. `try_lock` already covers a crash in a thread that holds the lock, but not this. Two cheap changes would keep the report safe: write the report first and log the memory line after it, and resolve the adapter when the device is created (e.g. from `real::init`), so the handler only does the two queries. Also: this now conflicts with `main` in `eh.rs` and `kernelx.rs`. AI-assisted (Claude Code), read-only review.
DavidM1911 commented 2026-11-25 16:12:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T15:19:50Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7166671810 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/194#issuecomment-7166671810). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T15:19:50Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Foniass commented 2026-12-01 03:00:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:00:03Z.


Triage (#1607) – head 9e79c69

No open PR adds a memory line at crash/exit. Partial overlap with main:

  • eh.rs: code_at and the "(code bytes: …)" text are already on main (0b28a391), so that part of the diff would add them twice.
  • main has the XCL_ACTIVITY memory report (d3d12x/memory_report.rs, #2697) with process commit and video segments. It is not logged at a crash, which is what this PR adds.
    Problem: memstat::adapter() calls CreateDXGIFactory1 / EnumAdapterByLuid the first time it runs, which can be inside the unhandled-exception filter. Loading DXGI from a crashing thread can block on the loader lock. The TITLE counters only add (frees are never subtracted), so they are totals asked for, not current use.
    Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7299214379 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/194#issuecomment-7299214379). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:00:03Z. --- **Triage (#1607)** – head 9e79c69 No open PR adds a memory line at crash/exit. Partial overlap with main: - `eh.rs: code_at` and the "(code bytes: …)" text are already on main (0b28a391), so that part of the diff would add them twice. - main has the `XCL_ACTIVITY` memory report (`d3d12x/memory_report.rs`, #2697) with process commit and video segments. It is not logged at a crash, which is what this PR adds. Problem: `memstat::adapter()` calls `CreateDXGIFactory1` / `EnumAdapterByLuid` the first time it runs, which can be inside the unhandled-exception filter. Loading DXGI from a crashing thread can block on the loader lock. The `TITLE` counters only add (frees are never subtracted), so they are totals asked for, not current use. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/194:upstream-pr/194'
git switch 'upstream-pr/194'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/194'
git switch 'upstream-pr/194'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/194'
git switch 'upstream-pr/194'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/194'
git switch 'main'
git merge --squash 'upstream-pr/194'
git switch 'main'
git merge --ff-only 'upstream-pr/194'
git switch 'main'
git merge 'upstream-pr/194'
git push origin 'main'
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
xcl-dev/xcl!191
No description provided.