pub struct BufferPoolConfig {
pub pool_min_size: usize,
pub min_size: NonZeroUsize,
pub max_size: NonZeroUsize,
pub max_per_class: NonZeroU32,
pub prefill: bool,
pub alignment: NonZeroUsize,
pub parallelism: NonZeroUsize,
/* private fields */
}Expand description
Configuration for a buffer pool.
Fields§
§pool_min_size: usizeMinimum request size that should use pooled allocation.
Requests smaller than this bypass the pool and use direct aligned
allocation instead. A value of 0 means all eligible requests use the
pool.
min_size: NonZeroUsizeMinimum buffer size. Must be >= alignment and a power of two.
max_size: NonZeroUsizeMaximum buffer size. Must be a power of two and >= min_size.
max_per_class: NonZeroU32Maximum number of buffers per size class.
Size-class slots are identified by u32, so the per-class capacity is
capped by this type.
prefill: boolWhether to create every tracked buffer during pool construction.
When enabled, each size class creates max_per_class buffers and parks
them in the class-global freelist before the pool is returned. This
moves allocation cost to startup and makes the first reuse path avoid
heap allocation.
alignment: NonZeroUsizeBuffer alignment. Must be a power of two.
parallelism: NonZeroUsizeExpected number of threads concurrently accessing the pool.
This sizes the shared global freelist stripes. It is also used to derive
thread-cache capacity when the thread-cache policy is automatic, using
approximately half of Self::max_per_class divided across expected
threads.
Implementations§
Source§impl BufferPoolConfig
impl BufferPoolConfig
Sourcepub const fn for_network() -> Self
pub const fn for_network() -> Self
Network I/O preset: 1KB to 128KB buffers, 4096 per class, not prefilled.
Network operations typically need multiple concurrent buffers per connection (message, encoding, encryption) so we allow 4096 buffers per size class.
Sourcepub fn for_storage() -> Self
pub fn for_storage() -> Self
Storage I/O preset: page_size (usually 4KB) to 8MB buffers, 64 per class,
not prefilled.
Sourcepub const fn with_pool_min_size(self, pool_min_size: usize) -> Self
pub const fn with_pool_min_size(self, pool_min_size: usize) -> Self
Returns a copy of this config with a new minimum request size that uses pooling.
Sourcepub const fn with_min_size(self, min_size: NonZeroUsize) -> Self
pub const fn with_min_size(self, min_size: NonZeroUsize) -> Self
Returns a copy of this config with a new minimum buffer size.
Sourcepub const fn with_max_size(self, max_size: NonZeroUsize) -> Self
pub const fn with_max_size(self, max_size: NonZeroUsize) -> Self
Returns a copy of this config with a new maximum buffer size.
Sourcepub const fn with_max_per_class(self, max_per_class: NonZeroU32) -> Self
pub const fn with_max_per_class(self, max_per_class: NonZeroU32) -> Self
Returns a copy of this config with a new maximum number of buffers per size class.
Sourcepub const fn with_parallelism(self, parallelism: NonZeroUsize) -> Self
pub const fn with_parallelism(self, parallelism: NonZeroUsize) -> Self
Returns a copy of this config with a new expected parallelism.
This controls the minimum global-freelist stripe count, and controls thread-cache capacity when the thread-cache policy is automatic. The automatic policy reserves about half of each class for the global freelist and divides the remaining capacity across expected threads.
Sourcepub const fn with_thread_cache_capacity(
self,
thread_cache_capacity: NonZeroUsize,
) -> Self
pub const fn with_thread_cache_capacity( self, thread_cache_capacity: NonZeroUsize, ) -> Self
Returns a copy of this config with an explicit per-thread cache size.
Global-freelist striping is set separately by Self::with_parallelism.
Sourcepub const fn with_thread_cache_disabled(self) -> Self
pub const fn with_thread_cache_disabled(self) -> Self
Returns a copy of this config with thread-local caching disabled.
Global-freelist striping is set separately by Self::with_parallelism.
Sourcepub const fn with_prefill(self, prefill: bool) -> Self
pub const fn with_prefill(self, prefill: bool) -> Self
Returns a copy of this config with a new prefill setting.
Sourcepub const fn with_alignment(self, alignment: NonZeroUsize) -> Self
pub const fn with_alignment(self, alignment: NonZeroUsize) -> Self
Returns a copy of this config with a new alignment.
Sourcepub fn with_budget_bytes(self, budget_bytes: NonZeroUsize) -> Self
pub fn with_budget_bytes(self, budget_bytes: NonZeroUsize) -> Self
Returns a copy of this config sized for an approximate tracked-memory budget.
This computes max_per_class as:
ceil(budget_bytes / sum(size_class_bytes))
where size_class_bytes includes every class from min_size to max_size.
This always rounds up to at least one buffer per size class, so the
resulting estimated capacity may exceed budget_bytes.
§Panics
min_sizeis not a power of twomax_sizeis not a power of twomax_size < min_size- the derived per-class capacity does not fit in
u32.
Trait Implementations§
Source§impl Clone for BufferPoolConfig
impl Clone for BufferPoolConfig
Source§fn clone(&self) -> BufferPoolConfig
fn clone(&self) -> BufferPoolConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BufferPoolConfig
impl RefUnwindSafe for BufferPoolConfig
impl Send for BufferPoolConfig
impl Sync for BufferPoolConfig
impl Unpin for BufferPoolConfig
impl UnsafeUnpin for BufferPoolConfig
impl UnwindSafe for BufferPoolConfig
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 more