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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MbufPool
impl !RefUnwindSafe for MbufPool
impl Send for MbufPool
impl Sync for MbufPool
impl Unpin for MbufPool
impl UnsafeUnpin for MbufPool
impl !UnwindSafe for MbufPool
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.