Skip to main content

MemPool

Struct MemPool 

Source
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

Source

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 pool
  • size - Size of each entry in bytes (0 defaults to 2048)
§Returns

An Arc-wrapped MemPool that can be shared across packet buffers.

§Errors
§Panics

Panics if size is not a divisor of the huge page size (2MB).

Source

pub fn entry_size(&self) -> usize

Returns the size (in bytes) of each entry in the pool.

Source

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§

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

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.