← All postsArchitecture

Engineering · Firecracker internals

Snapshotting RAM and disk consistently in Firecracker

A memory snapshot that disagrees with its block device corrupts the guest filesystem on resume. Here is how TaskCloud captures both at the same instant, encrypts them off-host and resumes on another server.

Firecracker makes taking a microVM snapshot look deceptively simple: pause the VM over its local Unix socket, call PUT /snapshot/create, and you get two files — vmstate (vCPU registers and virtio device state) and mem (guest physical memory). In a single-host demo, that is almost all you need.

In a multi-tenant cloud where disks persist across weeks, VMs are forked 50 ways, and physical servers eventually fail or get drained for maintenance, three harder problems show up immediately: RAM/disk consistency, cross-host durability, and fast restore without blocking on gigabytes of memory.

1. Why RAM and disk must freeze at the exact same instant

Inside a running Linux guest, the kernel's page cache holds dirty filesystem blocks and ext4 journal state in RAM. If you snapshot memory at time T while the virtio-block device keeps servicing writes to the backing volume at T + 10 ms (or vice versa), the resumed kernel wakes up believing the disk contains blocks that were overwritten or never flushed.

Our host daemon (hostd) treats memory and disk as one atomic unit:

  1. Pause all guest vCPUs through Firecracker's API so no new instructions or virtio-block requests are issued.
  2. Capture Firecracker's vmstate and memory snapshot while the vCPUs are halted.
  3. Take an LVM dm-thin snapshot of the VM's thin-provisioned block volume while the block device is completely quiescent.
  4. Exit the Firecracker process (for pause) or resume vCPUs and reset vsock agent connections (for live fork and named snapshots).

Because both the memory image and the thin block snapshot correspond to the exact same halted state, the guest kernel resumes with a completely consistent page cache and ext4 journal — no fsck, no reboot, no lost dirty buffers.

FIG. 01 · ATOMIC PAUSE & OFF-HOST SNAPSHOT PIPELINE LOCAL NVME → ENCRYPTED OBJECT STORAGE
Atomic pause and off-host snapshot pipeline Four stages: 1. Pause vCPUs and capture Firecracker vmstate plus memory alongside a dm-thin block delta; 2. Split into 4 MiB chunks, skip zero pages, compress with zstd; 3. Encrypt with per-organization AES-256-GCM key and content-address with HMAC-SHA256; 4. Commit manifest last to EU object storage for cross-host UFFD resume. 01 · FREEZE Pause vCPUs vmstate + RAM + dm-thin disk delta 02 · CHUNK 4 MiB blocks skip zero regions zstd compression 03 · ENCRYPT AES-256-GCM per-org data key HMAC-SHA256 addr 04 · OFFLOAD EU Object Storage manifest written last any-host UFFD resume Every chunk download verifies SHA-256 before mapping; corrupt state is rejected rather than booted.
Chunk size
4 MiB (zero-skip)
Encryption
AES-256-GCM / org key
Running checkpoint
Disk every ~15 min
Resume target
p95 < 800 ms

2. Getting snapshots off the host so a server failure never strands a VM

Keeping snapshots only on the local NVMe drive is fast until a host needs a kernel reboot or suffers a hardware failure. After a sandbox has been paused for a short window (default 10 minutes), hostd offloads its memory, vmstate and thin-pool disk delta relative to its base template to external EU object storage.

  • Per-organization encryption and deduplication: every organization gets its own random data key stored wrapped in the control plane. Chunks are addressed by HMAC-SHA256(org_key, SHA-256(plaintext)), so identical chunks deduplicate within an organization without leaking content hashes across tenants. Deleting an organization destroys its data key, cryptographically shredding offloaded snapshots.
  • Manifest-last commits and strict verification: the manifest is uploaded last, so an interrupted offload never produces a half-written generation. On download, every chunk and file checksum is verified; a mismatch leaves the sandbox paused with an explicit error instead of resuming corrupted memory.
  • Local NVMe becomes an LRU cache: once offloaded, the local copy stays hot for fast same-host resume and is evicted only when thin-pool occupancy crosses 80%. If the home host is full, drained or dead, the scheduler resumes the sandbox on any compatible host from object storage.

3. Lazy memory paging via userfaultfd

An 8 GB VM does not touch all 8 GB when it wakes up to answer an HTTP request or run a shell command. Copying the entire memory file before starting vCPUs would make cold-host resume take seconds.

Instead, Firecracker supports external memory backends over Linux userfaultfd (UFFD). When a sandbox resumes from remote storage, our UFFD handler maps the guest memory region, starts vCPUs immediately, and fetches 4 MiB chunks on demand as the guest faults them in — prioritizing the working set recorded from the previous pause while hydrating the rest in the background.

4. What about a VM that is running when a host dies?

Paused VMs are durable once offloaded, but long-running active sandboxes also need bounded data loss. Taking a full memory snapshot every 15 minutes would pause vCPUs for seconds and burn NVMe endurance, so running sandboxes take a disk-only crash-consistent checkpoint roughly every 15 minutes of active work (dm-thin snapshot takes milliseconds without stopping vCPUs, and only changed 4 MiB windows are uploaded).

If a host fails while a sandbox is running, the control plane restores it on another host from its latest checkpoint and emits a signed sandbox.restored_from_checkpoint webhook reporting whether RAM was lost and the exact data_loss_window_seconds.

Honest trade-offs and current work

  • CPU compatibility classes: Firecracker RAM snapshots depend on host CPU features, so Zen 3 (Ryzen 5950X) and Zen 4 (Ryzen 7950X) form separate snapshot pools. Cross-class recovery falls back to booting from the disk snapshot.
  • Full vs. diff memory snapshots: in our initial Phase 0 KVM tests, full 8 GB writes take several seconds per pause/fork. Moving to dirty-page differential snapshots (TrackDirtyPages) and copy-on-write memory is active engineering work required to hit our < 2 s bulk-fork target consistently on hardware.
  • Clock jump on resume: after a multi-hour pause, the guest wall clock jumps forward immediately on wake. Our guest images configure systemd-journald with WatchdogSec=0 so the clock jump never triggers a false watchdog kill.

Every assumption above is being measured against real KVM hosts in our Phase 0 validation. Check the status page for the exact SLO targets we are holding ourselves to, or read the snapshots and fork documentation.