resolve_mem_budget_mb

Function resolve_mem_budget_mb 

Source
pub fn resolve_mem_budget_mb(
    explicit_mb: Option<usize>,
    cgroup_bytes: Option<u64>,
    physical_bytes: Option<u64>,
) -> usize
Expand description

Resolve the admission memory budget (MB) from the three inputs, in one place the tests exercise so it can never silently regress to 0-when-a-ceiling-is- readable.

Precedence:

  1. An explicit IFC_MEM_BUDGET_MB wins outright. Some(0) is honored as a deliberate opt-out (memory gate off) - it is NOT treated as “unset”.
  2. Otherwise, 70% of the tightest readable ceiling: min(cgroup, physical). Using the tighter of the two keeps a small cgroup from being overridden by a large host, and lets physical RAM bound a bare VM with no cgroup.
  3. Otherwise 0 (gate off) - only when neither ceiling is readable (non-Linux dev, or /proc unavailable), which the caller logs loudly.