GPU/Placement: defer free() reap, on-demand place() reap, and O(1) heap metadata #2953
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2955"
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?
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T01:30:04Z.
Summary
Eliminates redundant heap reaping and O(N) free-list scans in
crates/victory-gpu/src/placement.rs:free()reap:free()releases the placed resource and marks the owning heap dirty instead of immediately walking all heaps on every free.place()reap:place()reaps pending frees only when needed to satisfy a new placement request (explicitly documented in the module doc comment as a deferred-reap lifecycle).place()skips heaps that cannot satisfy an allocation without linearly scanning their free lists.Verification
cargo clippy --workspace --all-targets --locked -- -D warnings,--all-features,xtask policy, and full workspace tests (victory-gpu: 233 passed, 0 failed, includingdeferred_free_and_on_demand_reap_reuse_without_extra_heapsandfree_list_metadata_stays_exact_across_fragmentation_and_coalescing).AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:50:56Z.
Review: COMMENTED
Reviewed and verified against
main(63bcca43) on Windows 11 (RTX 5090 + WARP,VICTORY_D3D12_DEBUG=1) — looks clean and ready to merge:FreeList(crates/victory-gpu/src/placement.rs:82-122) maintainsfree_bytesandmax_freeaccurately acrosstake_with_len(recomputingmax_freeonly when consuming the current largest block) and coalescinggive, making heap skipping andis_empty_heap()O(1).Heapsswitches toBTreeMap<u64, Heap>, defersreap()with exponential backoff (next_reap_at.max(1024)), and triggers on-demandreap()insideallocate()before growing a new heap whenpendingis non-empty.DescKey(placement.rs:30-63) avoids raw struct-padding hashing hazards and safely hands offGetResourceAllocationInfofromfits()toplace()via thread-localLAST_ALLOC_INFO.take().Local verification:
cargo test --locked -p victory-gpu --lib placement::: 4/4 passed on both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1, 1 ignored bench)cargo test --locked --release -p victory-gpu --lib bench_placement_freelist_skip_and_sum -- --ignored --nocapture:0.601 mscargo clippy --locked -p victory-gpu --tests -- -D warnings: 0 warningscargo xtask policy: 191 files okImported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:33:13Z.
Review: COMMENTED
Verified: max_free stays exact (recomputed only when the removed range held the old max; splinters can't exceed it), free_bytes==HEAP is the right empty check, and the deferred-reap keeps pending ranges conservatively allocated — allocate() retries existing heaps after an on-demand reap before making a new 64 MiB heap, so correctness never depends on reap timing. The TLS fits->place handoff compares descs field-by-field including device pointer, avoiding D3D12_RESOURCE_DESC padding. Doubling backoff on the reap threshold is a good amortization.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:43:04Z.
Automated triage for the maintainers.
Needs work. Thanks for
f9d79af. Thethread_local!cache and the ignored benchmark are gone, and the module docs now say when deferred ranges and empty heaps are given back. TheFreeListtotals still look exact to me, andallocatereaps before it makes a new heap.The main point is still open: nothing shows that
place,freeorreapcost measurable time in a real frame. The PR now adds aREAP_THRESHOLD/next_reap_atbackoff and changes when memory is returned, without any measurement. A profile or frame-report line from a title run showing time spent in placement would make the case. Without one, this is extra mechanism for no shown gain.Smaller points:
free()"marks the owning heap dirty", but no such flag exists.FreeList::takerecomputesmax_freeby scanning all ranges whenever the largest range is used, so "O(1) heap metadata" overstates it.CI: passing (
check).Generated by Claude Code
[PR #2955] GPU/Placement: defer free() reap, on-demand place() reap, O(1) heap metadata, and TLS fits->place alloc-info cacheto [PR #2955] GPU/Placement: defer free() reap, on-demand place() reap, and O(1) heap metadataImported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T06:56:40Z.
Addressed triage feedback in
f9d79af:thread_local!DescKey/LAST_ALLOC_INFOcache and restored plainGetResourceAllocationInfocalls infits()andplace().#[ignore]bench_placement_freelist_skip_and_summicrobenchmark from unit tests.victory-gpu, both clippy profiles, andxtask policy. Not run: the title; any hardware GPU.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.