Repository navigation
D3D12.X: XCL_ALLOC_TRIM_MB releases grown PC command allocators - #3612
Draft
ArtuArtaza wants to merge 2 commits into
Draft
ArtuArtaza wants to merge 2 commits into
ArtuArtaza wants to merge 2 commits into
Conversation
alloc_release dropped what XCL keeps by a command allocator's address (the pool's namespace and type, the dispatch chain's and list_x's state) after the Release that frees the object. In between, the driver can give that address to an allocator another thread creates, and the cleanup then ran on the new one: alloc_pool::forget took its type and stand-ins, and marked one that already held a recording for release by the pool. For an allocator nothing uses, the cleanup now runs while the hook still holds its probe reference, before the Release that frees it. One the pool keeps for the GPU, and a Release that did not see the last reference, are cleaned up after it as before. sage-sage's xcl-dev#2701 proposed this order for heaps, queues and allocators; the allocator part is not on main. Measured on main b2b1f10 (RX 6700 XT, driver 32.0.21045.29003) with a GPU test that creates allocators between the Release and the cleanup until one comes back at the freed address: it failed 5 of 5 runs there and passed 5 of 5 with this order. That test needs a hook in alloc_release and is not part of this commit. Assisted-by: Claude Code (Claude Fable 5.2)
amdxc64 keeps a command allocator's memory over its Reset: on an RX 6700 XT (driver 32.0.21045.29003) 20 allocators with 100,000 copies each held 60.6 MB of non-local memory, as much after their Reset, and 0.6 MB a few seconds after their Release. The pool resets and keeps its PC allocators, so each stays as large as the largest recording it ever held. In a retail title's world that memory grew by about 60 MB a frame until the device was removed at 5.6-5.8 GB. With XCL_ALLOC_TRIM_MB=<n>, once the process holds more than n MB of non-local memory besides the coherent windows, the idle PC allocators put aside are released instead of kept, and the title's Reset of an allocator nothing uses goes on with a new PC allocator when the one in use was recorded on. Off by default: the first recording on a new allocator took 1.1 ms on that driver, a recording after a Reset about 1 us, and the title's world went through about 75 new ones a frame. Measured with the limit at 1024 MB on main d0832e6 + xcl-dev#3455 + xcl-dev#3473 (this card needs both to reach the world), 3 runs each, 60 s into the world: commit 29.1 -> 26.7 GB, working set 20.3 -> 17.9 GB, shared GPU memory 8.8 -> 6.5 GB, growth 59-63 -> 19-25 MB a frame. The device was removed in 7 of 9 world runs without it and in none of 20 with it. iggyvilla found the leak (xcl-dev#3110: amdxc64 keeps memory per command list and per allocator), and Simon-CR's xcl-dev#2138 releases idle put-aside allocators. This builds on the reset of idle ones that is in main (31930d8, bmjask; Saksukella's xcl-dev#2707 proposed the same). Assisted-by: Claude Code (Claude Fable 5.2)
5 tasks
Contributor
|
Review (head ffc43a2, diff read, not a merge-check; draft):
Fine: opt-in (unset costs one AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #3611; only the top commit belongs here.
amdxc64 keeps a command allocator's memory over its
Reset, so each PC allocator the pool keeps stays as large as the largest recording it ever held. On an RX 6700 XT, in the retail title's world, that memory (system RAM, Windows' "shared GPU memory") grew by about 60 MB a frame until the device was removed at 5.6–5.8 GB. WithXCL_ALLOC_TRIM_MB=<n>, once the process holds more thannMB of non-local video memory besides the coherent windows, idle PC allocators are released and a titleResetgoes on with a new one. It is off by default because of its cost (below).Credit: @iggyvilla found this leak (#3110: amdxc64 keeps memory per command list and per allocator), and @Simon-CR's #2138 (open) releases idle put-aside allocators. This builds on the reset of idle ones that is in
main(31930d8 by @bmjask; @Saksukella's #2707 proposed the same). New here: on this driver aResetdoes not give the memory back, onlyReleasedoes, so the allocator in use is replaced too.What is in it
crates/xcl/src/hle/d3d12x/alloc_pool.rs: the switch (trim_limit,trimming: DXGI is asked at most every 250 ms);take_idle_spares/release_idle_sparesrelease the put-aside PC allocators nothing uses, never the title's own or the one in use; intitle_reseta free allocator that was recorded on is replaced by a new one (ResetWork::Create { replace }). Unit tests of the switch, of which spares go, and of the replacement's bookkeeping.README.md: the switch.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on ffc43a2: 2903 passed, 6 failed, 51 ignored. The 6 are 5 tests (the two-pass cache e2e test runs itself as a child and prints two results), the same 5 that fail onmain6bfb5c5 on this card (2899 passed, 6 failed, 51 ignored):gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form,f32_programs_on_the_gpu,gpu_f32_compares_with_nan,gpu_float_compares_random,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs. None is in the code this PR touches.cargo test -p xcl --lib alloc_pool -- --test-threads=4, 30 times: no run with a failure.Reset, and 0.6 MB a few seconds afterRelease.XCL_TEXTURE_LEVEL_PAGES=1, no prepared shaders), limit 1024 MB, 3 runs each, 60 s after entering the world, mean (lowest–highest):amdxc64.dll+0x790849, a separate problem).Reset1 µs (empty) to 83 µs (4,000 commands). The world went through 70–78 allocators a frame while trimming, so about 80 ms of CPU a frame. Those runs showed 0.3–1 frames a second, where that is small; at 30 frames a second it would not fit.XCL_ALLOC_TRIM_MB=1(trimming from the start, on the title's first screens at 60 frames a second): 1466 frames shown, exit 0x0, no device removal, no crash, peak commit 12738 MB; 1024 idle PC allocators were released and 1239 resets went on with a new one in the 60 s.Regression run
main:
PR:
Not tested
mainends at the first world load on this card (Recompiler: a pixel shader's carry ballot reads its quad lane by lane, not through quadOp #3455). The world numbers are frommaind0832e6 + Recompiler: a pixel shader's carry ballot reads its quad lane by lane, not through quadOp #3455 + Recompiler: compact literal indices are read from one table word on AMD #3473 with this change (before it was rebased), and a local switch that leaves one mesh pipeline unbuilt.submit_marking_calls_out_unlocked_and_revalidates_the_queue_markerit made that test fail in 5 of 30 runs (itsSTATE.try_lockchecks, Tests: alloc_pool checks for STATE held by the caller, not by a parallel test #3190). I can add it once Tests: alloc_pool checks for STATE held by the caller, not by a parallel test #3190 is in.AI use