pub struct UmemPool { /* private fields */ }Expand description
Pre-allocated page-aligned shared memory pool for AF_XDP kernel-bypass I/O.
Implementations§
Source§impl UmemPool
impl UmemPool
Sourcepub fn new(num_chunks: usize, chunk_size: usize) -> Result<Self>
pub fn new(num_chunks: usize, chunk_size: usize) -> Result<Self>
Allocates an anonymous, page-aligned shared memory region for num_chunks chunks
of size chunk_size with default pre-faulting (MAP_POPULATE) enabled.
Sourcepub fn new_lazy(num_chunks: usize, chunk_size: usize) -> Result<Self>
pub fn new_lazy(num_chunks: usize, chunk_size: usize) -> Result<Self>
Allocates a new UmemPool with lazy on-demand page allocation (MAP_POPULATE disabled),
minimizing startup latency and initial RSS footprint.
Sourcepub fn with_config(config: UmemPoolConfig) -> Result<Self>
pub fn with_config(config: UmemPoolConfig) -> Result<Self>
Allocates a new UmemPool according to the provided UmemPoolConfig.
Sourcepub fn alloc_chunk(&mut self) -> Option<u64>
pub fn alloc_chunk(&mut self) -> Option<u64>
Allocates a chunk address from the free pool, returning None if exhausted.
Sourcepub fn free_chunk(&mut self, addr: u64)
pub fn free_chunk(&mut self, addr: u64)
Returns a chunk address to the free pool.
Sourcepub fn chunk_slice(&self, addr: u64, len: usize) -> &[u8] ⓘ
pub fn chunk_slice(&self, addr: u64, len: usize) -> &[u8] ⓘ
Returns a bounds-checked immutable slice into the chunk starting at addr.
Sourcepub fn chunk_slice_mut(&mut self, addr: u64, len: usize) -> &mut [u8] ⓘ
pub fn chunk_slice_mut(&mut self, addr: u64, len: usize) -> &mut [u8] ⓘ
Returns a bounds-checked mutable slice into the chunk starting at addr.
Sourcepub fn chunk_size(&self) -> usize
pub fn chunk_size(&self) -> usize
Chunk size in bytes.
Sourcepub fn free_chunk_count(&self) -> usize
pub fn free_chunk_count(&self) -> usize
Number of free chunks currently available in the pool.
Sourcepub fn is_valid_chunk_addr(&self, addr: u64) -> bool
pub fn is_valid_chunk_addr(&self, addr: u64) -> bool
Returns true if addr is an aligned chunk address within this pool’s bounds.
Sourcepub fn create_slabs(self: &Arc<Self>, num_slabs: usize) -> Result<Vec<UmemSlab>>
pub fn create_slabs(self: &Arc<Self>, num_slabs: usize) -> Result<Vec<UmemSlab>>
Partitions an Arc<UmemPool> into num_slabs disjoint, per-core chunk slabs.
Each slab receives an equal partition of chunks (total_chunks / num_slabs).
Slabs operate completely independently without shared locks or cross-core
cache line contention.
Sourcepub fn new_slabs(
num_chunks: usize,
chunk_size: usize,
num_slabs: usize,
) -> Result<(Arc<Self>, Vec<UmemSlab>)>
pub fn new_slabs( num_chunks: usize, chunk_size: usize, num_slabs: usize, ) -> Result<(Arc<Self>, Vec<UmemSlab>)>
Allocates a new UmemPool with default configuration and partitions it into num_slabs disjoint slabs.
Sourcepub fn new_slabs_with_config(
config: UmemPoolConfig,
num_slabs: usize,
) -> Result<(Arc<Self>, Vec<UmemSlab>)>
pub fn new_slabs_with_config( config: UmemPoolConfig, num_slabs: usize, ) -> Result<(Arc<Self>, Vec<UmemSlab>)>
Allocates a new UmemPool using the specified UmemPoolConfig and partitions it into num_slabs disjoint slabs.