pub struct FramePool { /* private fields */ }Expand description
MTU-sized buffer pool for the virtio-net hot path.
Pins I-NET-4 (30-networking.md § 7):
frame allocation goes through a pool of pre-allocated BytesMut buffers
rather than vec![0u8; mtu] per-call. The pool is sized to MTU × 256 per
direction (the 71 § 5 bench-harness gating value); bursts beyond the pool
allocate fresh and are dropped on release rather than returned, so memory
pressure spikes are bounded.
The pool is Send + Sync; per-backend instances share their RX/TX pools
across the device thread and the host-side I/O thread without contention
(a parking_lot::Mutex<Vec<BytesMut>> is the boot-time-cheap, hot-path-
uncontended shape — RX or TX rarely interleave).
Implementations§
Source§impl FramePool
impl FramePool
Sourcepub fn new(mtu: usize, pool_capacity: usize) -> Self
pub fn new(mtu: usize, pool_capacity: usize) -> Self
Build a pool with pool_capacity slots, each mtu bytes wide.
Slots are allocated lazily on first acquire.
Sourcepub fn acquire(&self) -> BytesMut
pub fn acquire(&self) -> BytesMut
Acquire a buffer of at least mtu capacity. The buffer is empty
(len() == 0) on return; the caller fills it via BytesMut::extend_from_slice
or unsafe { set_len(_) } after a read writes into the spare capacity.
Sourcepub fn release(&self, buf: BytesMut)
pub fn release(&self, buf: BytesMut)
Return a buffer to the pool. Buffers beyond pool_capacity
are dropped, bounding memory pressure under burst.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of buffers currently in the free list (test/diagnostic).