Expand description
Disk accounting: how much magi’s own directories occupy, how much space is left on the volume they live on, and how the shared build cache is pruned.
The whole module grew out of one incident: a machine with 951.8 GB of disk
ran a handful of competitions and ended up with 6.7 GB free and a pile of
multi-gigabyte target/ directories. Every function here exists to keep
that from being a discovery, and every number is substituted at a pure
boundary so the policy can be tested without asking the OS anything.
Structs§
- Prune
- What a prune removed, for the report.
- Prune
Plan - What
plan_prunewould remove, without removing it.
Enums§
- Pressure
Outcome - How a shared-cache pressure pass that ran to completion ended, as its log line says it. None of them is an error: a pass that cannot make progress says so and the service’s next period tries again.
Constants§
- RUNNING_
PRESSURE - Prefix of a resource hold after emergency writer termination.
- UNMEASURED_
EN - Prefix of a failed free-space measurement.
- UNMEASURED_
JA - See
UNMEASURED_EN.
Functions§
- dir_
size - Total bytes under
path, without following symlinks. - enough_
space - Are
freebytes above the floor for starting a run? - extract_
cargo_ target_ dir - The path a rendered command sets
CARGO_TARGET_DIR=to, if any. - free_
bytes - Free bytes on the volume containing
path. - gate
- Why a run must not start, given measured free bytes and the floor —
Nonemeans the gate is open. Pure, so the policy is asserted directly. - gate_in
gate, with the reason inlanguage(en, or Japanese; anything else is English).- is_
gate_ reason - Is
reasonone of this module’s disk-gate reasons, in either language? What triage reads back to decide a hold is disk pressure. - over_
limit - Is
sizepastlimit? One comparison, shared by the janitor and the health view, so both answer “is the cache over its cap” identically. - parse_
df_ available - One
df -k -Pdata row:Filesystem 1024-blocks Used Available …. - plan_
prune - The selection
prune_dirwould act on if every one of these deletions succeeds, computed without touching disk. - pressure_
limit - A cache’s target size under its cap and the volume’s free space: the one rule every caller of pressure collection goes through.
- pressure_
outcome - Classify a pass:
removedis the logical bytes it removed;sizethe cache’s size going into the deletion (the pruning routine’s own inventory);limitwhatpressure_limitallowed;keepthe reserve the pruning was bounded by (pressure_reserve). - pressure_
reserve - The size a build cache must keep while free space is between the admission
floor and the collection threshold: half its configured
cap. Zero in every other band (at or above the threshold nothing is collected beyond the cap; below the floor getting space back outranks a warm cache), which is also what makes manualmagi cache pruneand the plain cap unchanged. - prune_
dir - Delete files under
diroldest-first until its size is at or belowlimit. - prune_
dir_ keeping prune_dirthat never takes the directory belowkeepbytes.- unmeasured_
in - The reason for a measurement that failed, in
language. - volume_
root - The drive root used for querying an absolute Windows path:
C:\, neverC:\Users\...and never a verbatim\\?\C:\....