Skip to content

Memory: attribute heap growth with optional lightweight counters - #3049

Draft
Prime1997 wants to merge 4 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-heap-count
Draft

Prime1997 wants to merge 4 commits into
xcl-dev:nvidia-devfrom
Prime1997:contrib/nv-heap-count

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Process commit combines title storage, XCL allocations, shader compilation and driver memory. This existing PR attributes XCL's Rust heap and title heap allocations. The new XCL_HEAP_COUNT=2 mode keeps byte/count buckets without stack capture, the allocation-site table lock, snapshot buffers or Windows heap walks; mode 1 retains the detailed diagnostics. This is instrumentation, not a RAM or VRAM reduction.

What is in it

  • Existing size buckets, sampled stacks, title allocation counters and optional detailed compiler/process-heap reporting are preserved.
  • Lightweight counters every 20 seconds with XCL_ACTIVITY=1; counts are concurrent samples, not an atomic process snapshot.
  • Current nvidia-dev is merged without rewriting the earlier commits. One new counters-only fixture is prepared.

Tested

  • Current PR head: e6e6b38160258e43b679f7245f43d61c983e7fae. Independent source review and git diff --check.

  • Combined integration d54d80e1bc9d070cbec4a619abb5f4b89880b2f5 compiled with cargo build --locked --release -p xcl --target-dir <isolated-target>: exit 0, 229.200 seconds. This is compilation of the combined candidate, not a build or runtime validation of this standalone PR. Zero tests executed; no GPU checks or smoke run.

  • The earlier description's suite and 60-second smoke results belong to f9d239bbdc5d2b8019ac58110e5752774a86eb2d; they are historical and do not validate this new head.

Regression run
Pending for this revision. No new smoke blocks are claimed.

Not tested
Standalone compilation, new fixture, full suite, gameplay performance and long-run memory behavior at this head. The existing detailed mode retains stack-attribution limitations around concurrent realloc/address reuse and may pause allocating threads during heap walks. The next local candidate selects counters-only mode 2.

AI use
The original contribution and earlier results were prepared with Claude Code (Claude Fable 5.2 and Claude Opus 5.5). Codex (GPT-6) added and independently source-reviewed the counters-only extension, reconciled current NVIDIA, compiled the combined candidate and prepared this update.

Optional contributor/test coordination: https://discord.gg/gK3y7WRRY

The process's commit is one number for the title's memory, the driver's, the
shader compiler's and XCL's own. With XCL_HEAP_COUNT=1 (and XCL_ACTIVITY) the
log says every 20 s how much XCL's own Rust code holds, by allocation size,
and for allocations of 64 KiB and more from which call stacks (offsets in
xcl.exe, to symbolize from the .pdb); what the title holds through
XMemAllocDefault; what the shader compiler's private heaps hold and have
committed; and once a minute what the process heap holds in all.
Off, it costs one relaxed load an allocation.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@Prime1997 Prime1997 self-assigned this Nov 27, 2026
@andrewDoing

Copy link
Copy Markdown

I found a reporting self-allocation on head 1d46e4b64b03e84286947151c6586111c7d84d8a using the production Counting allocator and lines(2) in a standalone native Windows probe.

Probe payload Total live line Large-allocation line
No payload 0 MB / 0 allocations 7 MB / 1 allocation
One live 1 MiB payload 1 MB 8 MB / 2 allocations; the 7 MB site ranks first

The Vec<Site>::with_capacity(65536) created for the snapshot is itself tracked before the large-site snapshot, so it appears as a live large allocation even though the totals were sampled earlier. A local candidate excluding that snapshot buffer's address from the large-site walk reported 0 MB with no payload and 1 MB for the single-payload case.

This is a synthetic diagnostic-accuracy test, not evidence of a title memory increase or GPU impact. I did not test concurrent mutation, saturation, or a retail run.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the probe; Codex reviewed and prepared this report.

lines() copies the kept allocations into a buffer made with room for the
whole table (7 MB), and with the switch on that buffer is itself kept as a
large allocation, so the report listed it first as XCL's memory (andrewDoing's
probe on xcl-dev#3049: 7 MB with nothing else alive). The copy now skips the
buffer's own address; test the_reports_own_buffer_is_not_reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JJAutoCompare

Copy link
Copy Markdown

Tested

CPU-only on Windows 11 build 26200, Ryzen 7 3800X, and Rust 1.100.0 MSVC debug. I verified that the standalone fixture's heap_count.rs was byte-for-byte the Git blob at 1d46e4b64b03e84286947151c6586111c7d84d8a, then reran the pinned heap-phases.exe with XCL_HEAP_COUNT=1. Only the six worker payloads used Counting. The observer sampled live() between synchronized phases.

