pub struct BufferPoolConfig { /* private fields */ }Expand description
Configuration for a buffer pool.
The class layout is a set of power-of-two size classes, each with its own tracked-buffer limit. Enabled classes do not need to be contiguous, and requests route to the smallest enabled class that fits.
Shape builders do not commute. Each builder applies to the layout produced
by the previous one: replacement builders (Self::with_size_class_range,
Self::with_size_classes) discard the current layout, uniform builders
(Self::with_max_per_class, Self::with_bytes_per_class) overwrite
every enabled limit, and Self::with_budget_bytes snapshots and rescales
the shape that exists at that call.
Implementations§
Source§impl BufferPoolConfig
impl BufferPoolConfig
Sourcepub fn for_network() -> Self
pub 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 fn with_size_class_range(
self,
min: NonZeroUsize,
max: NonZeroUsize,
max_buffers: NonZeroU32,
) -> Self
pub fn with_size_class_range( self, min: NonZeroUsize, max: NonZeroUsize, max_buffers: NonZeroU32, ) -> Self
Returns a copy of this config whose layout is the inclusive, contiguous
power-of-two range from min to max with a uniform limit.
This replaces the complete class layout.
§Panics
minormaxis not a power of twominormaxexceedsisize::MAXmax < min
Sourcepub fn with_size_classes<I, C>(self, classes: I) -> Self
pub fn with_size_classes<I, C>(self, classes: I) -> Self
Returns a copy of this config whose layout is exactly the given classes.
This replaces the complete class layout. Input order does not matter, classes are normalized into ascending size order.
§Panics
classesis empty- a class size is not a power of two
- a class size exceeds
isize::MAX - two classes have the same size
Sourcepub fn with_size_class(
self,
size: NonZeroUsize,
max_buffers: NonZeroU32,
) -> Self
pub fn with_size_class( self, size: NonZeroUsize, max_buffers: NonZeroU32, ) -> Self
Returns a copy of this config with the given class enabled, replacing its limit if it is already enabled.
§Panics
sizeis not a power of twosizeexceedsisize::MAX
Sourcepub fn without_size_class(self, size: NonZeroUsize) -> Self
pub fn without_size_class(self, size: NonZeroUsize) -> Self
Returns a copy of this config with the given class removed.
Requests that previously routed to the removed class route to the next larger enabled class.
§Panics
sizeis not a power of twosizeexceedsisize::MAX- no class with
sizeis enabled - the class is the final enabled class
Sourcepub fn with_max_per_class(self, max_buffers: NonZeroU32) -> Self
pub fn with_max_per_class(self, max_buffers: NonZeroU32) -> Self
Returns a copy of this config with the same limit on every enabled class.
Sourcepub fn with_bytes_per_class(self, bytes: NonZeroUsize) -> Self
pub fn with_bytes_per_class(self, bytes: NonZeroUsize) -> Self
Returns a copy of this config where every enabled class has approximately the same tracked-byte weight.
Each enabled class’s limit becomes max(1, bytes / size), so limits
halve as class sizes double. This is a one-shot count transformation,
not a stored byte policy, and it never disables a class.
§Panics
Panics if a derived limit exceeds u32::MAX.
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.
The global freelist derives its stripe count from this target and the class capacity. This value also 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_max_thread_cache_capacity(
self,
capacity: NonZeroUsize,
) -> Self
pub const fn with_max_thread_cache_capacity( self, capacity: NonZeroUsize, ) -> Self
Returns a copy of this config with an explicit per-thread cache size.
Each size class keeps a small per-thread cache of free buffers for
same-thread reuse. By default its capacity is derived per class from
the class limit and Self::parallelism, reserving about half of the
class for the shared global freelist. An explicit capacity replaces
that derivation and may be larger or smaller than the derived value.
The effective capacity for each class is min(capacity, class limit).
Clamping happens independently per class, so one small class cannot
invalidate the configuration.
Buffers held in a thread’s cache are invisible to other threads until they spill to the global freelist or the thread exits, and each thread can retain up to the effective capacity of every class it touches. Larger values favor same-thread reuse while smaller values favor cross-thread visibility and a lower per-thread memory ceiling.
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: NonZeroUsize) -> Self
pub fn with_budget_bytes(self, budget: NonZeroUsize) -> Self
Returns a copy of this config with all class limits proportionally rescaled under a strict tracked-byte ceiling.
This snapshots the currently enabled classes and their limits, then
chooses the greatest common proportional scale for which the total
tracked capacity sum(size * scaled_limit) stays within budget,
where scaled_limit = max(1, floor(limit * scale)). Scaling may raise
or lower limits, never disables a class, and may deliberately leave
part of the budget unused rather than distort the requested shape.
The budget covers tracked buffer payload capacity only. It does not include allocator metadata, alignment overhead, or pool bookkeeping.
This is a one-shot transformation, not a stored policy. Later builder calls may change the resulting total, and calling this again rescales the already scaled limits rather than the shape they were derived from.
§Panics
budgetis smaller than one buffer from every enabled class- the budget would require scaling a limit above
u32::MAX
Sourcepub fn size_classes(
&self,
) -> impl ExactSizeIterator<Item = BufferPoolClassConfig> + '_
pub fn size_classes( &self, ) -> impl ExactSizeIterator<Item = BufferPoolClassConfig> + '_
Returns an iterator over enabled classes in ascending size order.
Sourcepub fn class_for(&self, size: usize) -> Option<BufferPoolClassConfig>
pub fn class_for(&self, size: usize) -> Option<BufferPoolClassConfig>
Returns the enabled class that serves a pooled request of size bytes,
or None if size exceeds the largest enabled class.
Requests route to the smallest enabled class that fits, so in sparse
layouts the returned class may be much larger than the request. This
reports class shape only: zero-sized requests and requests below
Self::pool_min_size bypass the pool, and oversized requests fall
back to untracked aligned allocations with capacity at least as large
as the request.
Sourcepub const fn pool_min_size(&self) -> usize
pub const fn pool_min_size(&self) -> usize
Returns the minimum request size that uses pooled allocation.
Sourcepub const fn prefill(&self) -> bool
pub const fn prefill(&self) -> bool
Returns whether every tracked buffer is created during pool construction.
Sourcepub const fn alignment(&self) -> NonZeroUsize
pub const fn alignment(&self) -> NonZeroUsize
Returns the buffer alignment.
Sourcepub const fn parallelism(&self) -> NonZeroUsize
pub const fn parallelism(&self) -> NonZeroUsize
Returns the expected number of threads concurrently accessing the pool.
Sourcepub fn min_size(&self) -> NonZeroUsize
pub fn min_size(&self) -> NonZeroUsize
Returns the smallest enabled class size.
Sourcepub fn max_size(&self) -> NonZeroUsize
pub fn max_size(&self) -> NonZeroUsize
Returns the largest enabled class size.
Sourcepub fn max_tracked_bytes(&self) -> usize
pub fn max_tracked_bytes(&self) -> usize
Returns sum(class size * class limit), saturating at usize::MAX.
A saturated result means the configured maximum tracked capacity is at least that large.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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