From 91fed9449cf77b1badc8bcac9563a35a68932b06 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 09:00:35 -0800 Subject: [PATCH] rt: the pipeline cache holds up to 128 MiB, so one guest's set on the Mac host's driver fits What: PIPELINE_CACHE_BOUND goes from 32 MiB to 128 MiB, on every host. Nothing else about the cache changes: a cache past the bound when the reaper looks is still replaced by an empty one, the blob is the same single file per kind of device (at most four), written whole, and the counters are the same. Why: the owner's word, "Re 179, I'll take the 128mb cache". On KosmicKrisp (the Mac host's driver) a pipeline's cache data is about 140 KB against 3-25 KB on NVIDIA's, RADV's and ANV's drivers. One long recorded session's 448 pipelines write 62.6 MB there (m3-max-67847), and a guest boot's set reached 32.3 MB, so at 32 MiB the cache was replaced and a later launch made those pipelines again. With the bound at 32 MiB, re-making the 448 in one process took 1,669-2,370 ms after a replacement (m3-max-67741, m3-max-67789), against 80.4-81.0 ms with none (m3-max-67847). The cost, now stated in the runtime README: the blobs take up to 512 MiB of disk (four kinds of device at 128 MiB). On KosmicKrisp a full cache's seed holds about twice its data in host memory from device start: seeding from a 59.6 MiB blob raised the footprint by 119.3 MiB before any make (m3-max-67977), so about 256 MiB is expected at the bound there. Each write is the whole blob: a cold run with the bound lifted wrote 9 times, 271.9 MB, for a 62.6 MB blob (m3-max-68006). Docs: the bound's doc in cache.rs; DeviceOptions::pipeline_cache_dir and pipeline_cache_cap; Metrics::pipeline_caches_replaced and pipeline_cache_writes_skipped; Gauges::pipeline_cache_bytes; the runtime README's pipeline cache paragraph and its known gap for KosmicKrisp, reworded to 128 MiB with the measured pairs at 32 MiB kept. Test: the replacement test (tests/translate.rs) sets the bound to one byte under the cache's own size with Caches::set_bound, so it passes the bound whatever the constant is, and then restores PIPELINE_CACHE_BOUND. It needs no 128 MiB of pipelines and is unchanged. Verified: fmt, the refusal surface and the signatures table locally. The dev checks and an Iris states-only play (caches replaced and blob bytes) follow on development. --- crates/metal2vulkan-runtime/README.md | 43 +++++++++++++-------- crates/metal2vulkan-runtime/src/cache.rs | 7 ++-- crates/metal2vulkan-runtime/src/counters.rs | 6 +-- crates/metal2vulkan-runtime/src/device.rs | 4 +- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 83bfca407..0769da2e6 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2788,7 +2788,7 @@ the lowerings from one device to the next: comes before it waits for (microseconds). Then, off every guest thread, it reads the blob, makes a cache from it and makes that the cache creations take; the empty one is destroyed once no creation holds it. So no creation waits for the blob's read or the driver's parse of it, which for a blob -near 32 MiB take tens of milliseconds: a creation meanwhile goes through the empty cache +of 32 MiB take tens of milliseconds: a creation meanwhile goes through the empty cache (`Metrics::creations_before_seed` counts them), and what those compiled is not in this run's blob: a later run compiles those pipelines again, once. A blob that does not check, whose data does not begin with the device's pipeline cache header (whole, the `pipelineCacheUUID` a new driver version @@ -2808,13 +2808,20 @@ look alone (`Metrics::pipeline_cache_lock_waits` counts those waits, The device's drop writes the blob once more where the size changed at all. A crash between writes loses only the pipelines made since the last; no creation waits for a write. -The cache holds at most 32 MiB when the reaper looks (about five times the 6.25 MB of pipeline data -a long recorded session made): one past it is replaced by a fresh, empty cache that creations take -from then on, and is destroyed once no creation holds it, each replacement counted in -`Metrics::pipeline_caches_replaced`. The next write replaces the blob with the fresh cache's data, -so the blob holds at most 32 MiB too, with no second file and no generations. A write of data past -32 MiB, the teardown's of a cache that grew past it after the reaper's last look, is skipped and -counted in `Metrics::pipeline_cache_writes_skipped`; the blob keeps what it held. +The cache holds at most 128 MiB when the reaper looks: one long recorded session's 448 pipelines +write 62.6 MB of data on KosmicKrisp (the Mac host's driver) and 1.5-11.1 MB on NVIDIA's, RADV's +and ANV's drivers (m3-max-67847, 67727, 67726, 67729). One past it is replaced by a fresh, empty +cache that creations take from then on, and is destroyed once no creation holds it, each +replacement counted in `Metrics::pipeline_caches_replaced`. The next write replaces the blob with +the fresh cache's data, so the blob holds at most 128 MiB too, with no second file and no +generations; a directory keeps at most four blobs, one per kind of device or driver version, so +the blobs take at most 512 MiB of disk. A write of data past 128 MiB, the teardown's of a cache +that grew past it after the reaper's last look, is skipped and counted in +`Metrics::pipeline_cache_writes_skipped`; the blob keeps what it held. Each write is the whole +blob: a cold run with the bound lifted on KosmicKrisp wrote its blob 9 times, 271.9 MB in all, for +a 62.6 MB blob (m3-max-68006). A full cache costs host memory from device start: on KosmicKrisp, +seeding from a 59.6 MiB blob raised the process's footprint by 119.3 MiB before any make, about +twice the blob (m3-max-67977), so a cache at the bound is expected to hold about 256 MiB there. `Gauges::pipeline_cache_bytes` is the cache's size at the reaper's last look, and is zero once the device is torn down. With no directory the cache is the same, made empty, and nothing is written. @@ -2960,15 +2967,17 @@ cache is answered compile-required on both. ### Known gaps of pipeline states -- One large app's pipelines can pass the pipeline cache's 32 MiB on KosmicKrisp (the Mac host's - driver), whose blob takes about 140 KB a pipeline against 3-25 KB on NVIDIA's, RADV's and ANV's - drivers for the same pipelines. Past the bound the cache is replaced by an empty one, so a launch - after the replacement makes those pipelines again. On an M3 Max (KosmicKrisp in Mesa 26.3.1), - re-making one recorded session's 448 pipelines in the same process took 1,669-2,370 ms from the - bounded cache, with 45-60 cache hits (m3-max-67741, m3-max-67789), against 80.4-81.0 ms with no - bound, with 448 hits (m3-max-67847). A launch on that host makes its set in 0.06 s from a full - blob, and in 0.83-2.03 s around a replacement. The bound stays: the full cache of those 448 - pipelines holds about 119 MiB of host memory from device start. +- One very large app's pipelines can pass the pipeline cache's 128 MiB on KosmicKrisp (the Mac + host's driver), whose blob takes about 140 KB a pipeline against 3-25 KB on NVIDIA's, RADV's and + ANV's drivers for the same pipelines, so about 960 pipelines fill it there. A guest boot's set + (32.3 MB of blob after one boot on that host) and one long recorded session's 448 pipelines + (62.6 MB) fit. Past the bound the cache is replaced by an empty one, so a launch after the + replacement makes those pipelines again. On an M3 Max (KosmicKrisp in Mesa 26.3.1), with the + bound at 32 MiB, re-making those 448 pipelines in the same process took 1,669-2,370 ms after a + replacement, with 45-60 cache hits (m3-max-67741, m3-max-67789), against 80.4-81.0 ms with no + replacement, with 448 hits (m3-max-67847); a launch there made its set in 0.06 s from a full blob, + and in 0.83-2.03 s around a replacement. The bound's host memory on that host: a full cache's + seed holds about twice its data from device start (above). - Ray tracing's bound acceleration structure is not built (ray tracing is out of scope, docs/REFUSALS.md's `RayTracing` row). The runtime makes no acceleration structure, no encoder binds one (`setAccelerationStructure:atBufferIndex:`), and nothing supplies the instance count diff --git a/crates/metal2vulkan-runtime/src/cache.rs b/crates/metal2vulkan-runtime/src/cache.rs index b84ca83b7..ca7b92ffe 100644 --- a/crates/metal2vulkan-runtime/src/cache.rs +++ b/crates/metal2vulkan-runtime/src/cache.rs @@ -143,9 +143,10 @@ use std::time::{Duration, SystemTime}; /// lowerings fill. pub(crate) const DEFAULT_CAP: u64 = 128 << 20; /// The most bytes of data a device's `VkPipelineCache` holds when the reaper looks before it is -/// replaced by a fresh one, and so the most its blob holds: 32 MiB, about five times the 6.25 MB -/// of pipeline data a long recorded session made. -pub(crate) const PIPELINE_CACHE_BOUND: u64 = 32 << 20; +/// replaced by a fresh one, and so the most its blob holds: 128 MiB, past the 62.6 MB KosmicKrisp +/// (the Mac host's driver) writes for a long recorded session's 448 pipelines, against 1.5-11.1 MB +/// on NVIDIA's, RADV's and ANV's drivers for the same pipelines. +pub(crate) const PIPELINE_CACHE_BOUND: u64 = 128 << 20; /// How long pipeline creation stays quiet, no creation running and none ending, before the /// reaper looks at the cache: 20 ms, in nanoseconds of [`host_time`]. const QUIET_NANOS: u64 = 20_000_000; diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index d8963479c..ac1bb5f8e 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -2327,7 +2327,7 @@ pub struct Metrics { /// counterpart: Metal's compiler service keeps its own cache. pub cache_writes_dropped: u64, /// The reaper's replacements of the device's `VkPipelineCache` by a fresh, empty one, at a - /// look that found the cache past its bound of 32 MiB: creations take the fresh one from then + /// look that found the cache past its bound of 128 MiB: creations take the fresh one from then /// on, so the pipelines the old one held compile again where made again. Metal has no /// counterpart: Metal's compiler service keeps its own cache. pub pipeline_caches_replaced: u64, @@ -2335,7 +2335,7 @@ pub struct Metrics { /// in the device's map of contents first; the state takes the map's. No Metal counterpart. pub kernel_makes_dropped: u64, /// Writes of the pipeline cache's data over the device's blob skipped because the data was - /// past the bound of 32 MiB, as at the device's teardown where the cache grew past it after + /// past the bound of 128 MiB, as at the device's teardown where the cache grew past it after /// the reaper's last look: the blob keeps what it held, and a later device seeds from that. /// Metal has no counterpart. pub pipeline_cache_writes_skipped: u64, @@ -2958,7 +2958,7 @@ pub struct Gauges { /// at most 64 MiB of entries and 32 MiB of decodes. pub stage_entry_bytes: u64, /// The size of the data in the device's `VkPipelineCache`, as `vkGetPipelineCacheData` gave - /// it when the reaper last looked, once creation was quiet: at most 32 MiB at a look, past + /// it when the reaper last looked, once creation was quiet: at most 128 MiB at a look, past /// which the reaper replaces the cache with a fresh one, and this falls to the fresh one's. pub pipeline_cache_bytes: u64, /// Shadows, on a device without the attachment feedback loop: one image for each image a diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 714d915e7..591ae3d01 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -435,7 +435,7 @@ pub struct DeviceOptions { /// since none of its lookups reads their files; a device of an older one removes nothing of /// a newer one's. Beside them, one file per pipeline cache header (a kind of device and /// driver version; at most four such files, the oldest by last write removed) holds the data - /// of the `VkPipelineCache` every `VkPipeline` of the device is made through, at most 32 MiB: + /// of the `VkPipelineCache` every `VkPipeline` of the device is made through, at most 128 MiB: /// the device's cache takes it in off every guest thread, and it is /// replaced, never appended to, once pipeline creation has been quiet for 20 ms after the /// cache grew by more than an eighth, and at the device's drop where the cache changed. A @@ -447,7 +447,7 @@ pub struct DeviceOptions { /// [`Metrics::translations_loaded`]: crate::Metrics::translations_loaded pub pipeline_cache_dir: Option, /// The most bytes the lowerings in [`pipeline_cache_dir`](Self::pipeline_cache_dir) take; - /// `None` is 128 MiB. The pipeline cache's file, at most 32 MiB per kind of device, is beside + /// `None` is 128 MiB. The pipeline cache's file, at most 128 MiB per kind of device, is beside /// them. Half of the cap is what the directory is sure to keep: a lowering stays for at least /// half the cap, and at most the cap, of lowerings written or used after its last use, and /// one larger than half is not kept. Devices on one directory, in one process or several,