Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test) #913

Closed
opened 2026-11-26 04:36:41 +00:00 by github-bot · 5 comments
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 08:09 UTC · original

On a 12 GB card, cargo test -p xcl --lib on main now fills video memory and fails with E_OUTOFMEMORY (0x8007000E). The cause is the test #348 added, hle::d3d12x::sparse::tests::a_freed_block_is_decommitted_before_its_address_is_reused. Behind it is a sparse pool pattern a title could hit too: freeing the last tile in use retires its 64 MiB pool, and the next allocation creates a new one.

Seen (RTX 3060 12 GB, driver 32.0.16.1088, Ryzen 7 5700X, 16 GB RAM, Windows 11 26300, Rust 1.100.0 MSVC, debug, main a1672ef)

  • cargo test -p xcl --lib -- --test-threads=4: 3 of 3 runs failed. gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes panics on E_OUTOFMEMORY, then placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory fail on the poisoned lock. With --test-threads=2 and =1 it fails as well; one later run passed.
  • Peak video memory (nvidia-smi, sampled through the run, --test-threads=1):
tree peak VRAM lib tests
main a1672ef 12011–12026 MiB 4–5 failed (one run 0)
main with --skip a_freed_block_is_decommitted_before_its_address_is_reused 1652 MiB 673 passed, 0 failed
main + #532 (7f94c6f merged locally) 1652 MiB 675 passed, 0 failed
db1ddb2 (before #348) 1469 MiB 626 passed, 0 failed
  • Bisected on peak VRAM over 1-thread runs (db1ddb2 good, d208e14 bad): first bad commit ebbf377 (#348). Its parent peaks at ~1.6 GB.
  • Run alone, the test returns early (uma::get() has no sparse windows yet) and uses nothing. It only grows when earlier tests in the same process set up the sparse windows, which is why --exact runs don't show it.

Why (counted with temporary counters in take_tile / retire_free_pools, not committed)
The test allocates and frees one 64 KiB tile 2,000 times on each of 4 threads. After a free, that tile's pool is completely free, so retire_free_pools moves the 64 MiB heap to retired, where it stays for at least 2 s. The next alloc finds an empty free list and take_tile creates a new 64 MiB heap. In one run of this test: 288 pools created, up to 284 retired heaps held at once, about 18 GB asked of a 12 GB card.

The same applies outside the test: anything that frees the last tile of a pool and allocates again within 2 s gets a new 64 MiB heap each time.

Possibly relevant: #532 parks decommitted tiles in their pool instead of freeing them at once, so the pool is not all-free and not retired. With it merged, the peak is back to 1.65 GB (table above). Other ways out would be keeping one free pool instead of retiring it, or taking a tile from a pool in retired before creating a new one. Others have been skipping this test in their PR runs (e.g. #793, #794, #795, #797).

Not tested: AMD; release build; a retail title (no title here), so the effect in a game is not measured.

AI use: Claude Code (Claude Opus 5.5) ran the tests, the bisect and the counters, and wrote this issue.

**@⁠fromthemoonx** on GitHub · 2026-11-24 08:09 UTC · [original](https://github.com/xcl-dev/xcl/issues/913) On a 12 GB card, `cargo test -p xcl --lib` on `main` now fills video memory and fails with `E_OUTOFMEMORY` (0x8007000E). The cause is the test #348 added, `hle::d3d12x::sparse::tests::a_freed_block_is_decommitted_before_its_address_is_reused`. Behind it is a sparse pool pattern a title could hit too: freeing the last tile in use retires its 64 MiB pool, and the next allocation creates a new one. **Seen** (RTX 3060 12 GB, driver 32.0.16.1088, Ryzen 7 5700X, 16 GB RAM, Windows 11 26300, Rust 1.100.0 MSVC, debug, `main` `a1672ef`) - `cargo test -p xcl --lib -- --test-threads=4`: 3 of 3 runs failed. `gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes` panics on `E_OUTOFMEMORY`, then `placed_title_textures_share_vram_and_preserve_pixels`, `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory` fail on the poisoned lock. With `--test-threads=2` and `=1` it fails as well; one later run passed. - Peak video memory (`nvidia-smi`, sampled through the run, `--test-threads=1`): | tree | peak VRAM | lib tests | |---|---|---| | `main` `a1672ef` | 12011–12026 MiB | 4–5 failed (one run 0) | | `main` with `--skip a_freed_block_is_decommitted_before_its_address_is_reused` | 1652 MiB | 673 passed, 0 failed | | `main` + #532 (`7f94c6f` merged locally) | 1652 MiB | 675 passed, 0 failed | | `db1ddb2` (before #348) | 1469 MiB | 626 passed, 0 failed | - Bisected on peak VRAM over 1-thread runs (`db1ddb2` good, `d208e14` bad): first bad commit `ebbf377` (#348). Its parent peaks at ~1.6 GB. - Run alone, the test returns early (`uma::get()` has no sparse windows yet) and uses nothing. It only grows when earlier tests in the same process set up the sparse windows, which is why `--exact` runs don't show it. **Why** (counted with temporary counters in `take_tile` / `retire_free_pools`, not committed) The test allocates and frees one 64 KiB tile 2,000 times on each of 4 threads. After a `free`, that tile's pool is completely free, so `retire_free_pools` moves the 64 MiB heap to `retired`, where it stays for at least 2 s. The next `alloc` finds an empty free list and `take_tile` creates a new 64 MiB heap. In one run of this test: **288 pools created, up to 284 retired heaps held at once**, about 18 GB asked of a 12 GB card. The same applies outside the test: anything that frees the last tile of a pool and allocates again within 2 s gets a new 64 MiB heap each time. **Possibly relevant:** #532 parks decommitted tiles in their pool instead of freeing them at once, so the pool is not all-free and not retired. With it merged, the peak is back to 1.65 GB (table above). Other ways out would be keeping one free pool instead of retiring it, or taking a tile from a pool in `retired` before creating a new one. Others have been skipping this test in their PR runs (e.g. #793, #794, #795, #797). **Not tested:** AMD; release build; a retail title (no title here), so the effect in a game is not measured. AI use: Claude Code (Claude Opus 5.5) ran the tests, the bisect and the counters, and wrote this issue.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:41 +00:00
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 08:17 UTC · original

One more data point from the same machine. real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state failed in 2 of 15 cargo test -p xcl --lib -- --test-threads=4 runs on main f4ce27c, at the assert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0) after OpenExistingHeapFromAddress.

With --skip a_freed_block_is_decommitted_before_its_address_is_reused, 16 of 16 runs on main 09940bb passed completely: 674 passed, 0 failed. Neither that failure nor #718's showed up. So it looks like the same memory pressure, though I have not shown the cause directly.

AI use: Claude Code (Claude Opus 5.5) did the runs and wrote this.

**@⁠fromthemoonx** on GitHub · 2026-11-24 08:17 UTC · [original](https://github.com/xcl-dev/xcl/issues/913#issuecomment-7125958012) One more data point from the same machine. `real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state` failed in 2 of 15 `cargo test -p xcl --lib -- --test-threads=4` runs on `main` `f4ce27c`, at the `assert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0)` after `OpenExistingHeapFromAddress`. With `--skip a_freed_block_is_decommitted_before_its_address_is_reused`, 16 of 16 runs on `main` `09940bb` passed completely: 674 passed, 0 failed. Neither that failure nor #718's showed up. So it looks like the same memory pressure, though I have not shown the cause directly. AI use: Claude Code (Claude Opus 5.5) did the runs and wrote this.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 08:30 UTC · original

I'll take this one. The mechanism is clear from take_tile/retire_free_pools: a fully-free pool is moved to retired for ≥2 s, but take_tile only ever pops self.free or calls CreateHeap — it never looks at retired, so an alloc/free cycle inside the window mints a fresh 64 MiB heap every time.

Plan: in take_tile, before CreateHeap, reuse the oldest retired heap whose unmap fence value has already completed (GetCompletedValue() >= retired.value) — same placement into pools/free as a fresh heap. Heaps still inside their fence window stay retired, so the #348 decommit-before-reuse ordering is preserved. Unit test around the pool reuse if the existing sparse tests give me a seam; otherwise the suite + smoke.

**@⁠DavidM1911** on GitHub · 2026-11-24 08:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/913#issuecomment-7126211164) I'll take this one. The mechanism is clear from `take_tile`/`retire_free_pools`: a fully-free pool is moved to `retired` for ≥2 s, but `take_tile` only ever pops `self.free` or calls `CreateHeap` — it never looks at `retired`, so an alloc/free cycle inside the window mints a fresh 64 MiB heap every time. Plan: in `take_tile`, before `CreateHeap`, reuse the oldest retired heap whose unmap fence value has already completed (`GetCompletedValue() >= retired.value`) — same placement into `pools`/`free` as a fresh heap. Heaps still inside their fence window stay retired, so the #348 decommit-before-reuse ordering is preserved. Unit test around the pool reuse if the existing sparse tests give me a seam; otherwise the suite + smoke.
Author
Owner

@⁠juliptree on GitHub · 2026-11-24 09:02 UTC · original

I reproduced the pool churn in a standalone synthetic fixture on an RTX 5060 Ti, driver 616.92. The fixture creates its own D3D12 device and sparse windows, so it runs without whole-suite setup. After four allocation/free cycles, stock a1672ef failed the pool-reuse assertion in 3/3 runs. The same base with #532 at 7f94c6f passed 3/3. After each free, stock reported 0 MiB in active pools, while #532 retained one 64 MiB active pool with a parked tile.

The fixture measured active pools only. I didn’t measure retired heaps, peak VRAM, or reproduce the suite-level out-of-memory failure. A separate WARP run confirmed the explicit skip when sparse windows are unavailable. I have a local test-only patch if it would help validate the fix. AI-assisted by Codex.

**@⁠juliptree** on GitHub · 2026-11-24 09:02 UTC · [original](https://github.com/xcl-dev/xcl/issues/913#issuecomment-7126874086) I reproduced the pool churn in a standalone synthetic fixture on an RTX 5060 Ti, driver 616.92. The fixture creates its own D3D12 device and sparse windows, so it runs without whole-suite setup. After four allocation/free cycles, stock a1672ef failed the pool-reuse assertion in 3/3 runs. The same base with #532 at 7f94c6f passed 3/3. After each free, stock reported 0 MiB in active pools, while #532 retained one 64 MiB active pool with a parked tile. The fixture measured active pools only. I didn’t measure retired heaps, peak VRAM, or reproduce the suite-level out-of-memory failure. A separate WARP run confirmed the explicit skip when sparse windows are unavailable. I have a local test-only patch if it would help validate the fix. AI-assisted by Codex.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-24 09:34 UTC · original

Same experiment on the AMD/Wine rig (RX 7900 XT, 20 GB), since the issue data is NVIDIA-native only.

Result: reproduces, but order-sensitive here too:

  • During one threads=4 lib run, per-second mem_info_vram_used sampling caught the card at ~19.5 GB of 20 GB - the pool growth is real on RADV/Wine as well.
  • A solo clean rerun of the same suite peaked at ~17 MB and the offending test passes (a_freed_block_is_decommitted_before_its_address_is_reused ... ok, 8.16 s run).
  • No OOM on our rig - the 20 GB card absorbs the growth that fills a 12 GB card, so the failure mode is size-dependent, not driver-dependent.

Matches the issue's own note that growth only happens when earlier tests in the same process have set up sparse windows: on Wine lanes that precondition comes and goes with test interleaving, which is why our 28 batch lanes mostly sailed through.

Counts only.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, XCL_NETWORK=0, release profile.

AI use: Hermes agent (local Qwen-class) ran the sampling and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-24 09:34 UTC · [original](https://github.com/xcl-dev/xcl/issues/913#issuecomment-7127607130) Same experiment on the AMD/Wine rig (RX 7900 XT, 20 GB), since the issue data is NVIDIA-native only. Result: reproduces, but **order-sensitive here too**: - During one threads=4 lib run, per-second `mem_info_vram_used` sampling caught the card at **~19.5 GB of 20 GB** - the pool growth is real on RADV/Wine as well. - A solo clean rerun of the same suite peaked at ~17 MB and the offending test passes (`a_freed_block_is_decommitted_before_its_address_is_reused ... ok`, 8.16 s run). - No OOM on our rig - the 20 GB card absorbs the growth that fills a 12 GB card, so the failure mode is size-dependent, not driver-dependent. Matches the issue's own note that growth only happens when earlier tests in the same process have set up sparse windows: on Wine lanes that precondition comes and goes with test interleaving, which is why our 28 batch lanes mostly sailed through. Counts only. **Machine:** RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, `XCL_NETWORK=0`, release profile. AI use: Hermes agent (local Qwen-class) ran the sampling and drafted this; I checked it before posting.
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-24 09:42 UTC · original

A correction to my last comment. coherent_buffer_sanitizes_console_flags_and_state also fails without this issue's test. With --skip a_freed_block_is_decommitted_before_its_address_is_reused, it failed in 1 of 3 full runs of main 6bac4b4 + #953 here, at the same assert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0). The other two runs passed.

So the 16 clean runs I reported were luck. This VirtualFree failure is probably a separate flake, not this issue's memory pressure. I have not found its cause.

AI use: Claude Code (Claude Opus 5.5).

**@⁠fromthemoonx** on GitHub · 2026-11-24 09:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/913#issuecomment-7127781323) A correction to my last comment. `coherent_buffer_sanitizes_console_flags_and_state` also fails without this issue's test. With `--skip a_freed_block_is_decommitted_before_its_address_is_reused`, it failed in 1 of 3 full runs of `main` `6bac4b4` + #953 here, at the same `assert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0)`. The other two runs passed. So the 16 clean runs I reported were luck. This `VirtualFree` failure is probably a separate flake, not this issue's memory pressure. I have not found its cause. AI use: Claude Code (Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.