Files
metal2vulkan/docs
Anees Iqbal 89483d65cb An idle device lets go of its kept empty blocks and parked objects
What: a device keeps an emptied memory block for 10 s (KEPT_EMPTY_FOR) and a
released image or buffer parked for 1 s (recycle.rs), and only let either go
at a later call of the program: a release in the block's pool, a creation
call (sweep_stale, from keep_room), or a recycler's park or take. A device
whose program stopped making resources kept them until its next creation
call, however long that took. The consumer's Iris Xe rerun showed it: after a
guest application quit, 11 empty pooled blocks, 4 empty dedicated ones and
the parked objects sat 33 s with no counter moving; the first creation call
then freed 12 at once, and 7 empty blocks still stayed, the "one pooled block
per pool" kept for good.

How: one idle-sweep thread per device (idle_sweep.rs), started by the first
creation call that may wait (Device::keep_room). A block kept empty, a block
made ahead and an object parked each say when they may go (Due::by). The
thread waits for the earliest of those moments, sweeps (recyclers first, then
Memory::sweep_kept, the creation calls' sweep without its throttle), asks
what comes due next (Recycler::due, Memory::sweep_due) and waits again, with
no timeout when nothing is due. It sweeps at most once a second. It holds the
memory, the two recyclers (now Arc'd), the functions and the counts, never
the device. Its Vulkan calls run in an exit-guard section, and the teardown
stops and joins it before the parked objects and the memory go. Freed blocks
are posted to the free thread, which paces them as before.

The pool's last empty block now stays only in the pools the runtime keeps
room in for its own encodings' and commits' resources (Memory::keeps_room:
the kept list, not a small heap's). That block is the room the next creation
call's keep_room would make again. Every other pool keeps none past the 10 s.
So the lasting spare is bounded at one block per kept pool and counted in
WorkCounts::empty_memory_blocks_live. docs/FAST-PATHS.md's row says so and no
longer claims "held until 10 s after the dip" for blocks that stayed for good.

Verified: tests::idle_sweep (lavapipe, ms01). Private buffers and textures
over several blocks are used by a command buffer that completes, one refused
at commit (abandoned encoder) and one its submission check fails, then all
are released and the device idles. Before this change (b11d8115f1, job
m3-max-20498) it failed after 40 s idle: 32 images and 3 buffers parked,
8 pooled blocks live against 1 at the start, 512 MiB in the heap against
64 MiB. The unit test a_pool_without_room_lets_its_last_kept_block_go covers
stale/stale_at with and without room. The after-run is in the report.
2026-11-12 04:24:52 -08:00
..