PagedPool

Struct PagedPool 

Source
pub struct PagedPool { /* private fields */ }
Expand description

A pool of reusable fixed-size buffers allocated in large pages.

This type implements MemoryPool and can be configured as a custom memory pool for a S3CrtClient. It can also return mutable buffers (PoolBufferMut) to use in other scenarios, such as reading cache blocks from disk or buffering incremental uploads.

The pool is configured by providing a set of sizes for the buffers, e.g. read and write part sizes, cache block size. For each of these sizes, the pool will maintain a [SizePool] instance, which will allocate “pages” of BUFFERS_PER_PAGE (16) buffers on demand.

When a buffer of a given size is requested, the pool will return a buffer from one of 2 logical areas: primary and secondary:

  • primary: the [SizePool] with the smallest buffer size large enough to contain the requested size is selected. If any of its existing pages has a free buffer, it is marked as reserved and returned, otherwise a new page is allocated.
  • secondary: if the requested size is larger than the maximum buffer size in [SizePool]s, a buffer of the exact size is allocated and returned.

When a primary buffer is dropped, it will automatically be released back to the pool, so it can be reused. Secondary buffers will also notify the pool on drop, but only for tracking.

The trim method can be invoked to free all empty pages, i.e. with no currently reserved buffers, across [SizePool]s.

When reserving a buffer, a BufferKind parameter is required to keep track of the usage. Requests through the MemoryPool interface will map the originating MetaRequestType to BufferKind.

Implementations§

Source§

impl PagedPool

Source

pub const MAX_BUFFER_SIZE: usize

Maximum size for a primary buffer.

Buffers larger than this size will be allocated from secondary memory.

Source

pub const DEFAULT_BUFFER_SIZE: usize

Default size for a primary buffer.

Used when no other valid buffer size is provided when creating the pool.

Source

pub fn new_with_candidate_sizes(buffer_sizes: impl Into<Vec<usize>>) -> Self

Create a new pool, configuring primary memory with the given set of buffer sizes, if valid.

Ignores invalid (0 or greater than MAX_BUFFER_SIZE) or duplicate values for buffer sizes. If no valid value is provided, uses DEFAULT_BUFFER_SIZE.

Source

pub fn trim(&self) -> bool

Trim empty pages in the pool.

Source

pub fn schedule_trim(&self, recurring_time: Duration)

Schedule recurring calls to trim.

Source

pub fn reserved_bytes(&self, kind: BufferKind) -> usize

Return the reserved memory in bytes for the given kind of buffer.

Source

pub fn get_buffer_mut(&self, capacity: usize, kind: BufferKind) -> PoolBufferMut

Get a new empty mutable buffer from the pool with the requested capacity.

Trait Implementations§

Source§

impl Clone for PagedPool

Source§

fn clone(&self) -> PagedPool

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PagedPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MemoryPool for PagedPool

Source§

type Buffer = PoolBuffer

Associated buffer type.
Source§

fn get_buffer( &self, size: usize, meta_request_type: MetaRequestType, ) -> Self::Buffer

Get a buffer of at least the requested size.
Source§

fn trim(&self) -> bool

Trim the pool. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more