Expand description
§buffer_sv2
Handles memory management for Stratum V2 (Sv2) roles.
Provides a memory-efficient buffer pool (BufferPool
) that minimizes allocations and
deallocations for high-throughput message frame processing in Sv2 roles. Slice
helps
minimize memory allocation overhead by reusing large buffers, improving performance and
reducing latency. The BufferPool
tracks the usage of memory slices, using atomic operations
and shared state tracking to safely manage memory across multiple threads.
§Memory Structure
The BufferPool
manages a contiguous block of memory allocated on the heap, divided into
fixed-size slots. Memory allocation within this pool operates in three distinct modes:
- Back Mode: By default, memory is allocated sequentially from the back (end) of the buffer pool. This mode continues until the back slots are fully occupied.
- Front Mode: Once the back slots are exhausted, the
BufferPool
checks if any slots at the front (beginning) have been freed. If available, it switches to front mode, allocating memory from the front slots. - Alloc Mode: If both back and front slots are occupied, the
BufferPool
enters alloc mode, where it allocates additional memory directly from the system heap. This mode may introduce performance overhead due to dynamic memory allocation.
BufferPool
dynamically transitions between these modes based on slot availability,
optimizing memory usage and performance.
§Usage
When an incoming Sv2 message is received, it is buffered for processing. The BufferPool
attempts to allocate memory from its internal slots, starting in back mode. If the back slots
are full, it checks for available front slots to switch to front mode. If no internal slots are
free, it resorts to alloc mode, allocating memory from the system heap.
For operations requiring dedicated buffers, the Slice
type manages its own memory using
Vec<u8>
. In high-performance scenarios, Slice
can reference externally managed memory
from the BufferPool
, reducing dynamic memory allocations and increasing performance.
§Debug Mode
Provides additional tracking for debugging memory management issues.
Structs§
- Buffer
From System Memory - Manages a dynamically growing buffer in system memory using an internal
Vec<u8>
. - Buffer
Pool - A pool of reusable memory buffers to optimize memory allocation for Sv2 message frames.
- Slice
- A contiguous block of memory, either preallocated or dynamically allocated.
Enums§
- Write
Error - Represents errors that can occur while writing data into a buffer.
Traits§
- Aead
Buffer - In-place encryption/decryption byte buffers.
- Buffer
- Interface for working with memory buffers.
- Write
- Interface for writing data into a buffer.