Skip to main content

MemoryPressureMonitor

Struct MemoryPressureMonitor 

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

Monitors device memory pressure and drives reactive trim / eviction.

Construct with new supplying the warning and critical used fractions. Optionally attach an eviction hook with on_eviction and a transition callback with on_transition. Feed samples via observe (synthetic) or poll (live GPU).

Implementations§

Source§

impl MemoryPressureMonitor

Source

pub fn new(warning_fraction: f64, critical_fraction: f64) -> CudaResult<Self>

Creates a monitor with the given warning and critical used-fraction thresholds.

Both fractions must lie in (0.0, 1.0] and warning_fraction must be strictly less than critical_fraction.

§Errors
  • CudaError::InvalidValue if either threshold is non-finite, outside (0.0, 1.0], or if warning_fraction >= critical_fraction.
Source

pub fn on_eviction<F>(self, hook: F) -> Self
where F: FnMut() -> usize + Send + 'static,

Attaches an eviction hook fired whenever the monitor enters the critical level. The hook returns the number of bytes it reclaimed, which is accumulated into total_evicted.

Builder-style; returns self for chaining.

Source

pub fn on_transition<F>(self, hook: F) -> Self
where F: FnMut(PressureSample) + Send + 'static,

Attaches a callback fired on every level transition (escalation or de-escalation).

Builder-style; returns self for chaining.

Source

pub fn warning_fraction(&self) -> f64

The warning used-fraction threshold.

Source

pub fn critical_fraction(&self) -> f64

The critical used-fraction threshold.

Source

pub fn level(&self) -> PressureLevel

The current pressure level (state from the most recent sample).

Source

pub fn total_evicted(&self) -> usize

Total bytes reclaimed by the eviction hook over this monitor’s lifetime.

Source

pub fn eviction_count(&self) -> u64

Number of times the eviction hook has fired.

Source

pub fn classify(&self, used_fraction: f64) -> PressureLevel

Classifies a used_fraction (0.0–1.0) into a PressureLevel using this monitor’s thresholds.

The comparison is inclusive at the threshold (a fraction exactly equal to the critical threshold is Critical).

Source

pub fn observe(&mut self, info: MemoryInfo) -> PressureLevel

Feeds a synthetic memory sample through the monitor and returns the new level.

On a transition the transition callback (if any) fires. On entering the critical level the eviction hook (if any) fires and its return value is accumulated. Re-observing the same level does not re-fire hooks.

Source

pub fn poll(&mut self) -> CudaResult<PressureLevel>

Polls live device memory via crate::memory_info::memory_info and feeds the sample through observe.

§Errors

Forwards any error from the memory-info query (e.g. no current context).

Source

pub fn reset(&mut self)

Resets the monitor’s level to Nominal and clears eviction accounting, without changing thresholds or hooks.

Trait Implementations§

Source§

impl Debug for MemoryPressureMonitor

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> 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, 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.
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