Phase Raw live bytes Raw live allocations
Before allocation 0 0
Both workers' payloads live 1,126,783 6
First worker's payloads released 1,057,023 3
Both workers' payloads released 0 0

One fixture check passed, with zero failures, ignores, or skips. The native process exited 0. The logging wrapper initially mistook the skipped=0 tally for a skip. I verified the recorded native exit and tally separately.

Not tested

Diagnostic formatting or self-allocation, observation during concurrent mutation, other allocator paths, the workspace suite, GPU or retail runs, and performance.

AI use

T3 Code / Codex (gpt-6.2-sol) wrote the fixture, independently reran it, and drafted this report.

@Prime1997

Copy link
Copy Markdown
Collaborator Author

Thanks, confirmed and fixed in f9d239b: the snapshot is now copied by snapshot_into, which skips the snapshot buffer's own address. The test the_reports_own_buffer_is_not_reported keeps the buffer as the switch would and checks that it's left out while another large allocation is reported; it fails without the fix. The suite and the smoke for the new head are in the description.

AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply; Prime posted it.

@andrewDoing

Copy link
Copy Markdown

I reran the same standalone native Windows Counting + lines(2) probe from my earlier report against updated head f9d239bbdc5d2b8019ac58110e5752774a86eb2d, with a freshly built binary.

The empty payload now reports 0 MiB / 0 large sites (previously 7 MiB / 1 site). One live 1 MiB payload reports 1 MiB / 1 large site (previously 8 MiB / 2 sites), and the total live lines remain 0 and 1 MiB respectively. This verifies the reported self-allocation case; concurrent mutation, saturation, and retail behavior were not tested.

AI use: OpenAI Codex with GPT-6.2 Astra ran the probe; Codex reviewed and prepared this report.

Extend existing PR3049 with XCL_HEAP_COUNT=2 to omit sampled stacks and synchronous Windows heap walks while retaining Rust and title allocation totals. Source-reviewed independently; fixtures added but not executed. This is diagnostic attribution, not a measured memory reduction.

Assisted-by: Codex (GPT-6)
@Prime1997 Prime1997 changed the title Memory: XCL_HEAP_COUNT=1 counts XCL's own heap by size and by place Memory: attribute heap growth with optional lightweight counters Nov 28, 2026
@Prime1997

Copy link
Copy Markdown
Collaborator Author

Failed interactive integration result for d54d80e1bc9d070cbec4a619abb5f4b89880b2f5, containing this PR's change together with the other memory/removal repairs. This was not a standalone test of e6e6b38160258e43b679f7245f43d61c983e7fae and does not establish which change caused or prevented a symptom.

  • RTX 3060 Ti 8 GiB, 32 GiB system RAM, release, about 402 seconds with 126 read-only monitoring samples. XCL ended the title itself with 0x887a0005 (DEVICE_REMOVED); no external stop or automated inputs.
  • Peak process commit: 22,994 MiB; peak resident process-tree RAM: 15.79 GiB. Peak DXGI local usage: 6,839 MiB; all 196 console memory lines were below their simultaneous local budget, with minimum headroom 218 MiB. Sampling cannot rule out a transient overrun.
  • Last positive presentation interval was observed around 173 seconds. Audio/diagnostic activity continued during the later rendering stall.
  • DRED state was UNKNOWN. Both page-fault output and breadcrumbs returned 0x887a0004 (unsupported), so there is no reliable GPU fault location. System commit still had 34,764 MiB headroom at removal; no out-of-memory result was established.

Counters-only mode2 ran throughout. Between observations at 12:00:39 and 12:03:19 UTC, process commit rose from 19,977 to 22,880 MiB while Rust live allocations fell from 1,051 to 766 MiB. The increase is outside the Rust live payload count; native/driver/title allocations and allocator-retained capacity remain unseparated. No expensive stack capture or Windows heap walks were enabled.

This run does not justify merge approval or a claim that RAM growth/device removal is fixed. Full standalone validation and matching main/head smoke reports remain outstanding. No builds or synthetic GPU tests ran during gameplay. Logs, hashes, counter samples and source/installed-data preservation checks are retained locally.

AI use: OpenAI Codex (GPT-6) launched the prepared candidate at the user's request, monitored existing logs and read-only counters, and prepared this report; a separate Codex agent reviewed the log evidence.

Optional contributor/test coordination: https://discord.gg/gK3y7WRRY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants