pub struct MemPool { /* private fields */ }Expand description
A memory pool for efficient DMA-capable buffer allocation.
The memory pool pre-allocates a fixed number of equally-sized buffers from DMA-capable memory. This design ensures that:
- All buffers are physically contiguous and accessible by the NIC
- Allocation is fast (O(1) simple stack pop)
- Memory fragmentation is avoided
§Thread Safety
The memory pool uses interior mutability via RefCell and can be safely
shared between threads.
§Example
ⓘ
use ixgbe_driver::memory::MemPool;
// Create a pool with 4096 entries of 2048 bytes each
let pool = MemPool::allocate::<MyHal>(4096, 2048)?;
// Get the entry size
assert_eq!(pool.entry_size(), 2048);Implementations§
Source§impl MemPool
impl MemPool
Sourcepub fn allocate<H: IxgbeHal>(
entries: usize,
size: usize,
) -> IxgbeResult<Arc<MemPool>>
pub fn allocate<H: IxgbeHal>( entries: usize, size: usize, ) -> IxgbeResult<Arc<MemPool>>
Allocates a new memory pool.
Creates a memory pool with the specified number of entries, each of the given size. The entry size must divide the huge page size (2MB) evenly.
§Arguments
entries- Number of buffer entries in the poolsize- Size of each entry in bytes (0 defaults to 2048)
§Returns
An Arc-wrapped MemPool that can be shared across packet buffers.
§Errors
IxgbeError::PageNotAligned- Ifsizeis not a divisor of the page sizeIxgbeError::NoMemory- If DMA allocation fails
§Panics
Panics if size is not a divisor of the huge page size (2MB).
Sourcepub fn entry_size(&self) -> usize
pub fn entry_size(&self) -> usize
Returns the size (in bytes) of each entry in the pool.
Sourcepub fn get_phys_addr(&self, id: usize) -> usize
pub fn get_phys_addr(&self, id: usize) -> usize
Returns the physical address of a buffer from the memory pool.
This address can be passed to the NIC hardware for DMA operations.
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