Documentation
¶
Overview ¶
Package iobuf provides lock-free buffer pools and memory management utilities for high-performance I/O operations.
The package implements a 12-tier buffer size hierarchy and lock-free bounded pools optimized for zero-allocation hot paths. All pools use semantic error types from iox for non-blocking control flow.
Buffer Tiers ¶
Buffers are organized into 12 size tiers following a power-of-4 progression:
Tier Size Use Case ──── ──── ──────── Pico 32 B Tiny metadata, flags Nano 128 B Small headers, control frames Micro 512 B Protocol frames, small messages Small 2 KiB Typical network packets Medium 8 KiB Stream buffers, large packets Big 32 KiB TLS records, stream chunks Large 128 KiB io_uring buffer rings Great 512 KiB Large transfers Huge 2 MiB Huge page aligned buffers Vast 8 MiB Large file chunks Giant 32 MiB Video frames, datasets Titan 128 MiB Maximum allocation tier
Each tier has corresponding type aliases (e.g., SmallBuffer, LargeBuffer) and factory functions for bounded pools (e.g., NewSmallBufferPool).
Bounded Pool ¶
BoundedPool is a lock-free multi-producer multi-consumer (MPMC) pool based on the algorithm from "A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue" (Ruslan Nikolaev, 2019). Key characteristics:
- Lock-free: Uses atomic CAS operations, no mutexes
- Bounded: Fixed capacity rounded to power of two
- Memory-efficient: Single contiguous array, no per-element allocation
- Cache-optimized: Aligned to cache line boundaries to prevent false sharing
Indirect Pool Pattern ¶
Pools store indices (int) rather than buffer values directly. This enables:
- Zero-copy access via Value(indirect) method
- Efficient pool operations without moving large buffers
- Clear ownership semantics through index hand-off
Usage pattern:
pool := NewSmallBufferPool(100) // Creates pool with ~128 capacity
pool.Fill(NewSmallBuffer) // Initialize with buffer factory
idx, err := pool.Get() // Acquire buffer index
if err != nil {
// Handle iox.ErrWouldBlock (pool empty)
}
buf := pool.Value(idx) // Access buffer by index
// Use buf[:]...
pool.Put(idx) // Return buffer to pool
Page-Aligned Memory ¶
For DMA and io_uring operations requiring page alignment:
mem := AlignedMem(4096, PageSize) // Returns page-aligned []byte block := AlignedMemBlock() // Single page using default PageSize blocks := AlignedMemBlocks(16, PageSize) // Multiple aligned blocks
Vectored I/O ¶
IoVec provides scatter/gather I/O support for readv/writev syscalls:
buffers := make([]SmallBuffer, 8) iovecs := IoVecFrom(buffers) addr, n := IoVecAddrLen(iovecs) // Get pointer for syscall
Architecture Requirements ¶
This package requires a 64-bit CPU architecture (amd64, arm64, riscv64, loong64, ppc64, ppc64le, s390x, mips64, mips64le). 32-bit architectures are not supported due to 64-bit atomic operations in BoundedPool.
Thread Safety ¶
All pool operations are safe for concurrent use. BoundedPool supports multiple concurrent producers and consumers without external synchronization.
Dependencies ¶
iobuf depends on:
- iox: Semantic error types (ErrWouldBlock, ErrMore)
- spin: Spinlock and spin-wait primitives for backpressure
Index ¶
- Constants
- Variables
- func AlignedMem(size int, pageSize uintptr) []byte
- func AlignedMemBlock() []byte
- func AlignedMemBlocks(n int, pageSize uintptr) (blocks [][]byte)
- func ArrayFromSlice[T BufferType](s []byte, offset int64) T
- func BufferSizeFor(size int) int
- func CacheLineAlignedMem(size int) []byte
- func CacheLineAlignedMemBlocks(n int, blockSize int) (blocks [][]byte)
- func IoVecAddrLen(vec []IoVec) (addr uintptr, n int)
- func SetPageSize(size int)
- func SliceOfArray[T BufferType](s []byte, offset int64, n int) []T
- type BigBuffer
- type BigBufferBoundedPool
- type BigBufferPool
- type BoundedPool
- func (pool *BoundedPool[T]) Cap() int
- func (pool *BoundedPool[T]) Fill(newFunc func() T)
- func (pool *BoundedPool[T]) Get() (indirect int, err error)
- func (pool *BoundedPool[T]) Put(indirect int) error
- func (pool *BoundedPool[T]) SetNonblock(nonblocking bool)
- func (pool *BoundedPool[T]) SetValue(indirect int, value T)
- func (pool *BoundedPool[T]) Value(indirect int) T
- type BoundedPoolItem
- type BufferTier
- type BufferType
- type Buffers
- type GiantBuffer
- type GiantBufferBoundedPool
- type GiantBufferPool
- type GreatBuffer
- type GreatBufferBoundedPool
- type GreatBufferPool
- type HugeBuffer
- type HugeBufferBoundedPool
- type HugeBufferPool
- type IndirectPool
- type IoVec
- type LargeBuffer
- type LargeBufferBoundedPool
- type LargeBufferPool
- type MediumBuffer
- type MediumBufferBoundedPool
- type MediumBufferPool
- type MicroBuffer
- type MicroBufferBoundedPool
- type MicroBufferPool
- type NanoBuffer
- type NanoBufferBoundedPool
- type NanoBufferPool
- type PicoBuffer
- type PicoBufferBoundedPool
- type PicoBufferPool
- type Pool
- type RegisterBuffer
- type RegisterBufferPool
- type SmallBuffer
- type SmallBufferBoundedPool
- type SmallBufferPool
- type TitanBuffer
- type TitanBufferBoundedPool
- type TitanBufferPool
- type VastBuffer
- type VastBufferBoundedPool
- type VastBufferPool
Constants ¶
const ( BufferSizePico = 1 << 5 // 32 B - tiny metadata, flags BufferSizeNano = 1 << 7 // 128 B - small structs, headers BufferSizeMicro = 1 << 9 // 512 B - protocol frames BufferSizeSmall = 1 << 11 // 2 KiB - small messages BufferSizeMedium = 1 << 13 // 8 KiB - stream buffers BufferSizeBig = 1 << 15 // 32 KiB - TLS records BufferSizeLarge = 1 << 17 // 128 KiB - io_uring buffers BufferSizeGreat = 1 << 19 // 512 KiB - large transfers BufferSizeHuge = 1 << 21 // 2 MiB - huge pages BufferSizeVast = 1 << 23 // 8 MiB - large file chunks BufferSizeGiant = 1 << 25 // 32 MiB - video frames BufferSizeTitan = 1 << 27 // 128 MiB - maximum buffer tier )
Buffer size tiers follow a power-of-4 progression starting at 32 bytes. Each tier is 4x the previous size, optimized for different I/O patterns. 12 tiers: 32B, 128B, 512B, 2KiB, 8KiB, 32KiB, 128KiB, 512KiB, 2MiB, 8MiB, 32MiB, 128MiB
const CacheLineSize = internal.CacheLineSize
CacheLineSize is the CPU L1 cache line size for the current architecture. This is detected at compile time based on the target architecture:
- amd64: 64 bytes (Intel/AMD)
- arm64: 128 bytes (conservative for Apple Silicon)
- riscv64: 64 bytes
- loong64: 64 bytes
- others: 64 bytes (default)
Variables ¶
var PageSize uintptr = 4096
PageSize is the memory page size used for aligned allocations.
The default value (4 KiB) matches the typical x86-64 and ARM64 page size. Use SetPageSize to configure for systems with different page sizes.
Functions ¶
func AlignedMem ¶
AlignedMem returns a byte slice with the specified size and starting address aligned to the memory page size.
This is useful for DMA operations and io_uring registered buffers that require page-aligned memory addresses.
The returned slice shares underlying memory with a larger allocation; do not assume len(result) == cap(result).
func AlignedMemBlock ¶
func AlignedMemBlock() []byte
AlignedMemBlock returns a single page-aligned block using the system page size.
This is a convenience function equivalent to AlignedMemBlocks(1, PageSize)[0].
func AlignedMemBlocks ¶
AlignedMemBlocks returns n page-aligned byte slices, each of length pageSize.
All returned slices share a single contiguous underlying allocation, which is more memory-efficient than calling AlignedMem n times.
Panics if n < 1.
func ArrayFromSlice ¶ added in v0.3.0
func ArrayFromSlice[T BufferType](s []byte, offset int64) T
ArrayFromSlice returns a buffer of type T by copying from the slice at the given offset.
The caller must ensure offset+unsafe.Sizeof(T{}) <= len(s). The returned array is a copy, not a view of the underlying slice.
func BufferSizeFor ¶ added in v0.2.0
BufferSizeFor returns the smallest buffer size that can hold 'size' bytes. This is a convenience function equivalent to TierBySize(size).Size().
func CacheLineAlignedMem ¶ added in v0.2.0
CacheLineAlignedMem returns a byte slice with the specified size and starting address aligned to the CPU cache line size. This is useful for preventing false sharing in concurrent data structures.
func CacheLineAlignedMemBlocks ¶ added in v0.2.0
CacheLineAlignedMemBlocks returns n cache-line-aligned byte slices, each of length blockSize. Adjacent blocks are separated by cache line boundaries to prevent false sharing.
func IoVecAddrLen ¶
IoVecAddrLen extracts the raw pointer and length from an IoVec slice for direct syscall consumption (readv, writev, io_uring submission).
Returns (0, 0) for empty or nil slices.
func SetPageSize ¶
func SetPageSize(size int)
SetPageSize updates the package-level page size used for aligned allocations.
This should be called once during initialization, before any calls to AlignedMem or AlignedMemBlocks. Common values:
- 4096 (4 KiB): Standard x86-64, ARM64
- 16384 (16 KiB): Some ARM64 configurations (Apple Silicon)
- 65536 (64 KiB): Some embedded systems
func SliceOfArray ¶ added in v0.3.0
func SliceOfArray[T BufferType](s []byte, offset int64, n int) []T
SliceOfArray returns a slice of n buffers of type T viewed from the underlying slice.
The returned slice references the same memory as s[offset:]; modifications to either will be visible in both. The caller must ensure:
- offset + n*unsafe.Sizeof(T{}) <= len(s)
- n >= 1 (panics otherwise)
Types ¶
type BigBuffer ¶ added in v0.2.0
type BigBuffer [BufferSizeBig]byte
BigBuffer is a 32 KiB buffer for TLS records.
func NewBigBuffer ¶ added in v0.2.0
func NewBigBuffer() BigBuffer
NewBigBuffer returns a zero-initialized BigBuffer.
type BigBufferBoundedPool ¶ added in v0.2.0
type BigBufferBoundedPool = BoundedPool[BigBuffer]
BigBufferBoundedPool implements a bounded MPMC pool for 32 KiB buffers.
func NewBigBufferPool ¶ added in v0.2.0
func NewBigBufferPool(capacity int) *BigBufferBoundedPool
NewBigBufferPool creates a new instance of BigBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type BigBufferPool ¶ added in v0.2.0
type BigBufferPool = IndirectPool[BigBuffer]
BigBufferPool manages 32 KiB buffers via indirect indexing.
type BoundedPool ¶
type BoundedPool[T BoundedPoolItem] struct { // contains filtered or unexported fields }
BoundedPool is a generic type that represents a bounded pool of items of type T. The pool has a bounded and fixed capacity and allows items to be retrieved and returned. If the pool is empty and the non-blocking mode is not set, Get() calls would block until an item is available. If the pool is full and the non-blocking mode is not set, Put() calls would block until the BoundedPool is no longer full. BoundedPool is safe for concurrent use. The Get() and Put() methods ensure that at least one of the goroutines makes progress. The implementation of BoundedPool is based on the algorithms in the following paper:
https://nikitakoval.org/publications/ppopp20-queues.pdf
Usage:
pool := NewBoundedPool[ItemType](capacity) creates a new instance of BoundedPool with the specified capacity. pool.Fill(newFunc) initializes and fills the pool with a function to create new items. pool.SetNonblock(nonblocking) enables or disables the non-blocking mode of the pool. pool.Value(indirect) returns the item at the specified indirect index. pool.SetValue(indirect, val) sets the value of the item at the specified indirect index in pool. pool.Get() retrieves an item from the pool and returns its indirect index. pool.Put(indirect) puts the indirect index of an item back into the pool.
func NewBoundedPool ¶
func NewBoundedPool[ItemType BoundedPoolItem](capacity int) *BoundedPool[ItemType]
NewBoundedPool creates a lock-free bounded pool with the specified capacity.
The capacity is rounded up to the next power of two for efficient index calculation. The actual capacity can be retrieved via Cap().
Panics if capacity < 1 or capacity > math.MaxUint32.
After creation, Fill must be called before Get/Put operations.
func (*BoundedPool[T]) Cap ¶
func (pool *BoundedPool[T]) Cap() int
Cap returns the actual capacity of the BoundedPool.
This may be larger than the requested capacity due to power-of-two rounding.
func (*BoundedPool[T]) Fill ¶
func (pool *BoundedPool[T]) Fill(newFunc func() T)
Fill initializes and fills the BoundedPool with a newFunc function, which is used to create new items. Fill Put capacity items with new BoundedPoolItem created by newFunc for each item in the pool.
Example:
pool := NewBoundedPool[ItemType](capacity) pool.Fill(newFunc)
Parameters:
newFunc - a function that returns an instance of an item to be added to the pool.
func (*BoundedPool[T]) Get ¶
func (pool *BoundedPool[T]) Get() (indirect int, err error)
Get retrieves an item from the pool and returns its indirect index. If an item is available, its indirect index and a nil error are returned. Returns iox.ErrWouldBlock if the pool is empty and nonblocking mode is set.
In blocking mode, Get uses adaptive waiting (iox.Backoff) when the pool is empty. This acknowledges that buffer exhaustion is an external I/O event—buffers are released when the kernel/network finishes processing— requiring OS-level sleep rather than hardware-level spin.
func (*BoundedPool[T]) Put ¶
func (pool *BoundedPool[T]) Put(indirect int) error
Put puts the indirect index of an item back into the BoundedPool. It tries to put the given indirect index into the pool and returns nil error if successful. If the BoundedPool is currently full, it would block until the item can be put into the pool or return iox.ErrWouldBlock if the pool is nonblocking.
In blocking mode, Put uses adaptive waiting (iox.Backoff) when the pool is full. This acknowledges that pool capacity is freed by external consumers completing their I/O operations.
func (*BoundedPool[T]) SetNonblock ¶
func (pool *BoundedPool[T]) SetNonblock(nonblocking bool)
SetNonblock enables or disables the non-blocking mode of the pool. When nonblocking is set to true, Get() and Put() calls will not block and return immediately. When nonblocking is set to false, Get() calls will block until an item is available, and Put() calls will block until the pool is no longer full.
Example:
pool := NewBoundedPool[ItemType](capacity) pool.SetNonblock(true)
SetNonblock must be called during the initialization phase, before the pool is shared across goroutines. It is not safe for concurrent use.
Parameters:
nonblocking - determines whether the pool operates in non-blocking mode (true) or blocking mode (false).
func (*BoundedPool[T]) SetValue ¶
func (pool *BoundedPool[T]) SetValue(indirect int, value T)
SetValue sets the value of the item at the specified indirect index in the BoundedPool. The given indirect index must not be marked as empty and must be within the valid range.
func (*BoundedPool[T]) Value ¶
func (pool *BoundedPool[T]) Value(indirect int) T
Value returns the item at the specified indirect index. The given indirect index must not be marked as empty and must be within the valid range.
type BoundedPoolItem ¶
type BoundedPoolItem = any
BoundedPoolItem is a type constraint for items stored in a BoundedPool.
Any type can satisfy this constraint. The alias exists to make the generic type parameter explicit and to allow future extension.
type BufferTier ¶ added in v0.2.0
type BufferTier int
BufferTier represents a buffer tier index in the 12-tier system.
const ( TierPico BufferTier = iota TierNano TierMicro TierSmall TierMedium TierBig TierLarge TierGreat TierHuge TierVast TierGiant TierTitan TierEnd // Sentinel marking end of tiers )
Buffer tier indices for the 12-tier buffer system.
func TierBySize ¶ added in v0.2.0
func TierBySize(size int) BufferTier
TierBySize returns the smallest buffer tier that can hold 'size' bytes. Returns TierTitan for sizes larger than BufferSizeTitan.
func (BufferTier) Size ¶ added in v0.2.0
func (t BufferTier) Size() int
Size returns the buffer size for this tier.
type BufferType ¶
type BufferType interface {
PicoBuffer | NanoBuffer | MicroBuffer | SmallBuffer | MediumBuffer |
BigBuffer | LargeBuffer | GreatBuffer | HugeBuffer | VastBuffer |
GiantBuffer | TitanBuffer
}
BufferType is a type constraint for tiered buffer types.
type Buffers ¶
Buffers is an alias for net.Buffers, providing a standard way to group multiple byte slices for vectored I/O operations.
func NewBuffers ¶
NewBuffers creates a Buffers slice containing n byte slices, each of length size.
Returns an empty Buffers if n < 1. Each inner slice is independently allocated; for contiguous memory, use AlignedMemBlocks instead.
type GiantBuffer ¶
type GiantBuffer [BufferSizeGiant]byte
GiantBuffer is a 32 MiB buffer for video frames and datasets.
func NewGiantBuffer ¶
func NewGiantBuffer() GiantBuffer
NewGiantBuffer returns a zero-initialized GiantBuffer.
func (GiantBuffer) Reset ¶
func (b GiantBuffer) Reset()
type GiantBufferBoundedPool ¶
type GiantBufferBoundedPool = BoundedPool[GiantBuffer]
GiantBufferBoundedPool implements a bounded MPMC pool for 32 MiB buffers.
func NewGiantBufferPool ¶
func NewGiantBufferPool(capacity int) *GiantBufferBoundedPool
NewGiantBufferPool creates a new instance of GiantBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type GiantBufferPool ¶
type GiantBufferPool = IndirectPool[GiantBuffer]
GiantBufferPool manages 32 MiB buffers via indirect indexing.
type GreatBuffer ¶ added in v0.2.0
type GreatBuffer [BufferSizeGreat]byte
GreatBuffer is a 512 KiB buffer for large transfers.
func NewGreatBuffer ¶ added in v0.2.0
func NewGreatBuffer() GreatBuffer
NewGreatBuffer returns a zero-initialized GreatBuffer.
func (GreatBuffer) Reset ¶ added in v0.2.0
func (b GreatBuffer) Reset()
type GreatBufferBoundedPool ¶ added in v0.2.0
type GreatBufferBoundedPool = BoundedPool[GreatBuffer]
GreatBufferBoundedPool implements a bounded MPMC pool for 512 KiB buffers.
func NewGreatBufferPool ¶ added in v0.2.0
func NewGreatBufferPool(capacity int) *GreatBufferBoundedPool
NewGreatBufferPool creates a new instance of GreatBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type GreatBufferPool ¶ added in v0.2.0
type GreatBufferPool = IndirectPool[GreatBuffer]
GreatBufferPool manages 512 KiB buffers via indirect indexing.
type HugeBuffer ¶
type HugeBuffer [BufferSizeHuge]byte
HugeBuffer is a 2 MiB buffer matching huge page sizes.
func NewHugeBuffer ¶
func NewHugeBuffer() HugeBuffer
NewHugeBuffer returns a zero-initialized HugeBuffer.
func (HugeBuffer) Reset ¶
func (b HugeBuffer) Reset()
type HugeBufferBoundedPool ¶
type HugeBufferBoundedPool = BoundedPool[HugeBuffer]
HugeBufferBoundedPool implements a bounded MPMC pool for 2 MiB buffers.
func NewHugeBufferPool ¶
func NewHugeBufferPool(capacity int) *HugeBufferBoundedPool
NewHugeBufferPool creates a new instance of HugeBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type HugeBufferPool ¶
type HugeBufferPool = IndirectPool[HugeBuffer]
HugeBufferPool manages 2 MiB buffers via indirect indexing.
type IndirectPool ¶
type IndirectPool[T BufferType] interface { Pool[int] // Value returns the buffer associated with the given indirect index. // The caller must have acquired this index via Get. Value(indirect int) T // SetValue updates the buffer at the specified indirect index. // The caller must have acquired this index via Get. SetValue(indirect int, item T) }
IndirectPool manages items by index rather than by value, enabling zero-copy access to pooled buffers.
The pool stores buffer indices (int) rather than buffer values directly. This design allows:
- Zero-copy buffer access via Value() without moving large buffers
- Efficient pool operations (only small integers are enqueued/dequeued)
- Clear ownership semantics through index hand-off
Usage pattern:
idx, _ := pool.Get() // Acquire buffer index buf := pool.Value(idx) // Access buffer by index // Use buf[:]... pool.Put(idx) // Return buffer to pool
type IoVec ¶
type IoVec struct {
Base *byte // Starting address of the memory block
Len uint64 // Number of bytes to transfer
}
IoVec represents a scatter/gather I/O descriptor compatible with the standard Linux struct iovec. It is used to pass multiple non-contiguous user-space buffers to the kernel in a single vectored I/O system call (readv, writev, preadv, pwritev, io_uring operations).
Memory layout matches the C struct iovec exactly:
struct iovec {
void *iov_base; // Starting address
size_t iov_len; // Number of bytes
};
The caller must ensure Base points to valid memory for the lifetime of any I/O operation using this IoVec.
func IoVecFrom ¶ added in v0.3.0
func IoVecFrom[T BufferType](buffers []T) []IoVec
IoVecFrom converts a slice of typed buffers to an IoVec slice. The returned IoVec elements point directly to the buffer memory without copying.
func IoVecFromBytesSlice ¶
IoVecFromBytesSlice converts a slice of byte slices to an IoVec slice suitable for vectored I/O and io_uring buffer registration.
The caller must ensure the input byte slices remain valid for the lifetime of any I/O operation using the returned IoVec slice.
func IoVecFromRegisteredBuffers ¶
func IoVecFromRegisteredBuffers(buffers []RegisterBuffer) []IoVec
IoVecFromRegisteredBuffers converts a slice of RegisterBuffer to an IoVec slice. The returned IoVec elements point directly to the buffer memory without copying.
type LargeBuffer ¶
type LargeBuffer [BufferSizeLarge]byte
LargeBuffer is a 128 KiB buffer for io_uring buffer rings.
func NewLargeBuffer ¶
func NewLargeBuffer() LargeBuffer
NewLargeBuffer returns a zero-initialized LargeBuffer.
func (LargeBuffer) Reset ¶
func (b LargeBuffer) Reset()
type LargeBufferBoundedPool ¶
type LargeBufferBoundedPool = BoundedPool[LargeBuffer]
LargeBufferBoundedPool implements a bounded MPMC pool for 128 KiB buffers.
func NewLargeBufferPool ¶
func NewLargeBufferPool(capacity int) *LargeBufferBoundedPool
NewLargeBufferPool creates a new instance of LargeBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type LargeBufferPool ¶
type LargeBufferPool = IndirectPool[LargeBuffer]
LargeBufferPool manages 128 KiB buffers via indirect indexing.
type MediumBuffer ¶
type MediumBuffer [BufferSizeMedium]byte
MediumBuffer is an 8 KiB buffer for stream buffers.
func NewMediumBuffer ¶
func NewMediumBuffer() MediumBuffer
NewMediumBuffer returns a zero-initialized MediumBuffer.
func (MediumBuffer) Reset ¶
func (b MediumBuffer) Reset()
type MediumBufferBoundedPool ¶
type MediumBufferBoundedPool = BoundedPool[MediumBuffer]
MediumBufferBoundedPool implements a bounded MPMC pool for 8 KiB buffers.
func NewMediumBufferPool ¶
func NewMediumBufferPool(capacity int) *MediumBufferBoundedPool
NewMediumBufferPool creates a new instance of MediumBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type MediumBufferPool ¶
type MediumBufferPool = IndirectPool[MediumBuffer]
MediumBufferPool manages 8 KiB buffers via indirect indexing.
type MicroBuffer ¶
type MicroBuffer [BufferSizeMicro]byte
MicroBuffer is a 512-byte buffer for protocol frames.
func NewMicroBuffer ¶
func NewMicroBuffer() MicroBuffer
NewMicroBuffer returns a zero-initialized MicroBuffer.
func (MicroBuffer) Reset ¶
func (b MicroBuffer) Reset()
type MicroBufferBoundedPool ¶
type MicroBufferBoundedPool = BoundedPool[MicroBuffer]
MicroBufferBoundedPool implements a bounded MPMC pool for 512-byte buffers.
func NewMicroBufferPool ¶
func NewMicroBufferPool(capacity int) *MicroBufferBoundedPool
NewMicroBufferPool creates a new instance of MicroBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type MicroBufferPool ¶
type MicroBufferPool = IndirectPool[MicroBuffer]
MicroBufferPool manages 512-byte buffers via indirect indexing.
type NanoBuffer ¶
type NanoBuffer [BufferSizeNano]byte
NanoBuffer is a 128-byte buffer for small structs and headers.
func NewNanoBuffer ¶
func NewNanoBuffer() NanoBuffer
NewNanoBuffer returns a zero-initialized NanoBuffer.
func (NanoBuffer) Reset ¶
func (b NanoBuffer) Reset()
type NanoBufferBoundedPool ¶
type NanoBufferBoundedPool = BoundedPool[NanoBuffer]
NanoBufferBoundedPool implements a bounded MPMC pool for 128-byte buffers.
func NewNanoBufferPool ¶
func NewNanoBufferPool(capacity int) *NanoBufferBoundedPool
NewNanoBufferPool creates a new instance of NanoBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type NanoBufferPool ¶
type NanoBufferPool = IndirectPool[NanoBuffer]
NanoBufferPool manages 128-byte buffers via indirect indexing.
type PicoBuffer ¶
type PicoBuffer [BufferSizePico]byte
PicoBuffer is a 32-byte buffer for tiny metadata and flags.
func NewPicoBuffer ¶
func NewPicoBuffer() PicoBuffer
NewPicoBuffer returns a zero-initialized PicoBuffer.
func (PicoBuffer) Reset ¶
func (b PicoBuffer) Reset()
type PicoBufferBoundedPool ¶
type PicoBufferBoundedPool = BoundedPool[PicoBuffer]
PicoBufferBoundedPool implements a bounded MPMC pool for 32-byte buffers.
func NewPicoBufferPool ¶
func NewPicoBufferPool(capacity int) *PicoBufferBoundedPool
NewPicoBufferPool creates a new instance of PicoBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type PicoBufferPool ¶
type PicoBufferPool = IndirectPool[PicoBuffer]
PicoBufferPool manages 32-byte buffers via indirect indexing.
type Pool ¶
type Pool[T any] interface { // Put returns the item to the pool. // Returns iox.ErrWouldBlock if non-blocking and full. Put(item T) error // Get acquires an item from the pool. // Returns iox.ErrWouldBlock if non-blocking and empty. Get() (item T, err error) }
Pool is a generic object pool interface with configurable blocking semantics.
Implementations may operate in blocking or non-blocking mode. In blocking mode, Get blocks until an item is available and Put blocks until space is available. In non-blocking mode, both operations return iox.ErrWouldBlock instead of blocking.
All implementations must be safe for concurrent use.
type RegisterBuffer ¶
type RegisterBuffer [registerBufferSize]byte
RegisterBuffer represents a fixed-size buffer used for registering with the I/O ring.
type RegisterBufferPool ¶
type RegisterBufferPool = BoundedPool[RegisterBuffer]
RegisterBufferPool represents a pool of fixed-size buffers used for registering with the I/O ring.
func NewRegisterBufferPool ¶
func NewRegisterBufferPool(capacity int) *RegisterBufferPool
NewRegisterBufferPool creates a RegisterBufferPool for io_uring buffer registration.
The actual capacity is rounded up to the next power of two. RegisterBuffer uses LargeBuffer size (128 KiB), suitable for io_uring provided buffers.
type SmallBuffer ¶
type SmallBuffer [BufferSizeSmall]byte
SmallBuffer is a 2 KiB buffer for small messages.
func NewSmallBuffer ¶
func NewSmallBuffer() SmallBuffer
NewSmallBuffer returns a zero-initialized SmallBuffer.
func (SmallBuffer) Reset ¶
func (b SmallBuffer) Reset()
type SmallBufferBoundedPool ¶
type SmallBufferBoundedPool = BoundedPool[SmallBuffer]
SmallBufferBoundedPool implements a bounded MPMC pool for 2 KiB buffers.
func NewSmallBufferPool ¶
func NewSmallBufferPool(capacity int) *SmallBufferBoundedPool
NewSmallBufferPool creates a new instance of SmallBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type SmallBufferPool ¶
type SmallBufferPool = IndirectPool[SmallBuffer]
SmallBufferPool manages 2 KiB buffers via indirect indexing.
type TitanBuffer ¶ added in v0.2.0
type TitanBuffer [BufferSizeTitan]byte
TitanBuffer is a 128 MiB buffer, the maximum buffer tier.
func NewTitanBuffer ¶ added in v0.2.0
func NewTitanBuffer() TitanBuffer
NewTitanBuffer returns a zero-initialized TitanBuffer.
func (TitanBuffer) Reset ¶ added in v0.2.0
func (b TitanBuffer) Reset()
type TitanBufferBoundedPool ¶ added in v0.2.0
type TitanBufferBoundedPool = BoundedPool[TitanBuffer]
TitanBufferBoundedPool implements a bounded MPMC pool for 128 MiB buffers.
func NewTitanBufferPool ¶ added in v0.2.0
func NewTitanBufferPool(capacity int) *TitanBufferBoundedPool
NewTitanBufferPool creates a new instance of TitanBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type TitanBufferPool ¶ added in v0.2.0
type TitanBufferPool = IndirectPool[TitanBuffer]
TitanBufferPool manages 128 MiB buffers via indirect indexing.
type VastBuffer ¶ added in v0.2.0
type VastBuffer [BufferSizeVast]byte
VastBuffer is an 8 MiB buffer for large file chunks.
func NewVastBuffer ¶ added in v0.2.0
func NewVastBuffer() VastBuffer
NewVastBuffer returns a zero-initialized VastBuffer.
func (VastBuffer) Reset ¶ added in v0.2.0
func (b VastBuffer) Reset()
type VastBufferBoundedPool ¶ added in v0.2.0
type VastBufferBoundedPool = BoundedPool[VastBuffer]
VastBufferBoundedPool implements a bounded MPMC pool for 8 MiB buffers.
func NewVastBufferPool ¶ added in v0.2.0
func NewVastBufferPool(capacity int) *VastBufferBoundedPool
NewVastBufferPool creates a new instance of VastBufferBoundedPool with the specified capacity. The capacity must be between 1 and math.MaxUint32 and will be rounded up to the next power of two.
type VastBufferPool ¶ added in v0.2.0
type VastBufferPool = IndirectPool[VastBuffer]
VastBufferPool manages 8 MiB buffers via indirect indexing.