x86 macOS / Linux Vulkan, `backend/vulkan/engine/pools`.
The idle drain fires every `IDLE_DRAIN_INTERVAL_MS` (100 ms) whenever the poll
heartbeat ticks — which is *most passes* on any workload that does not saturate
the drain worker, because the heartbeat ticks whether or not the guest is
publishing. Every fired pass trimmed the image slab's empty blocks to zero,
overriding the hot release path's own `SLAB_KEEP_EMPTY` (2) churn budget between
two frames of a live animation.
The HOST_VISIBLE buffer pools were already protected from exactly this by
`SETTLED_PASSES_FOR_BUFFER_TRIM`, and their own comment states the reason: "a
live workload crosses a block boundary and back several times a minute and
re-crossing costs a whole block allocation". The DEVICE_LOCAL image slab was
trimmed from the caller, outside that gate, and so was not.
Measured on a driven macos-13 boot of the load probe's WebGL dial: **257 block
allocations against 162 idle trims of a 64 MiB block in a 25 s window**,
alternating one for one about eight times a second, where the compositing load
that saturates the drain worker read 39 in the same window. `vk_alloc_sites`
prices a `slab_block` allocation at ~1.2 ms on this host (352-288 allocs and
367-289 ms across two censuses 5.7 s apart), plus the `vkFreeMemory` that is not
timed. The sustained-animation probe churns too — 186 allocations and 155 trims
over one boot's log, and 284 on the boot of the same binary that latched 59 Hz.
The trim now runs from inside `trim_recycle_pools`, under the same settled state
as the buffer pools, through `idle_slab_trim_keep` — one policy, one call site,
so the two cannot drift apart again. `REIMS_VGPU_SLAB_RETAIN=off` restores the
old behaviour for the A/B; it narrows in the sense `env`'s module doc requires,
retaining strictly less memory and reaching no allocation the retaining arm
would not also reach.
Tests: 1871 + 82 pass, 0 failed (3 + 2 + 1 ignored: the wire fixtures, which are
gitignored on this checkout). New test
`idle_slab_trim_tests::an_unsettled_idle_pass_does_not_trim_the_image_slab`
fails without the gate — it would read `Some(0)` for both arms. Clippy clean at
`-D warnings` on all three arms including the cross-compiled Metal one.
Not verified: the frame-rate effect of the change. The A/B needs two driven
boots and the probe it was found with had to be fixed first (below). The `off`
arm of the switch is not reachable from the test suite, which shares one
`OnceLock` across every test in the binary.
Also: the load probe now jiggles the pointer between two corner pixels every
20 s. The guest's display sleeps, and a probe that only animates does not stop
it — a 145 s window read `display_vbl delivered=1607` frozen across two
censuses, every QEMU thread under 20 % of one core, and the page's leg
boundaries arriving exactly on schedule. A sleeping display reads as a device
that stopped.