Skip to main content

MemWatchdog

Struct MemWatchdog 

Source
pub struct MemWatchdog { /* private fields */ }
Expand description

The watchdog: a meminfo path, a floor, and the counters that say what it did.

Implementations§

Source§

impl MemWatchdog

Source

pub fn from_env() -> Self

From the environment: the real /proc/meminfo and the knobs above.

Source

pub fn with(meminfo: &Path, budget: u64, poll: Duration) -> Self

An explicit watchdog: meminfo is what is read, budget the floor in bytes, poll the re-check cadence. What a test builds.

Source

pub fn bounded(self, resume_margin: u64, deadline: Duration) -> Self

The two bounds that make a pause end: the absolute resume margin and the deadline. Duration::ZERO disables the deadline — the pre-2026-08-30 shape, which only a test asks for.

Source

pub fn with_reflush(self, every: Duration) -> Self

How often the flush runs again during one pause. A test shortens it so that the empty-flush arm can be asserted without 20 s of wall clock; production leaves it at REFLUSH_EVERY.

Source

pub fn disabled() -> Self

A watchdog that never pauses (budget 0). For callers that opt out.

Source

pub fn budget(&self) -> u64

Source

pub fn total(&self) -> u64

Source

pub fn available(&self) -> Option<u64>

MemAvailable right now, or None if the file cannot be read — and None never pauses: a box with no /proc is not a box short of memory.

Source

pub fn breached(&self) -> Option<(u64, u64)>

Some((available, budget)) when the floor is breached.

Source

pub fn resume_margin(&self) -> u64

The absolute resume margin this watchdog uses — RESUME_MARGIN_BYTES, or ZNIPPY_GIT_MEM_RESUME_MARGIN_BYTES. Never more than the floor itself: a margin bigger than the budget would be the old bug in a new spelling.

Source

pub fn pause_deadline(&self) -> Duration

The ceiling on one pause — PAUSE_DEADLINE, or ZNIPPY_GIT_MEM_PAUSE_MAX_MS. 0 means “no deadline”, which is what a test asks for when it wants the old shape on purpose.

Source

pub fn pauses(&self) -> u64

How many times a pause began.

Source

pub fn paused_ms(&self) -> u64

Milliseconds spent paused in total.

Source

pub fn is_paused(&self) -> bool

Is a pause in progress on some worker?

Source

pub fn give_ups(&self) -> u64

Pauses that ended on the deadline or with nothing left to drop.

Source

pub fn pause_until_ok( &self, label: &str, cancel: Option<&AtomicBool>, flush: &mut dyn FnMut() -> Result<u64>, ) -> Result<Pause>

The check. Returns immediately when the floor holds. Otherwise runs flush (the caller drops what it can, and says how much it dropped), then waits — re-reading every poll, re-flushing every REFLUSH_EVERY — until one of the four things in PauseEnd happens.

flush returns what it freed: rows, bytes, entries, whatever the caller counts — the number is only ever compared with zero. Three zeros in a row (GIVE_UP_AFTER_EMPTY_FLUSHES) with memory no better than it started means there is nothing on this box left to give, and the wait ends with PauseEnd::NothingToGive instead of continuing. So does MemWatchdog::pause_deadline expiring.

A pause that cannot end is worse than a pack that is refused, which is the whole lesson of lane P2’s two rig boxes: they parked for 31m44s and 1h45m41s, emitted 190 and 627 spills that freed nothing, and never resumed. The caller decides what to do with a give-up; this decides that there IS one.

label names the worker in the log lines (rickard/linux).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more