Skip to main content

MemoryGovernor

Struct MemoryGovernor 

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

The node-level memory governor (S1E-003). Cheap to clone (one Arc); thread-safe; the reservation fast path is lock-free and allocation-free.

Implementations§

Source§

impl MemoryGovernor

Source

pub fn new(config: GovernorConfig) -> Result<Self, MemoryError>

A governor over config (validated).

Source

pub fn with_max_bytes(max_bytes: u64) -> Result<Self, MemoryError>

A governor with the default configuration for max_bytes.

Source

pub fn config(&self) -> &GovernorConfig

The governor’s configuration.

Source

pub fn max_bytes(&self) -> u64

Configured node maximum in bytes.

Source

pub fn reserved_floor_bytes(&self) -> u64

Configured reserved floor in bytes.

Source

pub fn class_budget(&self, class: MemoryClass) -> u64

Configured budget of one class.

Source

pub fn usage(&self, class: MemoryClass) -> u64

Currently reserved bytes of one class.

Source

pub fn total_used(&self) -> u64

Currently reserved bytes across all classes.

Source

pub fn pressure(&self) -> f64

Fraction of the configured maximum in use, clamped to 0.0..=1.0.

Source

pub fn escalation(&self) -> EscalationLevel

The current escalation level (with hysteresis applied).

Source

pub fn should_reject_low_priority_work(&self) -> bool

Step 1 active: new low-priority work is being rejected.

Source

pub fn should_evict_caches(&self) -> bool

Step 2 active: reclaimable caches should be evicted (evict_reclaimable drives them).

Source

pub fn spill_trigger(&self) -> bool

Step 3 active: eligible query operators should spill. Exposed to the S1E-004 spill path: request_spill_grant turns the signal into a typed grant; the disk side is crate::spill::SpillManager.

Source

pub fn should_throttle_maintenance(&self) -> bool

Step 4 active: maintenance work should be throttled (§13.1).

Source

pub fn try_reserve( &self, bytes: u64, class: MemoryClass, ) -> Result<Reservation, MemoryError>

Reserves bytes of class, returning an RAII guard that releases the bytes on drop. Zero-byte reservations always succeed.

Admission rules, in order:

  1. Under escalation step 1, low-priority classes are rejected (MemoryError::LowPriorityRejected).
  2. The request must fit the class budget and the node limit — the configured maximum for reserved classes, the maximum minus the reserved floor for every other class, so replication/control memory is never fully starved (S1E-003 step 5).

The fast path is two atomic adds with exact rollback on rejection; no locks, no allocation.

Source

pub fn register_reclaimable<R: Reclaimable + 'static>( &self, reclaimable: &Arc<R>, )

Registers a reclaimable subsystem (held weakly) for the governor to drive under escalation step 2. Cold path; not for hot-path use.

Source

pub fn evict_reclaimable(&self, budget: u64) -> u64

Drives registered reclaimable subsystems until at least budget bytes have been freed (or nothing more is reclaimable), returning the bytes actually freed. The entry point of escalation step 2. Cold path.

Source

pub fn reclaimable_bytes(&self) -> u64

Bytes currently reclaimable from registered subsystems.

Source

pub fn request_spill_grant( &self, reservation: &mut Reservation, bytes: u64, ) -> Option<SpillGrant>

Step 3 entry point (S1E-004): while the spill trigger is active, an operator holding a Reservation of a spill-eligible class (MemoryClass::is_spill_eligible) may ask to move up to bytes of its working set to disk through crate::spill::SpillManager. On success the reservation shrinks immediately — the governor accounts the memory as freed — and the returned SpillGrant records the spilled amount; writing the bytes to spill files is charged against the query’s temporary-disk budget, and reading them back re-reserves through try_reserve. Returns None when the trigger is inactive, the class is not spill-eligible, or the reservation holds no bytes.

Source

pub fn stats(&self) -> GovernorStats

A point-in-time snapshot of governor state.

Trait Implementations§

Source§

impl Clone for MemoryGovernor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryGovernor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.