Memory: decommitted sparse tiles stay mapped until the next submit #532
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!532
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/532/head"
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?
@Vaximous on GitHub · 2026-11-24 01:28 UTC · original
Vaximous:sparse-park-decommitted-tiles→main· +231 −42 · 1 files · 1 commits · merged 2026-11-24 09:43 UTCA sparse window tile whose pages are all decommitted was unmapped at once (
UpdateTileMappingswith a NULL range, then a queue signal), and a commit at the same address mapped a pool tile again. Each of these calls took 0.12–0.15 ms in the NVIDIA driver here.The retail title moves physical pages one at a time while it loads after its menus (
MapTitlePhysicalPages, one page a call, on the thread that presents): thousands of tiles a second are decommitted and committed again. Timing probes in that phase: about 1,400 calls a second at ~0.68 ms each, 96% of that thread's time; symbolized thread dumps put it innvwgf2umx→D3D12Coreundersparse::State::map_tiles/unmap_tiles. When presents stop for more than about 30 s the title's own stall watchdog ends it (#232).A tile that goes is now parked: it stays mapped in its window and keeps its pool tile, and nothing is sent to the GPU. Parked tiles are unmapped together, one
UpdateTileMappingsper window, and their pool tiles freed (flush_parked):before_execute, before anything is uploaded), so title work never sees a decommitted tile mapped;take_tileflushes before it creates a new pool or fails, and then does not retire the pools it just freed);A commit at a parked address before that takes its pool tile back with no mapping call and queues the whole tile to be cleared (
to_zero), as a reused tile is.Who else reads tile mappings:
mappedno longer holds a parked tile, soreadback_ranges,before_execute's dirty scan,sync_sent_rangeandto_zero(pruned to mapped tiles bydecommit_tiles) skip it, as they did when it was unmapped.mapped_ranges/runs(title texture uploads) drop it:runsis reset andMAPPED_GENbumped on park, and again when a parked tile is taken back, which maps nothing new.release_if_unused(a placed buffer released) does not free a parked pool tile;flush_parkeddoes not free a pinned one, as the unmap did not.retire_free_poolsdoes not count parked tiles as free, so their pool stays.pool_bytes(XCL_ACTIVITY) counts them as in use.freeand the decommit paths in kernelx andplaceholdersall go throughdecommitted.initdrops its parked tiles with its pools.One case behaves differently: a tile a placed buffer pins, decommitted and committed again before the next submit, is mapped back to the same pool tile (and cleared) instead of to a new one.
committed/decommittedkeep their locking; their bodies moved intoState::commit_range/decommit_rangeso that the test can drive a state of its own.Overlaps: #236 (open) moves the
VirtualAlloc/VirtualFreeof sparse commits under the sparse lock and restructures the same functions; the two would need a rebase against each other but do not do the same thing. #262 is about CPU-write uploads beside the title queue; this does not change when or how those uploads run. #254 speeds upcommitted_page'sVirtualQuery, not this path. A second PR,kernelx: a page moving between addresses is copied there, not via home, removes the home's two tile mappings per moved page. The two do not depend on each other, and together they bring the pause down the most.What it does not achieve: the title still does not reach gameplay. With both PRs on a local tree it gets through the pause and keeps loading, but its memory keeps growing (peak commit 44 GB at 300 s, still rising; local video memory 19.4 GB on a 12 GB card). Memory growth, as in #248, is the next stop; that tree carries an earlier form of #288.
What is in it
Memory: decommitted sparse tiles stay mapped until the next submit(crates/xcl/src/hle/d3d12x/sparse.rs):State::parked,PARKED_MAX,flush_parkedand its calls inbefore_execute,take_tileand the decommit path; taking a parked tile back inensure_mapped; therelease_if_unusedcheck; and the testa_tile_decommitted_and_committed_again_keeps_its_video_memory. The test checks:release_if_unused;MAPPED_GEN;It does not compile on main. With taking back disabled it fails.
Tested
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on7f94c6f: 677 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.XCL_PRESS_A_AT=14,17,21,40,60,66,72, 150 s runs. The loading pause is measured as the longest stretch with 0 presents (XCL_ACTIVITYlines, 2 s windows).2997c9a), back to back, two runs each: neither main nor this branch reaches the phase within 150 s. In all four runs the title spends about 110 s at 7–9 presents per 2 s with no DirectStorage requests (an intro / logo screen), then loads at up to 60 presents per 2 s; longest gap with 0 presents 2 s and 2 s (main), 2 s and 4 s (this branch); 22,701–23,918 DirectStorage requests; frames 1,024 and 1,104 (main), 1,062 and 1,122 (this branch); no crash; peak commit 16.4–16.6 GB.Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60, no input, release builds; main at2997c9a(this branch's base).main:
this PR:
Not tested
AI use
@vibryxcx on GitHub · 2026-11-24 02:00 UTC · original
Regression run on an AMD GPU, which Not tested lists, on the same retail title.
Tested
cargo clean --release -p xclbefore each build.7f94c6fas it is, against its base,main2997c9a. No uncommitted changes.scripts/smoke.ps1 -Game <folder> -Seconds 60, no input. Menu run with the presses from the description,XCL_PRESS_A_AT=14,17,21,40,60,66,72,-Seconds 180.2997c9a7f94c6fRegression run
main2997c9a:This PR
7f94c6f:Not tested
2997c9a, neither build reaches the loading phase within 180 s here (same DirectStorage request count, both end in the menus at 3 presents per 2 s). So this is a regression check on AMD, not a check of the fix.AI use
@MesshM on GitHub · 2026-11-24 03:04 UTC · original
Test run of
7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5on AMD RDNA4. I merged it onto currentmaindd2ae9alocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 691 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 651 passed, 0 failed, 21 ignoredSKIPPED; thesparseandumatests pass.Review: A tile that is committed again while parked gets its contents cleared:
decommit_rangepasses&mut self.to_zerotodecommit_tiles, so the tile is queued for zeroing when it is parked, before it can be taken back, which is what the comment at the unpark says. The flushes beforebefore_executeand when the free list runs out keep title work from seeing a decommitted tile mapped. I found nothing to change; this adds an RDNA4 suite run to the RDNA2 regression run above.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@iggyvilla on GitHub · 2026-11-24 07:53 UTC · original
Read of
7f94c6f(nothing built or run by me); the parked-tile state machine and the take-back path look consistent to me. One statement in the description is not what the code does: "That bounds the video memory parked tiles hold to 256 MB beyond what is committed."PARKED_MAXis checked once perdecommit_range, after every tile of the range has been parked (sparse.rs:1346-1348). A single decommit of a large range (the title releasing a whole reservation, orsparse::freeof a multi-GiB block, which callsdecommitted(start, len)) therefore parks all the tiles it removes before the flush, so the peak is what the range had mapped, not 256 MB; the bound holds between calls. Flushing inside the loop whenparked.len()reaches the limit would make the sentence true, or the sentence could say "between calls".Smaller:
take_tileflushes when the free list is empty (:579-582) but does not callretire_free_poolsafterwards, so a pool freed that way stays allocated until the next flush fromdecommit_rangeorbefore_execute, wheremainretired on everydecommitted. If that is intended, a line in the comment would say so.AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.
@zondy1i on GitHub · 2026-11-24 08:29 UTC · original
Test report for exact PR head
7f94c6f5f0c93b3b369c22e4f5d647fd434f0eb5on an 8 GB NVIDIA card (Ampere, wave32).Tested
x86_64-pc-windows-msvc), debug (tests) + release (smoke).cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (2 SKIPPED GPU tests:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64)).nvidia-smiduring the full test run: 3143 MiB (noE_OUTOFMEMORY).XCL_NETWORK=0,XCL_ACTIVITY=1, folder name redacted toretail-title):End-of-run memory line:
video memory 6143 MB local, 4620 MB non-local; target pages 3579 MB (pools 3584 MB); arenas 465 MB in use, 465 MB made; sparse pools 896 MB (837 MB mapped).Not tested
main(tested exact PR head7f94c6fonly).AI use
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175@iggyvilla on GitHub · 2026-11-24 09:31 UTC · original
Read of
7f94c6f(nothing built or run by me); the parked-tile state machine and the take-back path look consistent to me. One statement in the description is not what the code does: "That bounds the video memory parked tiles hold to 256 MB beyond what is committed."PARKED_MAXis checked once perdecommit_range, after every tile of the range has been parked (sparse.rs:1346-1348). A single decommit of a large range (the title releasing a whole reservation, orsparse::freeof a multi-GiB block, which callsdecommitted(start, len)) therefore parks all the tiles it removes before the flush, so the peak is what the range had mapped, not 256 MB; the bound holds between calls. Flushing inside the loop whenparked.len()reaches the limit would make the sentence true, or the sentence could say "between calls".Smaller:
take_tileflushes when the free list is empty (:579-582) but does not callretire_free_poolsafterwards, so a pool freed that way stays allocated until the next flush fromdecommit_rangeorbefore_execute, wheremainretired on everydecommitted. If that is intended, a line in the comment would say so.AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine.
@ivall on GitHub · 2026-11-24 09:43 UTC · original
Merged (
9aec53d). Checked on an RX 9070 (RDNA4) on main9aec53dtogether with #532 and #556:cargo test --workspace -- --test-threads=4- 683 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps as before and starts loading the world. The merge neededparkedin the test-onlyStatefrom #923. iggyvilla's two points stand and are worth a follow-up: the 256 MB bound holds between calls, not within one largedecommit_range, and a flush fromtake_tiledoes not retire the pools it frees.mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175