Repository navigation
feat(prebuilt): budget-capped disk-cache LRU for extracted trees (#1882) - #2193
Merged
Merged
Conversation
`obtain` commits one tree per exact identity below `{cache}/prebuilt/` and
nothing ever removed them, so a client that walks framework versions kept a
full decompressed framework per fingerprint forever. `sweep_staging_tree`
cannot help: it reaps abandoned staging attempts and deliberately never
touches a tree carrying the completion marker.
`prebuilt::lru` owns the eviction decision and only that:
- a candidate is a directory below the prebuilt root holding a regular
`MARKER` file, written only after the whole tree verified; the root itself
and every staging sibling are never candidates;
- recency is the marker's modification time, and `obtain` bumps it with
`touch` on every reuse, so a tree that keeps being used is never the first
to go (proven RED: removing the call fails the reuse test);
- a tree inside the one-hour grace period is kept and counted — there are no
leases on this path, so a build may be reading it;
- eviction is oldest first, at most `MAX_REMOVALS` per pass, stops as soon as
the remaining bytes fit the budget, and never follows or removes a symlink.
Opt-in: `FBUILD_PREBUILT_BUDGET` is the only budget source. Unset, empty or
unparseable disables the LRU, so no existing cache is pruned by surprise. The
daemon calls `prune_once` on the same 6 h schedule as the staging sweep.
Tests: prebuilt:: 66 passed (12 new in lru_tests, 1 wiring test through
`obtain`), entry::prebuilt_gc:: 6 passed (2 new), fmt clean, boundary
rows=0; dylint_rows=0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
Unit 12 of the #1882 track: the disk-cache LRU that the
prebuiltplan listsafter staging/partial GC (delivered as #2189) and the identity → tree call site
(#2192). #1882 stays open.
obtaincommits one tree per exact identity below{cache}/prebuilt/, andnothing ever removed them: a client that walks framework versions keeps a full
decompressed framework per fingerprint forever.
sweep_staging_treecannothelp — it reaps abandoned staging attempts and deliberately never touches a
tree carrying the completion marker.
The rule
crates/fbuild-packages-fetch/src/prebuilt/lru.rs{cache}/prebuilt/holding aregular
MARKERfile. The marker is written only after the whole treeverified, so a staging directory, a partial destination or a loose file is
never a candidate (the sweep owns those), and the prebuilt root itself is
never one either.
obtainnow callstouchonevery reuse, so recency means last use, not creation — a tree that keeps
being used is never the first evicted. A failed touch never fails the
resolve (a read-only cache is still a correct cache).
MIN_AGE(1 h, sharedwith the sweep) is kept and counted. There are no leases on this path, so a
build may be reading it right now.
FBUILD_PREBUILT_BUDGETis the only source. Unset, empty orunparseable ⇒
None⇒ the LRU never runs, so no existing cache is pruned bysurprise.
0is a real budget (evict every eligible tree).MAX_REMOVALStrees perpass, stop as soon as the remaining bytes fit, at most
MAX_SCAN_DIRSdirectories and
MAX_SCAN_DEPTHlevels, never a symlinked directory, and aremoval error is reported rather than hidden.
Wiring:
crates/fbuild-daemon/src/bin/entry/prebuilt_gc.rsgainsprune_onceand calls it on the same 6 h schedule as the staging sweep, once, only when a
budget is declared.
Tests (real output)
lru_tests.rs: the candidate rule, the root guard, amarker that is not a regular file, a symlinked tree, oldest-first eviction
against a budget, the grace period, the removal ceiling, an absent root, and
the opt-in budget (including a typo disabling rather than guessing).
a_reuse_records_itself_as_the_last_usedownloads once, backdates the marker 24 h, reuses the tree, and asserts the
marker's last-use time moved forward while the request count stayed at 1.
Proven RED — deleting the
touchcall inobtainfails exactly that test.prune_oncewhile a fresh one isprotected, and a generous budget removes nothing.
Not done
cells of the track.
obtainhas no production build-path caller yet, so the LRU is exercised by tests and bythe daemon's opt-in pass only.
CI at open
Formatting,Reject .rs files over 1000 LOC,Reject new workspace crates,Verify local gate,Dylint policy,ProoftandValidate Board Definitionspassed;
Dylint Full (Linux builder, all OS targets)passed in 5m17s, whichis the gate that polices
ban_std_pathbuf/ban_std_fs_in_async/ban_poison_panicon the new files.linux / Checkwas still running at thetime of writing. (Local clippy could not run: the
soldrbuild route is a remoteforge worker whose build lease was held by another job for the whole tick.)