Sign in

    moonpressure

    Linux cgroup pressure diagnostics, hierarchical admission and worker reservation lifecycle in MoonBit

    linux
    cgroup
    psi
    pressure
    admission
    Download zip
    Author
    Version
    0.3.0
    License
    MIT
    Last updated
    6 days ago
    Downloads
    37

    No dependencies

    #Executable API example

    The published module is trail-it/moonpressure. This example is compiled as a black-box test.

    ///|
    test "visible ancestor budget" {
    let leaf = @moonpressure.Layer::parse(
    "leaf",
    memory_max="max",
    memory_current="100",
    )
    let parent = @moonpressure.Layer::parse(
    "parent",
    cpu_max="50000 100000",
    memory_max="1000",
    memory_current="900",
    )
    let limits = @moonpressure.budget([leaf, parent])
    assert_eq(limits.quota_cores, Some(0.5))
    assert_eq(limits.hard_headroom_bytes, Some(100L))
    }

    DeltaError

    pub(all) suberror DeltaError {
    IdentityChanged
    InvalidInterval
    CounterReset(String)
    AvailabilityChanged(String)
    } derive(Eq,
    Debug
    )

    DeltaError::equal

    fn DeltaError::equal(DeltaError, DeltaError) -> Bool

    DeltaError::not_equal

    fn DeltaError::not_equal(x : DeltaError, y : DeltaError) -> Bool

    ParseError

    pub(all) suberror ParseError {
    Invalid(String)
    } derive(Eq,
    Debug
    )

    ParseError::equal

    fn ParseError::equal(ParseError, ParseError) -> Bool

    ParseError::not_equal

    fn ParseError::not_equal(x : ParseError, y : ParseError) -> Bool

    Admission

    pub(all) enum Admission {
    Ready
    Shed
    } derive(Eq,
    Debug
    )

    Admission::equal

    fn Admission::equal(Admission, Admission) -> Bool

    Admission::label

    fn Admission::label(self : Admission) -> String

    Admission::not_equal

    fn Admission::not_equal(x : Admission, y : Admission) -> Bool

    Advice

    pub struct Advice {
    state : Admission
    reasons : Array[Reason]
    high_streak : Int
    low_streak : Int
    } derive(Eq,
    Debug
    )

    Advice::equal

    fn Advice::equal(Advice, Advice) -> Bool

    Advice::not_equal

    fn Advice::not_equal(x : Advice, y : Advice) -> Bool

    Advice::to_json

    fn Advice::to_json(self : Advice) -> Json

    Advice::to_repr

    Budget

    pub struct Budget {
    quota_cores : Double?
    hard_headroom_bytes : Int64?
    high_headroom_bytes : Int64?
    quota_source : String?
    hard_source : String?
    high_source : String?
    } derive(Eq,
    Debug
    )

    Budget::equal

    fn Budget::equal(Budget, Budget) -> Bool

    Budget::not_equal

    fn Budget::not_equal(x : Budget, y : Budget) -> Bool

    Budget::to_json

    fn Budget::to_json(self : Budget) -> Json

    Budget::to_repr

    Controller

    pub struct Controller {
    // private fields
    }

    Controller::new

    fn Controller::new(policy : Policy) -> Controller

    Controller::reset

    fn Controller::reset(self : Controller) -> Unit

    Explicitly reset after a source/generation change. No invalid update mutates state.

    Controller::update

    fn Controller::update(self : Controller, sample : Interval, limits : Budget) -> Advice raise DeltaError

    Consume contiguous intervals exactly once. Missing PSI prevents automatic recovery.

    CpuMax

    pub struct CpuMax {
    quota : Limit
    period_us : Int64
    } derive(Eq,
    Debug
    )

    CpuMax::equal

    fn CpuMax::equal(CpuMax, CpuMax) -> Bool

    CpuMax::not_equal

    fn CpuMax::not_equal(x : CpuMax, y : CpuMax) -> Bool

    CpuMax::to_repr

    CpuStat

    pub struct CpuStat {
    usage_us : Int64
    throttle : Throttle?
    } derive(Eq,
    Debug
    )

    CpuStat::equal

    fn CpuStat::equal(CpuStat, CpuStat) -> Bool

    CpuStat::not_equal

    fn CpuStat::not_equal(x : CpuStat, y : CpuStat) -> Bool

    CpuStat::to_repr

    Interval

    pub struct Interval {
    identity : String
    end_us : Int64
    elapsed_us : Int64
    cpu_cores_used : Double
    throttled_period_percent : Double?
    throttled_us : Int64?
    memory_current_bytes : Int64
    memory_high_events : Int64
    memory_max_events : Int64
    oom_events : Int64
    oom_kills : Int64
    cpu_stall : StallDelta?
    memory_stall : StallDelta?
    io_stall : StallDelta?
    } derive(Eq,
    Debug
    )

    Interval::equal

    fn Interval::equal(Interval, Interval) -> Bool

    Interval::not_equal

    fn Interval::not_equal(x : Interval, y : Interval) -> Bool

    Interval::to_json

    fn Interval::to_json(self : Interval) -> Json

    Interval::to_repr

    Layer

    pub struct Layer {
    name : String
    cpu : CpuMax?
    memory_max : Limit?
    memory_high : Limit?
    memory_current : Int64?
    } derive(Eq,
    Debug
    )

    Layer::equal

    fn Layer::equal(Layer, Layer) -> Bool

    Layer::not_equal

    fn Layer::not_equal(x : Layer, y : Layer) -> Bool

    Layer::parse

    fn Layer::parse(name : String, cpu_max? : String, memory_max? : String, memory_high? : String, memory_current? : String) -> Layer raise ParseError

    A visible cgroup layer. Missing controller files are distinct from max.

    Layer::to_repr

    Limit

    pub(all) enum Limit {
    Unlimited
    Finite(Int64)
    } derive(Eq,
    Debug
    )

    Limit::equal

    fn Limit::equal(Limit, Limit) -> Bool

    Limit::not_equal

    fn Limit::not_equal(x : Limit, y : Limit) -> Bool

    Limit::to_repr

    MemoryEvents

    pub struct MemoryEvents {
    high : Int64
    max : Int64
    oom : Int64
    oom_kill : Int64
    } derive(Eq,
    Debug
    )

    MemoryEvents::equal

    MemoryEvents::not_equal

    fn MemoryEvents::not_equal(x : MemoryEvents, y : MemoryEvents) -> Bool

    Policy

    pub struct Policy {
    enter_percent : Double
    exit_percent : Double
    enter_intervals : Int
    exit_intervals : Int
    min_headroom_bytes : Int64
    } derive(Eq,
    Debug
    )

    Policy::equal

    fn Policy::equal(Policy, Policy) -> Bool

    Policy::new

    fn Policy::new(enter_percent? : Double, exit_percent? : Double, enter_intervals? : Int, exit_intervals? : Int, min_headroom_bytes? : Int64) -> Policy raise ParseError

    Percent thresholds apply independently to PSI some and throttled periods. These defaults are heuristics; callers tune for their workload.

    Policy::not_equal

    fn Policy::not_equal(x : Policy, y : Policy) -> Bool

    Policy::to_repr

    Pressure

    pub struct Pressure {
    some : PressureLine
    full : PressureLine?
    } derive(Eq,
    Debug
    )

    Pressure::equal

    fn Pressure::equal(Pressure, Pressure) -> Bool

    Pressure::not_equal

    fn Pressure::not_equal(x : Pressure, y : Pressure) -> Bool

    Pressure::to_repr

    PressureLine

    pub struct PressureLine {
    avg10 : Double
    avg60 : Double
    avg300 : Double
    total_us : Int64
    } derive(Eq,
    Debug
    )

    PressureLine::equal

    PressureLine::not_equal

    fn PressureLine::not_equal(x : PressureLine, y : PressureLine) -> Bool

    Reason

    pub(all) enum Reason {
    CpuStall
    MemoryStall
    IoStall
    CpuThrottled
    LowMemoryHeadroom
    MemoryHigh
    MemoryMax
    OutOfMemory
    Recovering
    MissingPressure
    } derive(Eq,
    Debug
    )

    Reason::equal

    fn Reason::equal(Reason, Reason) -> Bool

    Reason::label

    fn Reason::label(self : Reason) -> String

    Reason::not_equal

    fn Reason::not_equal(x : Reason, y : Reason) -> Bool

    Reason::to_repr

    Snapshot

    pub struct Snapshot {
    identity : String
    time_us : Int64
    cpu : CpuStat
    memory_current : Int64
    events : MemoryEvents
    cpu_pressure : Pressure?
    memory_pressure : Pressure?
    io_pressure : Pressure?
    } derive(Eq,
    Debug
    )

    Snapshot::equal

    fn Snapshot::equal(Snapshot, Snapshot) -> Bool

    Snapshot::not_equal

    fn Snapshot::not_equal(x : Snapshot, y : Snapshot) -> Bool

    Snapshot::parse

    fn Snapshot::parse(identity : String, time_us : Int64, cpu_stat~ : String, memory_current~ : String, memory_events~ : String, cpu_pressure? : String, memory_pressure? : String, io_pressure? : String) -> Snapshot raise ParseError

    Snapshot::to_json

    fn Snapshot::to_json(self : Snapshot) -> Json

    Schema 1 uses decimal strings for Int64 counters to preserve JSON precision.

    Snapshot::to_repr

    StallDelta

    pub struct StallDelta {
    some_percent : Double
    full_percent : Double?
    } derive(Eq,
    Debug
    )

    StallDelta::equal

    fn StallDelta::equal(StallDelta, StallDelta) -> Bool

    StallDelta::not_equal

    fn StallDelta::not_equal(x : StallDelta, y : StallDelta) -> Bool

    Throttle

    pub struct Throttle {
    periods : Int64
    throttled_periods : Int64
    throttled_us : Int64
    } derive(Eq,
    Debug
    )

    Throttle::equal

    fn Throttle::equal(Throttle, Throttle) -> Bool

    Throttle::not_equal

    fn Throttle::not_equal(x : Throttle, y : Throttle) -> Bool

    Throttle::to_repr

    budget

    fn budget(layers : ArrayView[Layer]) -> Budget raise ParseError

    Reduces visible layers, including ancestors' own current usage. CPU result is a quota upper bound, not affinity-aware guaranteed capacity.

    interval

    fn interval(old : Snapshot, now : Snapshot) -> Interval raise DeltaError

    Only compare the same cgroup generation and a positive <=60s interval.

    parse_counter

    fn parse_counter(text : String) -> Int64 raise ParseError

    Strict unsigned decimal in signed Int64 range; rejects signs and overflow.

    parse_cpu_max

    fn parse_cpu_max(text : String) -> CpuMax raise ParseError

    parse_cpu_stat

    fn parse_cpu_stat(text : String) -> CpuStat raise ParseError

    parse_limit

    fn parse_limit(text : String) -> Limit raise ParseError

    parse_memory_events

    fn parse_memory_events(text : String) -> MemoryEvents raise ParseError

    parse_pressure

    fn parse_pressure(text : String) -> Pressure raise ParseError

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io