d3d12: memory grows without bound while driving on a 64 GB / 32 GB machine; texture-pool blocks are never given back #3261
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Reference
No Branch/Tag specified
main
github-pr/3295
beta
docs/changelog-3483-3500
github-pr/3294
github-pr/2975
github-pr/2815
feat/gate-driver-start
feat/skip-pipelines-release
perf/lazy-compare
perf/mwaitx-wait
test/prio-ceiling-main
fix/ab-cpu-stdout
fix/gate-old-crashes
diag/ab-cpu
test/main-0312
github-pr/3291
diag/indirect-clamp-census
feat/barrier-enhanced
perf/texture-frame-ceiling
perf/dstorage-threads
fix/console-queue-dma-tables
fix/port-descriptors-record-parts
fix/frame-waits-fence
fix/console-sampler-words
fix/graphics-userdata-spill
fix/xg-reserved-layout-rotation
fix/barrier-console-flags
fix/switches-wait-test-child
test/list-value-waits
test/lot-gxdk-0412
fix/bvh-compacted-size
docs/i18n-quickstarts
feat/native-pipeline-slots
fix/clippy-leonida-gpu
fix/list-value-producers
fix/descriptor-page-straddle
fix/xmem-low-window
fix/ffx-jitter-never-zero
fix/run-stdout-closed
github-pr/2892
github-pr/2896
feat/warm-save-every
github-pr/2980
github-pr/2994
github-pr/3005
github-pr/3010
github-pr/3136
github-pr/3303
github-pr/3220
github-pr/3143
github-pr/3330
github-pr/3226
github-pr/3187
carry/3395
github-pr/2946
github-pr/2947
github-pr/2945
github-pr/2983
github-pr/3001
github-pr/3372
github-pr/3128
github-pr/3296
github-pr/2588
github-pr/3119
github-pr/3378
fix/crash-diagnostics
feat/dlss-mip-bias
fix/retired-out-of-order
fix/dxr-postbuild-barrier
fix/amd-relay-default
fix/removed-report-wait
feat/heap-twin
feat/vram-margin
github-pr/2472
github-pr/3123
github-pr/3088
assets/annonce-v1
github-pr/2794
github-pr/3300
github-pr/3304
github-pr/3308
github-pr/3367
github-pr/3369
fix/launcher-dlss-diagnostics
github-pr/3269
github-pr/2957
github-pr/3205
fix/crash-zero-guard
github-pr/3185
github-pr/3099
github-pr/3104
github-pr/3348
github-pr/3379
github-pr/3377
perf/darner-title-priority-ceiling
github-pr/3376
gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github-pr/3373
github-pr/3368
github-pr/3198
gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github-pr/3346
github-pr/3375
github-pr/2958
github-pr/3151
github-pr/3307
github-pr/3278
github-pr/3374
fix/runtime-test-conservative-fixtures
github-pr/3366
ci/shard-semantic-linux
github-pr/3354
docs/fg-limit-fps-switch
github-pr/3365
fix/read-file-hard-link
github-pr/3364
fix/book-slot-heap-never-read
github-pr/3361
github-pr/3263
github-pr/3360
github-pr/3353
github-pr/3331
fix/alias-later-queued-submissions
github-pr/3352
github-pr/3228
github-pr/3349
claude/gallant-sagan-aamatr
github-pr/3200
github-pr/3132
github-pr/3323
github-pr/3332
github-pr/3340
github-pr/3311
github-pr/3334
github-pr/3297
github-pr/3256
github-pr/2567
github-pr/2851
d3d12/agility-sdk-621
github-pr/3164
github-pr/3114
github-pr/3050
github-pr/3113
github-pr/3326
github-pr/3144
github-pr/2642
github-pr/3072
github-pr/2789
github-pr/2643
github-pr/3009
github-pr/3035
github-pr/3031
github-pr/2686
github-pr/2834
github-pr/3321
github-pr/3325
github-pr/3290
github-pr/3324
github-pr/3130
claude/fervent-curie-m19lnr
github-pr/3309
github-pr/3305
github-pr/3306
github-pr/3302
github-pr/3301
github-pr/3345
github-pr/3211
github-pr/3027
github-pr/3286
github-pr/3235
github-pr/3265
github-pr/3275
codex/skip-no-hit-ray-passes
github-pr/2823
github-pr/2911
github-pr/3262
github-pr/3125
github-pr/3206
github-pr/3250
github-pr/3238
github-pr/3188
github-pr/2952
github-pr/3217
github-pr/3168
t3/preserve-fsr-sdk-restart-path
t3/propagate-host-failure-hresult
github-pr/3209
t3/launcher-custom-parameters
github-pr/3207
github-pr/3183
github-pr/3160
github-pr/3201
ci/less-to-run
github-pr/2930
github-pr/2797
github-pr/2999
perf/native-compute-shader-forms
github-pr/3191
github-pr/3011
github-pr/3019
github-pr/2996
gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
claude/blissful-franklin-ukp7ag
github-pr/3141
github-pr/3156
github-pr/3150
github-pr/3153
github-pr/3163
github-pr/3142
github-pr/3139
github-pr/2841
github-pr/3069
github-pr/3098
github-pr/3107
github-pr/3071
github-pr/2774
github-pr/2889
github-pr/3075
github-pr/2661
github-pr/3064
github-pr/3054
github-pr/3049
github-pr/2855
github-pr/2943
github-pr/3016
github-pr/2887
github-pr/3006
github-pr/3003
github-pr/2993
notes/card-time-and-plant-flicker
github-pr/2989
feat/vulkan-rs
github-pr/2985
github-pr/2951
github-pr/2982
github-pr/752
github-pr/792
github-pr/2877
github-pr/2654
github-pr/2893
github-pr/2948
github-pr/2944
github-pr/2919
github-pr/2915
archive/ci/less-to-run/20261202T1121Z
github-pr/2800
github-pr/2822
github-pr/2833
github-pr/2840
github-pr/2831
github-pr/2832
github-pr/2801
github-pr/2890
github-pr/2891
github-pr/2664
github-pr/2807
rt-call-trace
github-pr/2755
perf/ahead-split
github-pr/2587
github-pr/2698
github-pr/2609
github-pr/3219
docs/readme-runtime-proposal
github-pr/2017
github-pr/1741
github-pr/1667
codex/coord-claim-check-20261124-7e48
v1.1.0
v1.0.1
Notifications
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy#3261
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
What happens
On a high-RAM, high-VRAM machine, the process keeps growing for as long as the player moves through the world:
private bytes, Windows commit and card memory. Nothing gives the memory back. In a session of 10 to 15 minutes,
commit headroom falls toward zero. From there the runtime limits texture prefetch, stutters get worse, roads
show missing textures, and a crash follows if the session goes on. Restarting the game is the only workaround.
The numbers below are from the runtime's own
copystatmemory lines andcensuslines, over several runs on2026-12-02.
Growth over one session (city driving, hardware RT on):
That is about +1 GB of commit a minute while driving, and it never comes back down.
GetProcessMemoryInfo, DXGIQueryVideoMemoryInfo), so they do not include it. The Windows commit headroom is system-wide, so it is lower than on an otherwise idle PC by what that game held, and the card's budget the runtime saw fell from 31.4 GB to about 24.7 GB as VRAM filled, part of which is that game's share.Where it sits (the
censusline at the end of runs B and D):The 64 MiB
DEFAULTtexture blocks make up the bulk, and they only grow.What exists today, and why it is not enough here:
LEONIDA_REAPER=1(withLEONIDA_REAPER_LIMIT): on this machine, commit headroom still fell from 28.9 GB to6.9 GB in 15 minutes. In earlier builds it crashed after about 8 minutes. Retried tonight on the build below with
DLSS on: the device was lost about 50 s into the world (
device removed, 0x887A0006). The same build and settingswithout the reaper then ran 8 minutes with no device loss. That is one run each, so not proof. So I run with
LEONIDA_REAPER=0, and the table above is with it off.LEONIDA_COMMIT_FLOORon): I tested it in game (comment there). Onceheadroom fell to about 4.5 GB, it did let go of idle textures, 184k → 24k. But the 64 MiB blocks stayed:
192 blocks, 12.3 GB, holding 2.1 GB of live textures. So private bytes, commit and card memory kept their trend.
Suggestion: give back texture blocks (and shared-buffer blocks) once they are empty or nearly empty, or
compact them, driven by the same commit floor. Or cap the pool's block count by the card's budget on cards where
VRAM is not the limit but commit is.
Commit
Upstream main
0d7a451ab(2026-12-02), plus #3113, #3182 and #3204. Diag build. Run A was ona917c54d6, the samemorning, and grew the same way.
System
NVIDIA GeForce RTX 5090 32 GB, driver 621.40; i9-14900KS; 64 GB DDR5; Windows 11 (build 26300). Page file
system-managed.
Where
In the world, from a save, mostly city driving (also on foot). Standing still grows far more slowly.
Command and steps
scripts/play-d3d12.ps1 -HardwareRT -SmoothMotion -PrecompileAll -Log. Series X profile, output 3840x2160,render scale 0.6667,
LEONIDA_REAPER=0,LEONIDA_FPS_CAP=0. Load a save and drive around the city for 10 to 15minutes, then read the
copystat: memory:lines and thecensusline.Output
A
copystatline from run B at its end:Related: #3201 (partial fix: textures freed, blocks kept), #2821 (device removed after 5-46 min on a 4070 SUPER;
may share this cause), #3129 (16 GB memory wall).
AI-assisted: the log analysis and the write-up were done with Claude Opus 5.5 (Claude Code); the numbers are the
runtime's own log lines from the runs above.
Scripted repro without driving: camera spinning in place. Memory climbs fast, then plateaus. The reaper changes nothing.
Same machine as in the issue (RTX 5090 32 GB, driver 621.40, i9-14900KS, 64 GB DDR5, Windows 11 26300). Build: current play build (main
0d7a451ab+ local patches), diag,-HardwareRT -SmoothMotion -PrecompileAll -Dlss quality, 4K output. The character walks forward (W), and the camera turns with the look keys (Lfor 20 s, thenJfor 20 s, repeated) throughLEONIDA_KEYS_FILE. A driver script reads the log and presses Enter only while the frame has fewer than 3000 draws, so no input reaches the world before it loads. Each run is 600 s in the world.LEONIDA_REAPER=1LEONIDA_REAPER=0GetProcessMemoryInfo, DXGIQueryVideoMemoryInfo), so they do not include it. The Windows commit headroom is system-wide, so it is lower than on an otherwise idle PC by what that game held, and the card's budget the runtime saw fell from 31.4 GB to about 24.7 GB as VRAM filled, part of which is that game's share.LEONIDA_REAPER=1and=0match within noise.LEONIDA_D3D12_DRED=1set.The scripts (an adaptive menu/world key driver plus a log parser) are small bash; I can attach them if they help with reproducing.
AI-assisted: the runs, the key driver, the log reading and this write-up were done with Claude Opus 5.5 (Claude Code); the numbers are the runtime's own log lines.
For D3D12-POOL-PACK-FULLEST-BLOCK, I reproduced the re-pin behavior with the exact
Pool/Rangescode fromd9b618f10, using synthetic block handles and a fixed clock.Two ripe 64 MiB blocks have 8 MiB and 48 MiB live, with room in both for a new 8 MiB piece. With the sparse block first, the current allocator places the new piece there. When that block’s original piece is returned and finishes resting, the pool still has two blocks even with
reclaim(..., 0, true). Reversing only the two block entries sends the new piece to the fuller block. The sparse block then drops from the pool exactly when its original piece finishes resting, leaving one block. There was no GPU allocation in this test.This gives the packing change a small acceptance case and shows how it complements #3201: a lower empty-spare limit only helps once the sparse block actually becomes empty. AI-assisted with OpenAI Codex.
A 32 GB PC: private bytes level off at about 27–28 GB, but physical memory is under pressure much of the time
Same build and settings as my comment in #3255 (https://github.com/ProjectLeonida/mandy/issues/3255#issuecomment-7380290745): RTX 5070 12 GB, 32 GB RAM + 32 GB fixed page file (commit limit 63.1 GB), Series X, DLSS + FG 2×,
LEONIDA_WINDOWS_BAR_MB=3072(the play script's default under 48 GB of RAM). From thecopystatmemory lines, the video memory lines and the residency summary (MB from the log ÷ 1024):residency: run 1 had 1,962 of 2,034 one-second looks under pressure, run 2 had 265 of 500, every one by physical memory alone (commit never under 4 GiB left). The least seen: 291 MB and 469 MB of physical memory free, with 13,264 and 13,973 MB left to commit. On 32 GB the wall is physical memory, well before commit.Numbers collected from the logs with Claude Opus 5.5 (AI-assisted); reviewed by me before posting.
A read-only audit of the
D3D12-SHADER-BYTES-MAPPEDlead (no game run). The memory claim is real and the mechanism is sound; two corrections to the framing.Accounting confirmed:
Shader.container(pipeline.rs:63/146) = 188 MiB,Translated.host.dxil(emit/mod.rs:723) = 270 MiB — 458 MiB in this run.KEPT[0..3]counts only these two; the rest ofHostShaderand theArc/Pendinglists are smaller.Correction 1 — not a read-once cache.
dxilis read at everyHostPipeline::new(host.rs:875,887,951,978,1023), including pipeline-library hits, because the description and library name are built beforelibrary::pipeline.containeris read at title pipeline creation (make::named, andknownwhen the book is on), not only at translation. So trimming must be idle/pressure-based, not “after translation”.Correction 2 — the mechanism is already in-tree.
library.rs:112-208maps the pipeline library for exactly this reason (a 1.35 GB buffer otherwise), and trims withVirtualUnlock(library.rs:374-412). A synthetic 64 MiB prototype here reproduced it: 64.9 MiB private → 0.8 MiB after trim, working set back to baseline, identical bytes after re-read, pointer unchanged. Under memory pressure the pages may hit disk, so trim on idle/pressure and measurePages Input/sec.Minimal safe step —
dxilfirst: aBytes/Blobseam inpipeline/bytes.rs, arena chunks (oneFILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSEfile per kind, 64 MiB chunks — not one mapping per shader),VirtualUnlockon idle or under pressure,LEONIDA_SHADER_MAP=0to force in-memory for A/B.dxilis the better first phase: 270 MiB, written on pipeline workers (not the title’s 60k-pipeline burst), and already on disk in the shader cache. Mappingcontainerwrites the title’s original bytes to a temp file, so that is a second phase needing a policy decision.Risks: fault storms at pipeline creation, address-space/handle count if not arena-based, disk I/O under pressure, cleanup on crash (delete-on-close covers normal exit and kill; stale PID-named files cleaned at start). Tests: reload returns identical bytes; drop removes the file; mapping failure falls back to memory;
Send + Sync; a second chunk does not move the first blob. A game run is needed for the memory/stutter result.Read-only analysis of the D3D12-TEXTURE-BLOCK-8MB lead (no game run). The lead is plausible as a reserve/stranding optimisation, but the quoted occupancy numbers do not by themselves show a VRAM saving.
Byte math. At fill f, live L = fC and free = C(1-f): total free bytes depend on f, not on the block size. 64 -> 8 MiB multiplies the block count by 8 and divides the free bytes per block by 8; the sum is unchanged. So the 71-87 % (no RT) / 53-78 % (RT) figures only help if 8 MiB raises the fill fraction, and that before/after datum is missing.
Where the savings actually are:
Two risks dominate.
Minimal design: a per-pool, startup-fixed size field, Block { size }, byte-summed texture_room()/memory(), and byte budgets; textures only, staging and small pools stay at 64 MiB. Every safety predicate remains size-blind, and a later per-turn A/B becomes possible.
A run must settle: same save/camera with both sizes, comparing free bytes (MB of texture blocks free), fill, UNRIPE, BLOCKS_MADE count/ms/longest, residency refusals and device-removed reason; plus hitch p99 (the poster notes stutters are unsettled). Unproven without it: the texture-size distribution across 4-8->8 MiB and whether 8 MiB raises fill at all.
Read-only audit of the commit ramp (no game run). The short version: most of the commit is the title’s page-pool sections and is not ours to free; the layer’s largest trimmable holding is governed by VRAM, not commit.
What is commit. The title’s
XMemAllocatePhysicalPagescreates pagefile-backedSEC_RESERVEsections andcommit()maps them page-run by page-run (xmem.rs:1166-1217,2607-2617);Section::committedis set-only (848/892/921), so those pages are permanent for the run — ~35 GB target on a 32 GB PC. That explains a fall to near zero. Of the layer: host copies of title-filled textures (7.2 GB measured,findings.md:701), never-trimmed host-rendered target copies (2.8-3.1 GB), windows (LOOSE, 2.7 GB), containers+dxil (458 MB), scratch, staging/small blocks and the reaper line (4,096 things ≈ 1.0-1.3 GB private) are commit; texture blocks and BAR windows are VRAM (BAR windows are relief, not cost); the pipeline library is file-backed.The gap. Host copies are kept 600 s whenever VRAM is under 88% (
host.rs:233-248) — commit is not consulted.LEONIDA_COMMIT_FLOOR=1is the only commit-aware rule, is off by default, and measured 7.2 → 5.5 GB / +1.6 GB commit-left (findings.md:701). It also needs 2.5 s and 60 frames idle, i.e. 12 s at the 5 fps latch. So the runtime cannot reliably release before the title hits the wall; at best it lowers the ceiling and buys time.A likely second contributor:
pool::roomgives staging the samespares()limit as textures, so in the calm band staging may keep up toSPARE_KEPT= 64 empty 64 MiB blocks = 4 GiB of commit, not the 8 its own constant implies (pool.rs:55-65;STAGING_KEPTis only the initial value). Pressure drops it to 2, but pressure only starts at commit ≤ 4 GiB.The missing measurement is one line: per second,
commit left/limit, title pool committed (sum ofSection::committedbits × 4 KiB) and its delta, then the layer by category (host copies, windows, blocks, scratch, shader, reaper) and the refusal counters. The delta tells you whether the 40 s leg is ours or the title’s. For the #3434 direction,LEONIDA_DSTORAGE_LOGgives per-second unmap/map/commit counts: after the first 1455, does the title keep mapping or stop?The smallest device-free predicate for a fix is a pure
commit_aware_keep(commit_left, vram_policy) -> (idle_ms, frames, most)with boundary tests at 1536 MiB / 4 GiB, mirroringnext_pressure/critical_commit/commit_floor_times. No fix is implemented; the audit is read-only.Unproven: the category split during that specific ramp; whether WDDM charges upload/shared heaps exactly as private; the 4 GiB staging accumulation (code allows it, no run has shown it); and what the title does after a 1455/NULL map.
LEONIDA_WINDOWS_BAR_MB=0is not a commit lever — it moves ~3 GB into PC memory.