Skip to main content

Module disk

Module disk 

Source
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.
PrunePlan
What plan_prune would remove, without removing it.

Enums§

PressureOutcome
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 free bytes 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 — None means the gate is open. Pure, so the policy is asserted directly.
gate_in
gate, with the reason in language (en, or Japanese; anything else is English).
is_gate_reason
Is reason one of this module’s disk-gate reasons, in either language? What triage reads back to decide a hold is disk pressure.
over_limit
Is size past limit? 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 -P data row: Filesystem 1024-blocks Used Available ….
plan_prune
The selection prune_dir would 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: removed is the logical bytes it removed; size the cache’s size going into the deletion (the pruning routine’s own inventory); limit what pressure_limit allowed; keep the 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 manual magi cache prune and the plain cap unchanged.
prune_dir
Delete files under dir oldest-first until its size is at or below limit.
prune_dir_keeping
prune_dir that never takes the directory below keep bytes.
unmeasured_in
The reason for a measurement that failed, in language.
volume_root
The drive root used for querying an absolute Windows path: C:\, never C:\Users\... and never a verbatim \\?\C:\....