pub struct MbufPool { /* private fields */ }Expand description
Free-list backed mbuf pool.
The pool keeps a parking-lot mutex around a stash of recyclable
chunk allocations. New chunks are taken from the stash if available
and freshly allocated otherwise. MbufPool::put returns chunks
to the stash up to MBUF_POOL_MAX_FREE; chunks beyond that cap
are dropped.
The pool tracks total live and free counts for diagnostics, mirroring
the C mbuf_alloc_get_count / mbuf_free_queue_size accessors.
Implementations§
Source§impl MbufPool
impl MbufPool
Sourcepub fn new(chunk_size: usize, max_free: usize) -> Self
pub fn new(chunk_size: usize, max_free: usize) -> Self
Construct a new pool with chunk_size byte chunks and a free
list capped at max_free. Mirrors mbuf_init plus the Rust-
only free-list bound.
§Examples
use dynomite::io::mbuf::{MbufPool, MBUF_SIZE, MBUF_POOL_MAX_FREE};
let pool = MbufPool::new(MBUF_SIZE, MBUF_POOL_MAX_FREE);
let buf = pool.get();
assert_eq!(buf.chunk_size(), MBUF_SIZE);
pool.put(buf);Sourcepub fn chunk_size(&self) -> usize
pub fn chunk_size(&self) -> usize
Configured chunk size, in bytes.
Sourcepub fn get(&self) -> Mbuf
pub fn get(&self) -> Mbuf
Take a fresh or recycled chunk from the pool. Mirrors
mbuf_get.
§Examples
use dynomite::io::mbuf::MbufPool;
let pool = MbufPool::default();
let buf = pool.get();
assert!(buf.is_empty());Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of chunks currently sitting in the free list. Mirrors
mbuf_free_queue_size.
Sourcepub fn total_allocated(&self) -> u64
pub fn total_allocated(&self) -> u64
Lifetime count of fresh allocations performed by the pool.
Mirrors mbuf_alloc_get_count. Useful for tests asserting
that recycling avoids the allocator path.