Skip to main content

pressure_limit

Function pressure_limit 

Source
pub fn pressure_limit(
    size: u64,
    cap: u64,
    min_free: u64,
    threshold: u64,
    free: u64,
) -> u64
Expand description

A cache’s target size under its cap and the volume’s free space: the one rule every caller of pressure collection goes through.

Three bands, by free against the admission floor min_free and the collection threshold threshold (Disk::reclaim_threshold):

  • free >= threshold: nothing is short; the limit is the configured cap (never more than size, so nothing is asked to shrink).
  • min_free <= free < threshold: the limit shrinks by the deficit (threshold - free) but never below a reserve, half of cap (see pressure_reserve; never above the cache’s own size, so a cache at or below its reserve is left alone). A build cache is only worth anything while some of it is left: on a disk whose free space other software controls, a rule without a reserve would empty every cache on every pass and start every build cold. The ratio is fixed on purpose, not a setting. The limit alone does not keep the reserve: the pruning routine is also given the reserve as a bound (prune_dir_keeping) and refuses any removal that would cross it.
  • free < min_free: below the admission floor work is held anyway and getting space back outranks a warm cache, so this is exactly the rule from before the threshold existed: the limit shrinks by the deficit against min_free, down to zero if need be.

A zero cap yields zero here; callers that treat a zero cap as “pruning off” check it before asking. The limit is an estimate: the caller removes that many logical bytes oldest-first and does not re-measure within the pass (see PressureOutcome).