Repository navigation
gpu/pool/small: release pool mutex during CreateHeap block growth (D3D12-POOL-SMALL-GROW-UNLOCKED) - #2857
Conversation
|
Verified on Windows: the crate is green with it, and it adds two tests - measured against
Why one thread: this crate's tests interfere with each other when they share a process - sixteen runs with the default threads failed twice and eight with And that is the interesting part of this change for that flake: What I could not test: the latency it is for. The best I can say is that the tests that do use the pool still pass, and the crate has a AI-assisted: yes - DeepSeek v4.1 (flash), one 37-second serial run. Written with an AI assistant. |
|
Independent check of The new pool cases use a stub allocator. The surrounding test selection ran on AMD Raphael (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4). Driver allocation latency was outside this run. AI-assisted with OpenAI Codex. |
|
RUN (native Windows 10 + RTX 5070 verification; #2857, #2860, and #2862 merged cleanly together onto
GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver AI-assisted: Antigravity |
|
Verified by MoonEyes (another person than the author) on head In-game run with the six others of a batch on AI-assisted (Claude Code). |
|
I followed up on the mock allocator test with a real D3D12 heap handoff check at 2451b47 + 0ff8a53. On Radeon Raphael (RADV 26.3.1) and RTX 4070 SUPER (620.73.04), Win64 under Wine 11.22, I filled a real 64 MiB upload block with sixteen 4 MiB pieces. The growth thread made a second block through production block(), then waited inside make() before publishing the new block. A second worker reused the exact returned piece and its original heap while growth was still parked. The new block was distinct, and the stock GPU copy/reuse test and the rest of the small-pool selection passed (6/6 including the local fixture on each GPU). As a negative control I moved the pool lock back around make(). On RADV the same fixture timed out waiting for the returned piece before growth was released. The controlled pause is after the real driver allocation, so this checks lock scope and reuse during growth, without measuring natural driver latency. MEASURED with offscreen synthetic allocations. AI-assisted (Codex). |
KelboLive
left a comment
There was a problem hiding this comment.
Approved (non-blocking). The lock scope is exactly as claimed: small.rs:118 takes from free memory without grow, the miss path takes grow (:123), re-checks (:124), runs make() with only grow held (:129), then re-adds under pool (:130-137). Because pool is declared after _grow, the block is published before a waiter can acquire grow, so the double-check cannot duplicate a 64 MiB heap. returned() keeps the back→pool order and room() only try_locks pool, so there is no inversion; the failure arm mirrors Pool::grow's 500 ms backoff (:139-141).
Both new tests are meaningful, not just existence checks: holding the pool guard across make() makes growth_unlocks_the_pool_and_concurrent_misses_share_one_block fail at its try_lock assertion (small.rs:412) — I verified that locally. pool::small is 5/5, ten consecutive growth runs are green, and the merged tree with current main builds and passes.
Two optional consistency follow-ups: Small has no LEONIDA_POOL_GROW_UNLOCKED=0-style switch back to under-lock growth, unlike pool.rs, and grow.lock() waits are not counted in the diagnostics LOCK_WAITS that pool.rs::lock() feeds.
Not independently verified here: the 300 s in-game run and the claimed latency win (no game data), and the Wine/VKD3D driver timings. Unit and device tests only. Merge is clean; 383 commits behind, but both small.rs and pool.rs are byte-identical upstream.
|
In-game RUN of head 2451b47, merged with #2852 (c4e286f) onto main 1abef08 (tree 32b6b8c23). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11, -SeriesS -NoDlss -NoFrameGen.
|
|
Merging (added to the merge queue). Head 2451b47 merges cleanly with main 913b88b; since my test main gained only #2973, #2858, #2882, #2788, #2876 and #2884, none of which touches this pull request's file. Claim: D3D12-POOL-SMALL-GROW-UNLOCKED (coordination issue #2570). Red/green: merzleckeier (real 64 MiB D3D12 heap handoff under Wine on RADV and RTX 4070 SUPER), KelboLive review on this head (lock scope checked line by line), MoonEyes, fiestorra and lixonik earlier. I ran: #2857 and #2852 together on main 1abef08, leonida-gpu 647 passed / 0 failed, and a 900 s warm in-game run on an RTX 4070 Laptop (621.40): 0 device lost, private memory flat at 24.0-24.3 GB (details in my RUN comment above). CI: green on head and main; the queue runs the full CI before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR. |
|
Independent native Windows 11 + RTX 3090 verification (
AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra build, unit tests, and serialized RTX 3090 gate execution). |
VERIFY-2857 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game filesVerdict: PASS. The pool no longer holds its lock across the driver's heap creation, the new test checks exactly that, and nothing that passed before fails now. One test failed once in a full run; it fails on the base at the same rate, so it is not this pull request's doing. Head 1. What it changesThe small-buffer pool kept its mutex across fn take_with<B: Clone>(pool: &Mutex<Pool<B>>, back: &Mutex<Vec<Piece>>, grow: &Mutex<()>,
len: u64, make: impl FnOnce() -> Option<B>) -> Option<(Piece, B, bool)> {
match returned(pool, back).take_or_need(len, ALIGN, now(), Ripe::ALL) { ... }
let _grow = grow.lock().unwrap_or_else(|e| e.into_inner());
// … check again: the previous grower may have supplied enough memory for both requests
match returned(pool, back).take_or_need(len, ALIGN, now(), Ripe::ALL) { ... }
let memory = make(); // the driver's CreateHeap, without the pool lock
...
}The second lookup is what keeps two concurrent misses from each creating a block: the second one finds the first one's block. 2. The new test checks the property that matterslet grower = scope.spawn(|| {
take_with(&pool, &back, &grow, ALIGN, || {
assert!(pool.try_lock().is_ok(), "heap creation must not own the pool lock");
...The test parks a growing worker inside 3. What the tests do here
The red side (the merge base with only this pull request's tests) does not compile — the new test calls
4. The one failure I saw, and why it is not this pull request
The base fails it at the same rate, so I do not attribute it to the pull request. It is one of the 5. What I did not check
AI-assisted: MiniMax M3.1 Flash. |
Claimed in the coordination issue as:
D3D12-POOL-SMALL-GROW-UNLOCKED(claim comment)What and why
Release the
Smallbuffer pool mutex (Small::pool) while creating and making resident a new 64 MiBID3D12Heapblock ind3d12/crates/leonida-gpu/src/pool/small.rs— direct companion to merged PR#2693(D3D12-POOL-GROW-UNLOCKED, which unlocked growth for texture and staging pools inpool.rsbut leftpool/small.rsholdingsmall.pool()acrossblock(device, kind)).grow: Mutex<()>toSmalland extractstake_with, reusingsuper::Pool::take_or_need,super::Pool::add, andsuper::Pool::growth_failedfrompool.rs:backand callstake_or_need(..., Ripe::ALL)without takinggrow, so threads taking free/returned pieces never wait behind a concurrentCreateHeap/MakeResident.grow, double-checktake_or_need(so concurrent misses share a single newly created block and respect failed-growth backoff), drop thepoolmutex, invokemake(), and then re-acquirepoolto add the new block (or recordgrowth_failed).KEPT = 2unchanged (zero VRAM/retention policy change).d3d12/crates/leonida-gpu/src/pool/small.rs+pool.rs#2693) + race-free deterministic multi-threaded unit tests verified red→green under Wine + MEASURED 300 s in-game gate on exact PR head2451b4744.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/pool/small.rs→ exit 0.cargo check --locked --target x86_64-pc-windows-msvc -p leonida-gpu --features diagnostics→ 0 errors, 0 warnings inpool/small.rs.leonida-gputest binary (x86_64-pc-windows-msvc) and ran under Wine:origin/main(testingorigin/main's lockedpool.takewithassert!(pool.try_lock().is_ok(), "heap creation must not own the pool lock")):2451b4744(rebased ontocd73ddab7):pool::small::tests:5 passed; 0 failed; 0 ignored(includinggrowth_unlocks_the_pool_and_concurrent_misses_share_one_block, verified 10/10 consecutive runs).pool::tests:14 passed; 0 failed; 0 ignored.docs/game_gate.md) on exact PR head2451b4744(leonida.exe--profile play --features mimalloc,dlss,diagnostics, Series S + DLSS Quality 1280×720 → 1920×1080):310.04 s(world_at_s = 77.49 s,>= 300 srequired)world + 60 sto stop):3,108presented frames (3,206total world presents),15.20median FPS,115.53 msp95 frame time (15.53end-window median FPS,4,372median draws/frame)3.884 s(<= 10.0 srequired)6,717 MiB(<= 7,400 MiBguard)0device losses,0crashes/faults,0panics,0kernelNVRM: XiderrorsGPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (authored by Gemini 4 Neon; audited and approved in a separate independent review pass by Gemini 4 Neon).
Checklist
main(cd73ddab7) and merges cleanly.check_no_game_data.pyclean).docs/design.md(n/a — GPU small-buffer pool locking change).2451b4744).