Skip to main content

FirecrackerPool

Struct FirecrackerPool 

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

Pre-booted Firecracker VM pool for fast cell startup.

Each slot is a VM that has booted to the kernel’s init stage and been snapshot’d — ready to restore in ~10 ms vs cold-boot ~125 ms.

Thread-safety: the pool is currently &mut self-driven for clarity. The wiring inside FirecrackerCellBackend will wrap it in tokio::sync::Mutex<FirecrackerPool> (same pattern as running_vms) so concurrent create / destroy calls serialize on slot allocation.

Implementations§

Source§

impl FirecrackerPool

Source

pub fn new(size: usize) -> Self

Construct an empty pool with size slots, all in PoolSlot::Empty. size==0 is valid and yields a pool whose checkout always returns None — the wiring code uses this to short-circuit when the env var is unset or zero.

Source

pub fn size(&self) -> usize

Number of slots configured for this pool (any state).

Source

pub fn available(&self) -> usize

Number of PoolSlot::Available slots — the number of cells that can be served by the fast-path right now.

Source

pub fn in_use(&self) -> usize

Number of PoolSlot::InUse slots.

Source

pub async fn checkout(&mut self, cell_id: &str) -> Option<PathBuf>

Reserve an available snapshot for cell_id, transitioning the slot from Available to InUse. Returns the snapshot path on success, or None if no Available slot exists (caller falls back to cold-boot).

Marked async for symmetry with the future implementation that will hold a tokio::sync::Mutex. The body is currently synchronous.

Source

pub async fn checkin(&mut self, cell_id: &str) -> bool

Release the slot previously checked out by cell_id, transitioning it to PoolSlot::Empty. A background filler is expected to re-populate the slot via Self::fill; this is intentional — a VM that ran a real cell is no longer at the parked-init state, so re-using its snapshot would leak workload-side state into the next cell.

Returns true if a matching InUse { cell_id } slot was found and reset, false otherwise (call was a no-op).

Source

pub async fn fill(&mut self, firecracker_bin: &str, kernel: &str, rootfs: &str)

Boot one VM per Empty slot, snapshot it, and transition the slot to PoolSlot::Available. No-op for slots already in Available or InUse.

On Linux (the only platform Firecracker runs on) this spawns one VMM per empty slot, drives the configure → InstanceStart → wait-for-init → PATCH-Paused → PUT-snapshot/create sequence, then kills the child process. The pair of (snapshot_path, mem_file_path) files left behind on disk is the durable artifact a future checkout will load.

Off-Linux this is a no-op — Firecracker is not available, so the pool stays empty and checkout returns None, falling FirecrackerCellBackend::create through to its cold-boot path.

Failures during fill are logged and the slot is left Empty (so a subsequent fill can retry); we don’t propagate errors out of fill because the pool is a best-effort latency optimisation, not a correctness gate.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
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<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