Skip to main content

ArenaPool

Struct ArenaPool 

Source
pub struct ArenaPool<B: FixedRange, F> { /* private fields */ }
Expand description

A pool of recyclable BumpArenas — hand them out with checkout, return them with give_back (an O(1) reset plus retain up to a cap), so in steady state the same backings are reused with no munmap / mmap / re-fault. The motivating use is a per-commit / per-branch workload where throwing arenas away per unit of work would dominate the cost.

B is the backing type; F mints a fresh backing on demand (e.g. || MmapBacked::new(32 * 1024)). Arenas are wrapped in BumpArena internally. When idle arenas should not hold physical RAM, an OsBacked backing additionally enables release_idle.

Implementations§

Source§

impl<B, F> ArenaPool<B, F>
where B: FixedRange, F: FnMut() -> Result<B, AllocError>,

Source

pub fn new(cap: usize, factory: F) -> Self

Create an empty pool that retains up to cap idle arenas and mints new backings with factory.

Source

pub fn checkout(&mut self) -> Result<BumpArena<B>, AllocError>

Check out an arena: reuse a reset idle one if available, otherwise mint a fresh backing via the factory and wrap it. The returned arena always starts empty (cursor 0).

Source

pub fn give_back(&mut self, arena: BumpArena<B>)

Return an arena to the pool. It is reset (O(1)) and retained for reuse if the pool is below its cap; otherwise it is dropped (releasing its backing). In steady state — checkouts and give-backs balanced under the cap — this performs no allocation syscalls.

Source

pub fn prewarm(&mut self, n: usize) -> Result<usize, AllocError>

Pre-mint up to n idle arenas (clamped to the remaining cap), so the first checkouts don’t pay backing construction. Returns the number actually added; stops early and returns Err if the factory fails.

Source

pub fn idle_count(&self) -> usize

Number of reset arenas currently retained and ready for checkout.

Source

pub fn capacity(&self) -> usize

The retention cap (maximum idle arenas).

Source

pub fn clear(&mut self)

Drop all idle arenas, releasing their backings (e.g. munmap). Use to reclaim address space when the pool will be idle for a long time; the next checkout mints fresh.

Source§

impl<B, F> ArenaPool<B, F>
where B: FixedRange + OsBacked, F: FnMut() -> Result<B, AllocError>,

Source

pub fn release_idle(&self)

Release the physical pages backing every idle arena (madvise(DONTNEED) / MEM_RESET) while keeping their virtual reservations mapped for reuse. Bounds resident memory for arenas sitting idle without dropping or re-mmaping them; the next checkout re-faults the pages it touches.

Auto Trait Implementations§

§

impl<B, F> !RefUnwindSafe for ArenaPool<B, F>

§

impl<B, F> !Sync for ArenaPool<B, F>

§

impl<B, F> Freeze for ArenaPool<B, F>
where F: Freeze,

§

impl<B, F> Send for ArenaPool<B, F>
where F: Send, B: Send,

§

impl<B, F> Unpin for ArenaPool<B, F>
where F: Unpin, B: Unpin,

§

impl<B, F> UnsafeUnpin for ArenaPool<B, F>
where F: UnsafeUnpin,

§

impl<B, F> UnwindSafe for ArenaPool<B, F>
where F: UnwindSafe, B: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.