Memory: attribute heap growth with optional lightweight counters #3049
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3049"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T17:54:28Z.
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=2mode 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.Rebased onto main (2026-11-28).
nvidia-devwas merged intomainby #3203, so this PR now targetsmainand its branch was rebased ontomain765b2c5bfff6754e8c9886a73e188a86aca3c64c: heada209ad1f0ea884676a65a16a6769d5a0025a7343(wase6e6b38160258e43b679f7245f43d61c983e7fae). The earlier head was a merge ofnvidia-devinto the branch; that merge commit is gone and the three commits of this PR are replayed onmain. Conflicts were theXCL_ACTIVITYparagraph of README.md and one line ofhost.rs. On the rebased head, on the same RTX 3060 Ti PC, debug profile:cargo check -p xcl --all-targetsexited 0, andcargo test -p xcl --lib -- --test-threads=4 a_large_allocation_is_kept_with_its_place_until_it_is_freed about_one_small_allocation_in_sample_is_kept counters_only_do_not_retain_sites sizes_fall_in_their_class the_reports_own_buffer_is_not_reported heap_countgave 5 passed, 0 failed, 0 ignored, no SKIPPED. The whole suite and the paired title runs have not been rerun on this head; every other result below is from the earlier head. The rebase and its conflict resolution were done with Claude Code.What is in it
XCL_ACTIVITY=1; counts are concurrent samples, not an atomic process snapshot.Tested
Current PR head:
e6e6b38160258e43b679f7245f43d61c983e7fae. Independent source review andgit diff --check.Combined integration
d54d80e1bc9d070cbec4a619abb5f4b89880b2f5compiled withcargo 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/6B4TykyC4W
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-27T20:21:08Z.
I found a reporting self-allocation on head
1d46e4b64b03e84286947151c6586111c7d84d8ausing the productionCountingallocator andlines(2)in a standalone native Windows probe.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.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T20:57:24Z.
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.rswas byte-for-byte the Git blob at1d46e4b64b03e84286947151c6586111c7d84d8a, then reran the pinnedheap-phases.exewithXCL_HEAP_COUNT=1. Only the six worker payloads usedCounting. The observer sampledlive()between synchronized phases.One fixture check passed, with zero failures, ignores, or skips. The native process exited 0. The logging wrapper initially mistook the
skipped=0tally 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.Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T21:21:15Z.
Thanks, confirmed and fixed in
f9d239bb: the snapshot is now copied bysnapshot_into, which skips the snapshot buffer's own address. The testthe_reports_own_buffer_is_not_reportedkeeps 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.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-27T21:26:15Z.
I reran the same standalone native Windows
Counting+lines(2)probe from my earlier report against updated headf9d239bbdc5d2b8019ac58110e5752774a86eb2d, 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.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-28T12:06:50Z.
Failed interactive integration result for
d54d80e1bc9d070cbec4a619abb5f4b89880b2f5, containing this PR's change together with the other memory/removal repairs. This was not a standalone test ofe6e6b38160258e43b679f7245f43d61c983e7faeand does not establish which change caused or prevented a symptom.0x887a0005(DEVICE_REMOVED); no external stop or automated inputs.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
Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T04:23:16Z.
Edited 2026-11-29 (twice): first to "not yet" after Kalmarv's merge-check, then corrected - see my two replies below.
How this was run: the suite ran once on the 11 of your PRs that build on this base, merged together (#3047 #3048 #3049 #3091 #3092 #3103 #3104 #3105 #3107 #3123 #3125; a local tree, only #3125 needed a resolution in README and the
sparse.rstest module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27SKIPPEDlines (21 no wave64, 3 refused per-lane f16/f32 forms, 2 heap windows opt-in, 1 driver cache needs Developer Mode). This PR alone was merged onto the base, built (cargo build --workspace, then release), its modules' lib tests run (debug), and smoke-run once for 60 s (scripts/smoke.ps1, retail title, front end,XCL_PREPARE=0). The smoke numbers are for my local merged tree, not a clean-head block for the description. Load runs: 150 s, the save loaded with A presses,XCL_PREPARE=0, after one warm-up, one run per arm; on this 10 GB card main is over the video memory budget while loading, and presents stop after 94-125 s in every arm.AI use: Claude Code (Claude Opus 5.5 and Claude Fable 5.2) ran the builds, tests and title runs, reviewed the diff and wrote this; the code points cited were checked against the merged tree.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T04:28:01Z.
Independent Windows check of #3049 head
a209ad1fagainst its parent765b2c5b. RTX 3080 Ti / NVIDIA 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1, DXC 1.8.2502.11. Both checkouts were clean for the results below.cargo build --offline --locked -j 4 --workspacepassed on the PR head.cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4: 2,596 passed, 3 failed, 49 ignored; 26 GPU SKIPPED notices (those skips are included in Cargo's pass counts). The failing cases wereconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk,a_preparation_worker_also_builds_a_split_programs_whole_form, andtest_title_draws_with_a_root_signature_under_the_debug_layer. I reran the first two separately on the exact parent; both failed there too (0 passed, 1 failed each, no skips). The debug-layer title test passed alone on the PR head (1 passed, 0 failed, no skips), so its full-suite failure is not attributed to this change. These results do not establish a passing whole suite or merge readiness.The new
XCL_HEAP_COUNT=2test currently callsadded(..., false)directly. I added a disposable child-isolated test that sets the environment before the test process starts, then uses the productionCountingallocator to allocate, reallocate and free a 2→3 MiB buffer. It checked exact byte/count deltas, absence of a retained stack site, and the two-line counters-only report.cargo test --offline --locked -j 4 -p xcl --lib heap_count::tests::counters_only_mode_uses_the_actual_allocator_path -- --exact --test-threads=1 --nocapture: 1 passed, 0 failed, 0 ignored, no skip. This is a test-only candidate, not part of the clean PR-head suite.Passing test-only candidate diff
I did not run paired clean-commit title smoke, a long memory-attribution run, AMD or Intel. AI use: Codex (GPT-6.2 Sol) ran the tests and wrote this report; Codex (GPT-6.2 Sol) independently reviewed the counters-only path.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T05:40:22Z.
At #3049 head
a209ad1f, the detailed heap report labelsUNTRACKEDas large allocations “not kept: table full.” The counter actually increments when a kept large or sampled-small allocation misses its 64-slot probe window, and it never decrements on free. An otherwise empty table given 65 kept addresses with the same initial slot would record one miss; that count would remain after all 65 were freed. It does not establish that the table is full or that a large allocation is still live.For memory investigations, I suggest reporting this separately as cumulative site insertion misses after 64 probes, including both size groups. The small logging-only diff below also corrects the counter comment. It does not change allocation behavior, the counter, or the memory budget. This is a source review and candidate wording; I did not run a build or synthetic collision test for it.
Candidate diagnostic wording diff
AI use: Codex (GPT-6.2 Sol) checked the source and wrote this report and wording diff; Codex (GPT-6.2 Astra) independently reviewed the counter semantics.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T22:38:30Z.
merge-check
base:
beeb81be4b(mergeable cleanly on current main)head:
a209ad1f0emerge: clean
build: cargo check -p xcl --all-targets -> ok
tests: non-GPU lib tests of touched modules (heap_count 5 passed, host 2 passed). Full workspace suite and GPU tests not run.
review: (1) Adding note_heap to crates/xcl/src/gpu/recomp/dxc.rs (which is in build.rs TRANSLATOR_SOURCES) changes XCL_TRANSLATOR_SOURCE_ID, invalidating the translated-DXIL cache and native preparation key for all users on first run (measured +76 s to first present on a warm cache: 140.9 vs 64.4 s; driver blobs still hit). Suggest registering the DXC heap from outside dxc.rs. (2) XCL_HEAP_COUNT is not in shaders.rs warm_settings() ignore list, so enabling the diagnostic changes the warm settings key. Allocator implementation itself looks sound (one relaxed load when off).
performance: one relaxed load per allocation when off, plus the one-time cache invalidation noted above. Tested in a combined 600 s retail run on main
beeb81be+ 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.verdict: not yet: dxc.rs edit invalidates translated-DXIL caches; XCL_HEAP_COUNT missing from warm_settings() ignore list; full suite not run.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:45:56Z.
Review: COMMENTED
Critical review of current head
a209ad1f. Diagnostic accuracy issue: the detailed heap report callsUNTRACKEDlarge allocations 'not kept: table full', but the counter is a cumulative insertion miss after a 64-slot probe and can include sampled-small allocations; it remains nonzero after those allocations are freed. This can falsely explain current commit growth. Please label it as cumulative site insertion misses (both size groups), or maintain a true live count. The source analysis includes a 65-address example. This is an instrumentation fix, not a RAM reduction. No local Windows run.Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T23:00:20Z.
@Kalmarv both findings hold at
a209ad1f, and they change my verdict from yesterday's merge-check (comment) from "safe to merge" to "not yet". I had missed both.gpu/recomp/dxc.rs(heap_count::note_heap("DXC", …)) is in a filebuild.rslists inTRANSLATOR_SOURCES, so the translated-DXIL cache of every user is rebuilt once after the merge, for a diagnostic that is off by default. Confirmed by reading the tree; I did not measure the cost (your +76 s to the first present on a warm cache).XCL_HEAP_COUNTis not inwarm_settings()'s ignore list inshaders.rs, so turning the counter on changes the warm key. My three mode-2 load runs had the switch set, so their frame counts were taken under another warm key than the base run I compared them with – that comparison ("no cost visible") is weaker than I wrote.What I reported about the allocator itself (one relaxed load per allocation when off, the 65,536-slot site table, the spinlock in mode 1) stands. I have edited the verdict line of my merge-check to match.
Not tested: a rerun with the heap registered from outside
dxc.rsand the switch in the ignore list.RTX 3080 10 GB (621.40), Ryzen 9 7950X, Windows 11 26200. AI use: Claude Code (Claude Fable 5.2) read the tree and wrote this; read and posted by me.
Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T23:26:39Z.
Correction to my reply above – I checked the wrong tree.
I wrote that both of @Kalmarv's findings "hold at
a209ad1f". They do in the PR's own tree and at the base of that merge-check (beeb81be), but not for this PR merged onto currentmain, which is what matters:mainsincee62a02ff(#3447, merged 29 November 20:19Z) no longer listsgpu/recomp/dxc.rsinbuild.rs'sTRANSLATOR_SOURCES, so the PR's one line there does not change the translator source id any more;warm_settings()into an allow-list of translation switches, soXCL_HEAP_COUNTcannot change the warm key. (Onlylegacy_warm_settings, used to migrate a saved library, still has an ignore list.)Read in a worktree of
main53e85fb1; nothing was run. So neither point is a reason against merging onto currentmain, and my change of verdict to "not yet" for those two reasons was wrong. What remains open from the reviews is @bmjask's point about the "not kept: table full" label (a cumulative miss count, not a live one), and that nobody has run the suite on this PR merged onto currentmain– my merge-check is onfa204595and stale. I have edited its verdict line to say that instead.AI use: Claude Code (Claude Fable 5.2) found the mistake and wrote this; read and posted by me.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T12:11:49Z.
Test report for the counters, from a world run. RTX 5070 Ti 16 GB (617.42), Ryzen 7 9800X3D, 32 GB RAM, this PR's head
a209ad1fmerged ontomain9dfbe3ea, release,XCL_HEAP_COUNT=2, a retail title withXCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16. One run of 330 s; it entered the world and ran to the time limit with no device removal.About 60 s after world entry the counters give 2.47 GB for XCL's own Rust heap in 4.2 M allocations (0.92 GB under 4 KiB, 0.39 GB under 64 KiB, 0.78 GB under 1 MiB) and 0 MB for the title through the process heap.
Two other runs of the same binary without this PR put that next to the process heap as a whole:
VirtualQueryExcensus of xcl.exe at 141 s: 39.3 GB private commit, of which 5.7 to 5.9 GB is 363 to 373 private read-write regions of about 16 MiB each. A second census at 157 s in another run gave the same split.HeapSummaryfor each heap ofGetProcessHeaps(not submitted): the default process heap goes from 2.5 GB at 91 s to 5.1 GB at 114 s, which is world entry, is at 5.7 GB allocated and 6.2 GB committed at 157 s, and reaches 6.6 GB at 328 s.So on this card about 3 GB of the default process heap in the world belongs to neither XCL's Rust heap nor the title. I have no call stacks for it; the D3D12 runtime and the NVIDIA driver are the callers left, and that part is a guess. It is one run per counter, so read the sizes as rough.
If mode 2 could also print the
HeapSummaryof the default heap (allocated and committed) on thememory by ownerline, that line would explain about 6 of the roughly 10.5 GB it shows asothercommit here. Mode 1 already walks that heap, and this would be the cheap version of it.Also seen in the census and not explained by any owner: 788 private write-combined regions of 4 MiB, 3.2 GB in total.
AI use: Claude Code (Claude Opus 5.5 ran the runs, wrote the census script and the local patch and read the logs, Claude Fable 5.2 wrote this).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:51:10Z.
Review (head
a209ad1f, diff read, not a merge-check; draft, so not built or run):SITEStable (heap_count.rs~52, 65,536 x 112 B) sits inxcl.exeeven withoutXCL_HEAP_COUNT, and writable image pages are probably charged to commit at load. Comparing peak commit with main, or allocating the table on first use in detailed mode, would settle it.removed(p)runs afterSystem.reallochas freedp, so another thread that getspfirst can lose its record (the description admits this).XCL_HEAP_COUNTis set even withoutXCL_ACTIVITY, the only thing that prints the counters.pipeline_library/warm_library) also failed on main's own run that day.Fine: the title counter's add and subtract match (
total==HeapSize(raw)), the variable is read without allocating, stacks are captured outside the lock, the diagnostics are their own PR, and with the counters off the cost is one relaxed load and a branch per allocation.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T17:13:09Z.
Test report (not a merge-check: draft,
PR descriptionred)base:
b2b1f109d2head:
a209ad1f0emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2907 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3049#issuecomment-7302206605, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run.
assessment: merges, builds and passes the whole suite on current main (0 failed, its new tests included); the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.