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.
Implementations§
Source§impl BufferAllocator
impl BufferAllocator
pub fn new(block_size: usize, source: BufferSource) -> Self
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 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.