pub struct Mempool { /* private fields */ }Expand description
Memory pool for packet buffers
A mempool is a fixed-size pool of mbufs. All packet buffers in DPDK must be allocated from a mempool.
Implementations§
Source§impl Mempool
impl Mempool
Sourcepub fn create(
name: &str,
n: u32,
cache_size: u32,
data_room_size: u16,
socket_id: i32,
) -> DpdkResult<Self>
pub fn create( name: &str, n: u32, cache_size: u32, data_room_size: u16, socket_id: i32, ) -> DpdkResult<Self>
Create a new mempool for packet buffers
§Arguments
name- Unique name for this mempool (max 32 characters)n- Number of elements in the poolcache_size- Per-core cache size (0 to disable)data_room_size- Size of data buffer in each mbufsocket_id- NUMA socket ID (-1 for any)
§Errors
Returns an error if:
- The name is empty or too long
- The name contains null bytes
- DPDK mempool creation fails (e.g., out of memory, invalid parameters)
Sourcepub fn create_with_config(
name: &str,
config: &MempoolConfig,
) -> DpdkResult<Self>
pub fn create_with_config( name: &str, config: &MempoolConfig, ) -> DpdkResult<Self>
Create a new mempool with configuration
§Arguments
name- Unique name for this mempoolconfig- Mempool configuration
Sourcepub fn create_default(name: &str) -> DpdkResult<Self>
pub fn create_default(name: &str) -> DpdkResult<Self>
Create a mempool with default configuration
Sourcepub fn alloc(&self) -> DpdkResult<Mbuf>
pub fn alloc(&self) -> DpdkResult<Mbuf>
Allocate an mbuf from this pool
Sourcepub fn alloc_bulk(&self, count: usize) -> DpdkResult<Vec<Mbuf>>
pub fn alloc_bulk(&self, count: usize) -> DpdkResult<Vec<Mbuf>>
Allocate multiple mbufs from this pool in a batch
This is more efficient than calling alloc() multiple times.
Returns Ok with a vector of mbufs, or Err if allocation fails.
Sourcepub fn available_count(&self) -> u32
pub fn available_count(&self) -> u32
Get the number of free elements in the pool
Sourcepub fn in_use_count(&self) -> u32
pub fn in_use_count(&self) -> u32
Get the number of elements in use
Sourcepub fn as_raw(&self) -> *mut rte_mempool
pub fn as_raw(&self) -> *mut rte_mempool
Get the raw pointer to the mempool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mempool
impl RefUnwindSafe for Mempool
impl Unpin for Mempool
impl UnsafeUnpin for Mempool
impl UnwindSafe for Mempool
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
Mutably borrows from an owned value. Read more