pub struct MemoryManagement<Storage> { /* private fields */ }Expand description
Reserves and keeps track of chunks of memory in the storage, and slices upon these chunks.
Implementations§
Source§impl<Storage: ComputeStorage> MemoryManagement<Storage>
impl<Storage: ComputeStorage> MemoryManagement<Storage>
Sourcepub fn from_configuration(
storage: Storage,
properties: &MemoryDeviceProperties,
config: MemoryConfiguration,
logger: Arc<ServerLogger>,
options: MemoryManagementOptions,
) -> Self
pub fn from_configuration( storage: Storage, properties: &MemoryDeviceProperties, config: MemoryConfiguration, logger: Arc<ServerLogger>, options: MemoryManagementOptions, ) -> Self
Creates the options from device limits.
Sourcepub fn mode(&mut self, mode: MemoryAllocationMode)
pub fn mode(&mut self, mode: MemoryAllocationMode)
Change the mode of allocation.
Windows nest: a Persistent or Dedicated call opens one, an
Auto call closes the innermost, and the innermost open window decides
the effective mode. Callers routinely nest without knowing it — a
module load opens a persistent window around the whole load while the
parameter machinery underneath opens one per parameter — and without
the stack, the first inner window’s exit would flip the rest of the
outer window back to Auto: weights landing in the dynamic pools,
where every page they sit on is held for the model’s whole life.
The persistent-memory config decides what a Persistent window puts in
force (Disabled and Enforced keep the configured mode); a
Dedicated window is honored whatever the config, since it exists to
keep a buffer out of every pool.
Sourcepub fn cleanup(&mut self, cleanup: Cleanup, failures: &mut ErrorGraph)
pub fn cleanup(&mut self, cleanup: Cleanup, failures: &mut ErrorGraph)
Cleanup allocations in pools that are deemed unnecessary.
Sourcepub fn get_cursor(&self, binding: ManagedMemoryBinding) -> Result<u64, IoError>
pub fn get_cursor(&self, binding: ManagedMemoryBinding) -> Result<u64, IoError>
Returns the storage from the specified binding
Sourcepub fn get_storage(
&mut self,
binding: ManagedMemoryBinding,
) -> Result<StorageHandle, IoError>
pub fn get_storage( &mut self, binding: ManagedMemoryBinding, ) -> Result<StorageHandle, IoError>
Returns the storage from the specified binding.
This is the funnel every buffer dereference passes through
(get_resource delegates here), so it is where
a lazily-carved allocation gets its real device backing: the handle
returned always refers to mapped memory.
Sourcepub fn bytes_allocated(&self) -> u64
pub fn bytes_allocated(&self) -> u64
The bytes this memory holds from the device right now, whatever pool holds them.
Sourcepub fn relocation_need(&self) -> RelocationNeed
pub fn relocation_need(&self) -> RelocationNeed
Whether emptying the outdated pools is wanted, before the bytes the device holds are known: only while something is outdated, when the arena is full or the device is short of room, and not again while the pools look as they did when the last relocation moved nothing.
Sourcepub fn has_outdated(&self) -> bool
pub fn has_outdated(&self) -> bool
Whether a growth left pages behind for a relocation to empty.
Sourcepub fn relocate(
&mut self,
copier: &mut dyn CopyQueue<Storage>,
reason: RelocationReason,
failures: &mut ErrorGraph,
)
pub fn relocate( &mut self, copier: &mut dyn CopyQueue<Storage>, reason: RelocationReason, failures: &mut ErrorGraph, )
Empty what the outdated pools hold into the current pages, so the
pages they held go back to the driver. reason decides whether a
target may take a new page.
Sourcepub fn guard(&mut self, location: MemoryLocation) -> Option<PageGuard>
pub fn guard(&mut self, location: MemoryLocation) -> Option<PageGuard>
Keep the page location names as it is for as long as the guard lives
(see PageGuard). None when no pool holds such a page.
Sourcepub fn managed_resource(
&mut self,
binding: ManagedMemoryBinding,
offset_start: Option<u64>,
offset_end: Option<u64>,
) -> Result<ManagedResource<Storage::Resource>, IoError>
pub fn managed_resource( &mut self, binding: ManagedMemoryBinding, offset_start: Option<u64>, offset_end: Option<u64>, ) -> Result<ManagedResource<Storage::Resource>, IoError>
The resource behind binding, holding the allocation’s binding for as
long as it lives: what a caller that keeps the raw address past this
call is handed. The binding keeps the allocation in place, and leaves
the rest of its page to other allocations.
Sourcepub fn get_resource(
&mut self,
binding: ManagedMemoryBinding,
offset_start: Option<u64>,
offset_end: Option<u64>,
) -> Result<Storage::Resource, IoError>
pub fn get_resource( &mut self, binding: ManagedMemoryBinding, offset_start: Option<u64>, offset_end: Option<u64>, ) -> Result<Storage::Resource, IoError>
Returns the resource from the storage at the specified handle
Sourcepub fn reserve(
&mut self,
size: u64,
update: PageUpdate,
failures: &mut ErrorGraph,
) -> Result<ManagedMemoryHandle, IoError>
pub fn reserve( &mut self, size: u64, update: PageUpdate, failures: &mut ErrorGraph, ) -> Result<ManagedMemoryHandle, IoError>
Reserve size bytes, changing the pages held only as far as update
allows.
§Errors
IoError::PageUpdateForbidden when update forbids a new page and
the room held cannot serve it, and whatever the pools or the device
refused otherwise.
Sourcepub fn storage(&mut self) -> &mut Storage
pub fn storage(&mut self) -> &mut Storage
Fetch the storage used by the memory manager.
§Notes
The storage should probably not be used for allocations since the handles won’t be compatible with the ones provided by the current trait. Prefer using the alloc and dealloc functions.
This is useful if you need to time the deallocations based on async computation, or to change the mode of storage for different reasons.
Sourcepub fn memory_report(&self) -> MemoryPoolsReport
pub fn memory_report(&self) -> MemoryPoolsReport
Everything this memory holds, pool by pool: each pool’s shape, usage
and high-water marks, the dynamic ones in allocation-routing order.
MemoryPoolsReport::usage sums them.
Sourcepub fn print_memory_usage(&self)
pub fn print_memory_usage(&self)
Print out a report of the current memory usage.
Sourcepub fn bind(
&mut self,
reserved: ManagedMemoryHandle,
assigned: ManagedMemoryHandle,
cursor: u64,
failures: &mut ErrorGraph,
) -> Result<(), IoError>
pub fn bind( &mut self, reserved: ManagedMemoryHandle, assigned: ManagedMemoryHandle, cursor: u64, failures: &mut ErrorGraph, ) -> Result<(), IoError>
Binds the given handle to a [MemorySlot].
Sourcepub fn failure(
&self,
binding: &ManagedMemoryBinding,
range: Range<u64>,
) -> Option<FailureId>
pub fn failure( &self, binding: &ManagedMemoryBinding, range: Range<u64>, ) -> Option<FailureId>
The failure claiming any byte of range in the allocation behind
binding, if one does.
This is the read path’s whole check: a field on a slice the resolution
walks anyway. A binding this manager does not hold answers None —
lookup errors are find’s to report, and a failed lookup
carries no failure to name.
Sourcepub fn taint(
&mut self,
binding: &ManagedMemoryBinding,
range: Range<u64>,
failure: FailureId,
failures: &mut ErrorGraph,
)
pub fn taint( &mut self, binding: &ManagedMemoryBinding, range: Range<u64>, failure: FailureId, failures: &mut ErrorGraph, )
Point range of the allocation behind binding at failure.
A binding this manager does not hold is left alone, for the same
reason failure answers None for one.
Sourcepub fn written(
&mut self,
binding: &ManagedMemoryBinding,
range: Range<u64>,
failures: &mut ErrorGraph,
)
pub fn written( &mut self, binding: &ManagedMemoryBinding, range: Range<u64>, failures: &mut ErrorGraph, )
range of the allocation behind binding has a writer again: release
every claim on those bytes — and only those bytes, since a partial
write says nothing about the rest of the buffer.
Trait Implementations§
Source§impl<Storage> Debug for MemoryManagement<Storage>
impl<Storage> Debug for MemoryManagement<Storage>
Auto Trait Implementations§
impl<Storage> Freeze for MemoryManagement<Storage>where
Storage: Freeze,
impl<Storage> RefUnwindSafe for MemoryManagement<Storage>where
Storage: RefUnwindSafe,
impl<Storage> Send for MemoryManagement<Storage>where
Storage: Send,
impl<Storage> Sync for MemoryManagement<Storage>where
Storage: Sync,
impl<Storage> Unpin for MemoryManagement<Storage>where
Storage: Unpin,
impl<Storage> UnsafeUnpin for MemoryManagement<Storage>where
Storage: UnsafeUnpin,
impl<Storage> UnwindSafe for MemoryManagement<Storage>where
Storage: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> ErasedDestructor for Twhere
T: 'static,
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 more