Skip to main content

cpu_max_to_write

Function cpu_max_to_write 

Source
pub fn cpu_max_to_write(
    spec_limits: Option<&RunLimits>,
    env_cpu_max: Option<&str>,
) -> Option<String>
Expand description

Resolve the cpu.max payload for the host-subprocess cgroup leaf.

Resolution order (highest priority first):

  1. spec.run.limits.cpuMax — typed source of truth from the contract.
  2. env_cpu_max — operator-supplied CELLOS_CGROUP_CPU_MAX override; used only when the spec is silent. The caller passes the env value verbatim (or None when unset / empty); validation/normalization happens here.

Returns Some(payload) when a value should be written to the leaf’s cpu.max file (without a trailing newline; the writer adds one). Returns None when neither source produced an applicable value, or when the env override was syntactically invalid (caller should warn — see cpu_max_env_validation_error for the diagnostic string).

Accepted env-override syntaxes (per cgroup v2 cpu.max):

  • max"max 100000"
  • max <period>"max <period>"
  • <quota>"<quota> 100000"
  • <quota> <period>"<quota> <period>"

Whitespace is collapsed; quota and period must parse as u64 and be >= 1 (cgroup v2 rejects 0). Anything else returns None here and the caller is expected to log a warning.