MemoryGrant

Struct MemoryGrant 

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

A memory grant.

Grants define a number of bytes which have been granted for use, with an accompanying “slop factor.”

§Slop factor

There can be numerous sources of “slop” in terms of memory allocations, and limiting the memory usage of a process. Not all components can effectively track their true firm/hard limit, memory allocators have fragmentation that may be reduced over time but never fully eliminated, and so on.

In order to protect against this issue, we utilize a slop factor when calculating the effective limits that we should verify memory bounds again. For example, if we seek to use no more than 64MB of memory from the OS perspective (RSS), then intuitively we know that we might only be able to allocate 55-60MB of memory before allocator fragmentation causes us to reach 64MB RSS.

By specifying a slop factor, we can provide ourselves breathing room to ensure that we don’t try to allocate every last byte of the given global limit, inevitably leading to exceeding that limit and potentially causing out-of-memory crashes, etc.

Implementations§

Source§

impl MemoryGrant

Source

pub fn effective(effective_limit_bytes: usize) -> Result<Self, GrantError>

Creates a new memory grant based on the given effective limit.

This grant will have a slop factor of 0.0 to indicate that the effective limit is already inclusive of any necessary slop factor.

If the effective limit is greater than 9007199254740992 bytes (2^53 bytes, or roughly 9 petabytes), then None is returned. This is a hardcoded limit.

Source

pub fn with_slop_factor( initial_limit_bytes: usize, slop_factor: f64, ) -> Result<Self, GrantError>

Creates a new memory grant based on the given initial limit and slop factor.

The slop factor accounts for the percentage of the initial limit that can effectively be used. For example, a slop factor of 0.1 would indicate that only 90% of the initial limit should be used, and a slop factor of 0.25 would indicate that only 75% of the initial limit should be used, and so on.

If the slop factor is not valid (must be 0.0 < slop_factor <= 1.0), then None is returned. If the effective limit is greater than 9007199254740992 bytes (2^53 bytes, or roughly 9 petabytes), then None is returned. This is a hardcoded limit.

Source

pub fn initial_limit_bytes(&self) -> usize

Initial number of bytes granted.

This value is purely informational, and should not be used to calculating the memory available for use. For that value, see effective_limit_bytes.

Source

pub fn slop_factor(&self) -> f64

The slop factor for the initial limit.

This value is purely informational.

Source

pub fn effective_limit_bytes(&self) -> usize

Effective number of bytes granted.

This is the value which should be followed for memory usage purposes, as it accounts for the configured slop factor.

Trait Implementations§

Source§

impl Clone for MemoryGrant

Source§

fn clone(&self) -> MemoryGrant

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryGrant

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MemoryGrant

Source§

fn eq(&self, other: &MemoryGrant) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for MemoryGrant

Source§

impl Eq for MemoryGrant

Source§

impl StructuralPartialEq for MemoryGrant

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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> Track for T

Source§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
Source§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. 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.
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