Files
metal2vulkan/docs
Anees Iqbal d1e9062b5f rt: blocks are ranges of 16 MiB allocations; the block-maker thread allocates only while a class's free bytes run low
The pool handed a take of up to a block length a whole pooled block and kept one ready block per
class, which the block-maker thread made again as soon as a take used it. A 16-byte Shared buffer
took the ready block, and the 16 MiB allocation that followed held the consumer's next pipeline
creation for its whole length on NVIDIA's driver.

Now each block is a range of one of its class's allocations, with its own VkBuffer:
- A take is a kept block of its length, else the first free range that fits, else the start of an
  allocation made in the call: 16 MiB, or the block's own length where that is longer. Lengths
  round up to 64 KiB (or bufferImageGranularity); a block starts at its length rounded up to a
  power of two, up to 2 MiB.
- Device::new makes one 16 MiB allocation per class. After that, the block-maker thread makes
  another only while the class's free bytes are under 8 MiB. A take never waits on it for memory.
- A take that no free range fits, while the class keeps blocks of other lengths, allocates at once.
  It also asks the block-maker thread to give those blocks' bytes back, after the consumer's hook.
  Only when its own allocation fails does it wait for those bytes, then look for a free range once
  more.
- An allocation holding no live block is idle. A class keeps its idle allocations while their
  bytes plus those of its allocations in use stay at or under the most bytes it had in use over the
  last 10 seconds, and within an eighth of its memory type's heap. Past that it frees the oldest,
  except the reserve that keeps 8 MiB free. The rule runs at takes and give-backs on an injectable
  clock; there is no timer.
- Removed: the dedicated path, fits-and-fills-half, the 256 and 128 MiB idle bounds and the 64 MiB
  Private block.
- Metrics: blocks_reused replaces dedicated_blocks_reused. New metrics: block_bytes_made, and the
  vkAllocateMemory time on the consumer's threads (count, total, longest) apart from the
  block-maker thread's.

Tests:
- Unit: rounding, base alignment, and the window and surplus rule.
- On device:
  - the first allocations, and the trigger at 8 MiB free;
  - kept blocks taken again with their number, address and mapping;
  - an allocation beside kept blocks of other lengths, with their bytes given back;
  - the failed-allocation path, at an answered maxMemoryAllocationCount;
  - idle allocations following the window down, the reserve kept;
  - a seeded 300-step stress of mixed takes and releases across both classes, each step under a
    one-minute timeout.
- Tests that took a block of 1 byte and used more of it now take what they use.
- The replay's rt counters read the new metrics.

Verified: cargo fmt; api_signatures blessed; REFUSALS.md regenerated. Clippy, the suites and the
device legs follow as potluck jobs.
2026-11-17 23:59:05 -08:00
..