Repository navigation
Memory: decommitted sparse tiles stay mapped until the next submit - #532
Conversation
A sparse window tile whose pages were all decommitted was unmapped at once (UpdateTileMappings with a NULL range, then a queue signal), and a commit there again mapped a pool tile anew. Each of these calls took about 0.12-0.15 ms in the NVIDIA driver on an RTX 4070 Ti. A retail title moves physical pages one at a time while it loads, on the thread that presents: thousands of tiles a second are decommitted and committed again, and timing probes and symbolized thread dumps put that thread in the driver under map_tiles / unmap_tiles most of the time. With presents stopped for more than 30 s the title's own stall watchdog ended it. 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. The parked tiles are unmapped together (one UpdateTileMappings per window) and their pool tiles freed (flush_parked) before the next title submit (before_execute), when the free list runs out (take_tile), or when 4096 are parked (256 MB of video memory). A commit at a parked address before that takes its pool tile back with no mapping call and queues it to be cleared (to_zero), as a reused tile is. Readers of `mapped` see a parked tile as unmapped, MAPPED_GEN changes when one is taken back, and release_if_unused does not free a pool tile that is parked. committed / decommitted keep their locking; their bodies are now State methods (commit_range / decommit_range) so the test can drive a state of its own. Assisted-by: Claude Code (Claude Opus 5.5)
|
Regression run on an AMD GPU, which Not tested lists, on the same retail title. Tested
Regression run
This PR Not tested
AI use
|
|
Test run of Tested
Review: A tile that is committed again while parked gets its contents cleared: Not tested: no retail title or regression run (I have no unpacked game), no Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
Read of
Smaller: AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine. |
|
Test report for exact PR head Tested
End-of-run memory line: Not tested
AI use
|
|
Read of
Smaller: AI use: Claude Code, Claude Sonnet 5.5, read the code at the head above; the points are mine. |
|
Merged (9aec53d). Checked on an RX 9070 (RDNA4) on main 9aec53d together with #532 and #556: |
Upstream's xcl-dev#532 (decommitted sparse tiles stay mapped until the next submit) adds State::parked; its new tests' State literals get W2's queue_rb and unlanded.
A copy back on a queue held by a Wait64 gate lands when the GPU gets there, possibly after the title decommitted pages it covers. With xcl-dev#532 such a tile is parked (still mapped) and may be committed again with the same pool tile, cleared through to_zero; the sparse queue may also unmap it (flush_parked) before the gated queue runs the copy, which then reads nothing there. copy_back only checked that the page is mapped and committed at landing, so old bytes could be written over a page committed again since. Each TileEntry now has an epoch that changes whenever a page of it is committed or decommitted; the copy remembers its tiles' epochs and lands only on tiles whose epoch is unchanged. The synchronous readback is ordered on the sparse queue and unchanged. Not run. Assisted-by: omp (Claude Opus 5.5)
A 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=4on 7f94c6f: 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).Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60, no input, release builds; main at 2997c9a (this branch's base).main:
this PR:
Not tested
AI use