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
impl MemoryGrant
Sourcepub fn effective(effective_limit_bytes: usize) -> Result<Self, GrantError>
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.
Sourcepub fn with_slop_factor(
initial_limit_bytes: usize,
slop_factor: f64,
) -> Result<Self, GrantError>
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.
Sourcepub fn initial_limit_bytes(&self) -> usize
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
.
Sourcepub fn slop_factor(&self) -> f64
pub fn slop_factor(&self) -> f64
The slop factor for the initial limit.
This value is purely informational.
Sourcepub fn effective_limit_bytes(&self) -> usize
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
impl Clone for MemoryGrant
Source§fn clone(&self) -> MemoryGrant
fn clone(&self) -> MemoryGrant
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MemoryGrant
impl Debug for MemoryGrant
Source§impl PartialEq for MemoryGrant
impl PartialEq for MemoryGrant
impl Copy for MemoryGrant
impl Eq for MemoryGrant
impl StructuralPartialEq for MemoryGrant
Auto Trait Implementations§
impl Freeze for MemoryGrant
impl RefUnwindSafe for MemoryGrant
impl Send for MemoryGrant
impl Sync for MemoryGrant
impl Unpin for MemoryGrant
impl UnwindSafe for MemoryGrant
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self> ⓘ
Tracked
wrapper. Read more