pub struct BufferAllocator { /* private fields */ }Expand description
BufferAllocator creates Buffer objects to be used for block device I/O requests.
This is implemented through a simple buddy allocation scheme. Allocations always prioritize the lowest available offset (first-fit), packing allocations toward the beginning of the memory pool and reusing recently freed lower offsets.
Implementations§
Source§impl BufferAllocator
impl BufferAllocator
pub fn new(block_size: usize, source: BufferSource) -> Self
Sourcepub fn vmo(&self) -> Option<Arc<Vmo>>
pub fn vmo(&self) -> Option<Arc<Vmo>>
Returns the underlying VMO if the allocator is untrusted.
Returns None if is_trusted() is true, because exposing the VMO would allow
external modification of memory that is assumed to be unshared.
pub fn is_trusted(&self) -> bool
pub fn block_size(&self) -> usize
pub fn buffer_source(&self) -> &BufferSource
Sourcepub fn take_buffer_source(self) -> BufferSource
pub fn take_buffer_source(self) -> BufferSource
Takes the buffer source from the allocator and consumes the allocator.
Sourcepub fn identifier(&self) -> usize
pub fn identifier(&self) -> usize
Returns an identifier for this allocator based on its memory address.
Sourcepub fn allocate_buffer(&self, size: usize) -> BufferFuture<'_> ⓘ
pub fn allocate_buffer(&self, size: usize) -> BufferFuture<'_> ⓘ
Allocates a Buffer with capacity for size bytes. Blocks until there are enough bytes
available to satisfy the request.
The allocated buffer will be block-aligned and the padding up to block alignment can also be used by the buffer.
Allocation is O(lg(N) + M), where N = size and M = number of allocations.
§Panics
Panics if size exceeds the pool size (self.buffer_source().size()).
Sourcepub fn allocate_buffer_sync(&self, size: usize) -> Buffer<'_>
pub fn allocate_buffer_sync(&self, size: usize) -> Buffer<'_>
Allocates a Buffer with capacity for size bytes synchronously. Blocks the current thread
until enough memory is available.
§Panics
Panics if size exceeds the pool size (self.buffer_source().size()).
Sourcepub fn allocate_buffer_sync_owned(self: &Arc<Self>, size: usize) -> OwnedBuffer
pub fn allocate_buffer_sync_owned(self: &Arc<Self>, size: usize) -> OwnedBuffer
Allocates an OwnedBuffer with capacity for size bytes synchronously. Blocks the current
thread until enough memory is available.
§Panics
Panics if size exceeds the pool size (self.buffer_source().size()).
Sourcepub fn try_allocate_buffer_owned(
self: &Arc<Self>,
size: usize,
) -> Result<OwnedBuffer, EventListener>
pub fn try_allocate_buffer_owned( self: &Arc<Self>, size: usize, ) -> Result<OwnedBuffer, EventListener>
Allocates an OwnedBuffer non-blockingly, returning an EventListener if memory is unavailable.
§Panics
Panics if size exceeds the pool size (self.buffer_source().size()).
Sourcepub fn try_allocate_buffer(
&self,
size: usize,
) -> Result<Buffer<'_>, EventListener>
pub fn try_allocate_buffer( &self, size: usize, ) -> Result<Buffer<'_>, EventListener>
Like allocate_buffer, but returns an EventListener if the allocation cannot be satisfied.
The listener will signal when the caller should try again.
§Panics
Panics if size exceeds the pool size (self.buffer_source().size()).
Source§impl BufferAllocator
impl BufferAllocator
Sourcepub fn clean_transfer_buffer(&self)
pub fn clean_transfer_buffer(&self)
Zeroes out all unnallocated ranges in the transfer buffer.
Trait Implementations§
Source§impl BufferAllocator for BufferAllocator
impl BufferAllocator for BufferAllocator
Source§fn free_buffer(&self, range: Range<usize>)
fn free_buffer(&self, range: Range<usize>)
Source§fn is_trusted(&self) -> bool
fn is_trusted(&self) -> bool
Source§fn vmo(&self) -> Option<Arc<Vmo>>
fn vmo(&self) -> Option<Arc<Vmo>>
Source§fn identifier(&self) -> usize
fn identifier(&self) -> usize
Source§impl Debug for BufferAllocator
impl Debug for BufferAllocator
Source§impl<'a> TryAllocateBuffer<'a> for BufferAllocator
impl<'a> TryAllocateBuffer<'a> for BufferAllocator
type Buffer = BufferImpl<'a, &'a BufferAllocator, BufferAllocator>
Source§fn try_allocate_buffer(
&'a self,
size: usize,
) -> Result<Buffer<'a>, EventListener>
fn try_allocate_buffer( &'a self, size: usize, ) -> Result<Buffer<'a>, EventListener>
size bytes. Returns an EventListener to wait on if
memory is temporarily unavailable.