vkback: free idle empty image-arena blocks back to Vulkan #195
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!195
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-195"
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?
@deuxque on GitHub · 2026-12-02 07:07 UTC · original
deuxque:pr/arena-free-empty-blocks→main· +269 −17 · 2 files · 1 commits · openProblem
The
vkbackimage arena (greenfield/vkback/src/arena.rs) allocates 256 MiB blocks andnever frees completely empty ones until shutdown. On both 8 GB and 16 GB cards, unused
256 MiB blocks remain counted in Vulkan heap usage (
heap_usage), reducing physicalheadroom for the compositor, driver allocations, and
umem::can_grow().Observed on RX 6600 8 GB (Series S,
UMEM_MEMREPORT=1ond59b4f8):arena blocks 10 (326 MB free, 0 MB of it in GTT blocks, 1 empty, largest free range 256 MB)with
vkback arena block 2560/10held indefinitely while VRAM stood over its reserve line.Change
Arena::blocksfromVec<Block>toVec<Option<Block>>so freeing an emptyblock tombstones its slot and
push_blockreuses empty slots, keeping existingPiece.0block indices inVulkanBackend::arena_ofstable.empty_since: Option<Instant>per block andlast_alloc_at: HashMap<u32, Instant>per memory type (
Arena::alloc,Arena::free,push_block_at).Arena::trim_empty(called once per present frompipewait.rsaftersource_sweep)enforcing GPU fence safety and anti-thrash rules per memory type:
b.ready <= done && b.is_empty()(Arena::freeruns only in
VulkanBackend::retirestrictly after timeline completion andvkDestroyImage).over_line()query): Frees excess empty blocks (>= 2empty, or anotherready block of the same type has
>= 128 MiBfree) after1 s, keeping 1 warm sparewhenever remaining blocks have
< 128 MiBlargest free range.<= 1 / 1 s): Frees the last empty spare onlywhen
empty_since >= 5 s,last_alloc_at(ty) >= 5 s(preventing sawtooth againstMakerpre-allocation and synchronous fresh-block waits), and that heap is over itsline (
over_line() >= 0).has_empty()skips both timeline andover_line()querieswhen no block is empty;
needs_pressure_check()avoids per-presentover_line()callson healthy cards holding 1 warm spare.
Measurements & Tests
UMEM_MEMREPORT=1):upstream/main(d59b4f8)arena blocks(end)10 (326 MB free, 1 empty, largest 256 MB)9 (70 MB free, 0 empty, largest 54 MB)VRAMusage5,392 MB5,136 MB(-256 MB)UMEM_MEMREPORTvkback arena block2,560 MB / 10(heap 1: 5,380 MB)2,304 MB / 9(heap 1: 5,124 MB)66(+0)30.0 fps/030.0 fps/0greenfield/vkback/src/arena.rs(no GPU required):tombstone_slot_keeps_other_block_indices_valid_and_reuses_slotfresh_empty_block_is_never_freed_before_readyexcess_empty_blocks_keep_one_spare_when_others_lack_half_blocklast_empty_spare_freed_only_after_idle_under_pressureper_type_isolationno_maker_sawtooth_during_active_alloc_churnpressure_probe_skipped_until_candidate_is_aged_and_throttledcargo test --manifest-path greenfield/Cargo.toml --workspace --no-fail-fast:252 passed, 6 ignored, 0 failed.
cargo clippy --manifest-path greenfield/Cargo.toml -p vkback --all-targets -- -D warnings:0 warnings.
cargo test --manifest-path greenfield/Cargo.toml -p vkback --test policy:6 passed, 0 failed (
lib.rsunchanged at 4,250 non-test lines).tools/build.sh: exit 0 (41 s warm cache).AI use
Model: Gemini 4 Neon, human-directed scope and review. Verified via isolated Linux unit,
clippy, and policy tests plus a 120 s on-card RX 6600 8 GB Series S
UMEM_MEMREPORT=1capture (37 draws/frame, without BCPack tables). Full 3D-world streaming and 16 GB
reference-card testing remain pending.
Refs #17 #103
@copilot-pull-request-reviewer[bot] on GitHub · 2026-12-02 07:07 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@vktory6 on GitHub · 2026-12-02 15:28 UTC · original
Thanks, giving empty arena blocks back is worth having (−256 MB in your run). Three things:
memory.c,vkd3d_free_memory→remove_chunk). This adds timers instead (1 s / 5 s / 128 MiB / keep one spare / probe every 1 s). Please say why we differ (the maker thread and the waits for fresh blocks are plausible reasons) and derive the rule from that, not from tuned numbers.last_alloc_at(anInstantplus a hash insert).The fence-safety argument in the SAFETY comment holds.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.