pub struct MemoryAccounting { /* private fields */ }Expand description
The one shared accounting pool: fixed shares, live usage.
Usage is a relaxed atomic per pool. Reporting is a single store or fetch-add — no allocation, no lock, nothing a read hot path has to wait on. Relaxed is the right ordering because the counters are observability, not synchronisation: no other memory is published through them.
Implementations§
Source§impl MemoryAccounting
impl MemoryAccounting
Sourcepub fn new(budget: MemoryBudget, profile: DeployProfile) -> MemoryAccounting
pub fn new(budget: MemoryBudget, profile: DeployProfile) -> MemoryAccounting
Build the pool from a resolved budget and the profile’s policy.
Build the pool from shares already resolved (and already asserted).
Sourcepub fn budget(&self) -> MemoryBudget
pub fn budget(&self) -> MemoryBudget
The budget this process runs under.
The shares this pool accounts against.
Sourcepub fn report(&self, pool: MemoryPool, bytes: u64)
pub fn report(&self, pool: MemoryPool, bytes: u64)
Overwrite a pool’s live usage. The reporting shape for pools whose footprint is a measured total rather than a running delta.
Sourcepub fn charge(&self, pool: MemoryPool, bytes: u64)
pub fn charge(&self, pool: MemoryPool, bytes: u64)
Charge bytes to a pool. One relaxed fetch-add.
Sourcepub fn release(&self, pool: MemoryPool, bytes: u64)
pub fn release(&self, pool: MemoryPool, bytes: u64)
Return bytes to a pool, saturating at zero.
Saturation rather than wrap: a double-release is a programmer error the
enforcement slice will assert on, but until then an accounting counter
underflowing to 18 exabytes would make red.stats lie spectacularly.
Sourcepub fn used_bytes(&self, pool: MemoryPool) -> u64
pub fn used_bytes(&self, pool: MemoryPool) -> u64
This pool’s live usage.
This pool’s share of the budget.
Sourcepub fn total_used_bytes(&self) -> u64
pub fn total_used_bytes(&self) -> u64
Σ(used) across every pool — the number the enforcement slice will gate on.
Σ(shares). Never exceeds the budget.
Sourcepub fn snapshot(&self) -> [PoolUsage; 5]
pub fn snapshot(&self) -> [PoolUsage; 5]
Every pool’s share and usage, in MEMORY_POOLS order.
Sourcepub fn observe_total_used(&self, total: u64)
pub fn observe_total_used(&self, total: u64)
Record a sampled total as the shared accounting high-water mark.
pub fn record_admission_denied(&self)
pub fn record_pressure_reclamation(&self, reclaimed_bytes: u64)
pub fn enforcement_snapshot(&self) -> MemoryEnforcementSnapshot
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MemoryAccounting
impl RefUnwindSafe for MemoryAccounting
impl Send for MemoryAccounting
impl Sync for MemoryAccounting
impl Unpin for MemoryAccounting
impl UnsafeUnpin for MemoryAccounting
impl UnwindSafe for MemoryAccounting
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request