Files
metal2vulkan/crates
Anees Iqbal 3d2b846caa Runtime cache directory: a newer translator's open retires both generations
Every lowering's and record's name under translations/ and renders/ holds the translator's
SEMANTICS_VERSION, and a lowering decodes under its own ARTIFACT_FORMAT_VERSION alone. So after a
version change no file of the old version is looked up again, yet it stayed counted until
young filled, and the one rotation then only moved it from young to old. A consumer's directory
held 97.6 MB of translations, of which 92.7 MB were of older versions.

The state file now records, after young's number, its bytes and their checksum (bytes 0..24,
unchanged), the newest SEMANTICS_VERSION and ARTIFACT_FORMAT_VERSION a store opened the directory
under, each at its highest, with a checksum (bytes 24..40). At its open, under the state's lock
(Store::meet), a store whose translator is newer than the record in either version moves young
two generations on, counted empty, so the young and old it found are both below old and the
existing removal thread removes them, and it records the higher of each version. A store at the
recorded versions or older ones retires nothing and records nothing: product builds of every
version share one directory in the consumer's layout, so two builds alternating on it, or one
running beside the other, keep each other's files after the newer one's first open, and the
older one's writes go into young. A state whose versions are missing or do not check after a
young's record that does (an earlier version's 24-byte state file) reads as older than every
translator, so the first open after this change retires once; an earlier version writes only
bytes 0..24 at the start of a file it opens without truncation, so the record stays. A state
that does not check at all (a new directory's, or a torn one) is rebuilt from the generations'
names as before and retires nothing. Read-only directories retire nothing.

The removal now takes the dead generations lowest first, so a removal cut short while two are
dead (the retire's case) leaves the one just below old, which the next open looks for.

Store::open takes the store's Versions; Caches::new passes Versions::BUILT (the translator's
constants). No SEMANTICS bump: the translator's output and keys are unchanged. The cache.rs
module doc, the runtime README's cache-directory section and DeviceOptions::pipeline_cache_dir's
doc say so.

Tests (host, each on a directory of its own, in src/tests/cache.rs):
- a_newer_translators_open_retires_both_generations_once: filled under (S, F), four stores open
  at once under (S+1, F), then under (S, F+1): young 3 -> 5 once, generations 2 and 3 gone, no
  older file left, writes and hits work, a reopen retires nothing.
- an_older_translators_open_retires_nothing_of_a_newer_ones: after the newer one's open, the
  older one's open removes nothing and records nothing, its write and the newer one's file are
  both read by the newer one's reopen; a translator newer in format alone retires and the record
  keeps the higher of each, so neither earlier one retires after it.
- a_state_with_no_versions_reads_as_older_once: the record cut to 24 bytes, or its checksum
  broken, retires once; then an earlier version's 24-byte write at offset 0 leaves the record,
  and the next open reads that write and retires nothing.
- the_dead_generations_are_removed_lowest_first: dead generations 30, 9, 1, 10, 2 listed as
  1, 2, 9, 10, 30.

Verified: compile job m3-max-65330 (fmt, the signatures table, clippy plain, --cfg m2v_gpu and
--cfg m2v_cpu_icd, workspace Rustdoc -D warnings, the store's host tests 23/23, and
metal2vulkan-runtime's suite on lavapipe 629 passed, the four new tests among them).
2026-11-21 17:43:08 -08:00
..