Skip to main content

PinnedBufferAllocator

Struct PinnedBufferAllocator 

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

A specialized buffer allocator that pins memory in coarse chunks (e.g. 1 MiB) for DMA.

The first chunk (chunk 0) is pinned at initialization and remains pinned for the lifetime of the allocator to eliminate pinning latency on requests. Additional chunks are pinned dynamically on demand when buffers spill over into them, and unpinned when all buffers within those chunks are dropped.

This allocator relies on BufferAllocator’s lowest-offset-first allocation strategy so that allocations pack into the permanently pinned first chunk before spilling over into dynamically pinned chunks.

Implementations§

Source§

impl PinnedBufferAllocator

Source

pub fn new( block_size: usize, source: BufferSource, bti: Bti, contiguity: u64, ) -> Self

Creates a new PinnedBufferAllocator with default chunk size (1 MiB).

contiguity specifies the minimum physical address contiguity (in bytes) required by the hardware/BTI, which determines the granularity of entries in paddrs.

Source

pub fn with_chunk_size( block_size: usize, source: BufferSource, bti: Bti, contiguity: u64, chunk_size: usize, ) -> Self

Creates a new PinnedBufferAllocator with a custom chunk_size.

contiguity specifies the minimum physical address contiguity (in bytes) required by the hardware/BTI, which determines the granularity of entries in paddrs.

Source

pub fn block_size(&self) -> usize

Source

pub fn chunk_size(&self) -> usize

Source

pub fn contiguity(&self) -> u64

Source

pub fn buffer_source(&self) -> &BufferSource

Source

pub fn vmo(&self) -> Option<Arc<Vmo>>

Returns the underlying VMO for DMA operations.

Source

pub fn is_trusted(&self) -> bool

Source

pub fn clean_transfer_buffer(&self)

Decommits unallocated pages in the buffer so the kernel can reclaim memory.

Source

pub fn paddrs(&self, range: &Range<usize>) -> Option<(&[zx_paddr_t], u64)>

Returns a slice of physical addresses covering range and the contiguity granularity (in bytes) represented by each address in the slice.

Source

pub fn try_allocate_buffer( &self, size: usize, ) -> Result<PinnedBuffer<'_>, EventListener>

Source

pub fn allocate_buffer_sync(&self, size: usize) -> PinnedBuffer<'_>

Source

pub fn allocate_buffer(&self, size: usize) -> PinnedBufferFuture<'_>

Source

pub fn try_allocate_buffer_owned( self: &Arc<Self>, size: usize, ) -> Result<OwnedBuffer, EventListener>

Source

pub fn allocate_buffer_sync_owned(self: &Arc<Self>, size: usize) -> OwnedBuffer

Trait Implementations§

Source§

impl BufferAllocator for PinnedBufferAllocator

Source§

fn free_buffer(&self, range: Range<usize>)

Frees or reclaims the specified memory range.
Source§

fn identifier(&self) -> usize

Returns an identifier for this allocator based on its memory address.
Source§

fn is_trusted(&self) -> bool

Returns true if buffers produced by this allocator are trusted (unshared).
Source§

fn vmo(&self) -> Option<Arc<Vmo>>

Returns the underlying VMO if backed by a VMO and untrusted. Read more
Source§

fn paddrs(&self, range: &Range<usize>) -> Option<(&[zx_paddr_t], u64)>

Returns the physical addresses for range if pinned, along with the contiguity.
Source§

impl Debug for PinnedBufferAllocator

Source§

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

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

impl Drop for PinnedBufferAllocator

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for PinnedBufferAllocator

Source§

impl Sync for PinnedBufferAllocator

Source§

impl<'a> TryAllocateBuffer<'a> for PinnedBufferAllocator

Source§

type Buffer = BufferImpl<'a, &'a PinnedBufferAllocator, PinnedBufferAllocator>

Source§

fn try_allocate_buffer( &'a self, size: usize, ) -> Result<PinnedBuffer<'a>, EventListener>

Attempts to allocate a buffer of size bytes. Returns an EventListener to wait on if memory is temporarily unavailable.
Source§

fn allocate_buffer_sync(&'a self, size: usize) -> Self::Buffer

Allocates a buffer synchronously, blocking the current thread until memory is available.

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, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V