Research · mica v0.2

mica v0.2: how it works and how fast it is

mica gives a VM or a container a disk whose data lives in an S3 bucket. The disk runs at local SSD speed, and it can move to another machine in a few seconds. This page explains how, and shows what mica measures on a host and in Firecracker.

October 2026 · All numbers come from one lab machine (the lab). Each change and its review: mica v0.2 optimization. The first design: the v0.1 deck.

24 msto attach a disk (p50)
2.3 scold Firecracker boot, attach until ssh answers
0.64 scold memory restore until ssh answers
0 of 24power cuts and daemon kills that lost a flushed write

01Why a disk in S3

A sandbox is a small VM or container that runs one user's work. A platform stops idle sandboxes, and starts them again when the user comes back. If the disk is on the SSD of one machine, the sandbox can start only on that machine. If that machine is full or down, the user waits.

mica keeps the shared copy of each disk in S3, and uses the local SSD as a cache. Any machine can attach the disk. Three rules hold in every part of mica:

  1. A write never waits for S3. Writes and FLUSH go to the local SSD only.
  2. A read never waits for data that it does not need. An attach copies nothing. Prefetch runs behind the guest's reads.
  3. After a detach, S3 has everything. Then any machine can attach the disk.

02Where mica sits

mica is a program in user space, not a kernel module. It uses ublk, a Linux driver that makes a block device whose requests go to a user-space program. For each attached disk, mica asks ublk for a device: /dev/ublkb0, with the link /dev/mica/<disk>. To the rest of the system it is a normal disk. Firecracker, QEMU, a container or a host mount can use it.

The diagram follows one 4 KiB write from an app in a Firecracker guest to the SSD.

One guest write. In the guest VM, the app writes, ext4 and the virtio-blk driver pass it to Firecracker. Firecracker writes to /dev/mica/disk, a ublk block device in the host kernel. The ublk driver hands the request to the mica queue thread through io_uring. The queue thread writes the disk's data file through the host filesystem, which writes to the local SSD. Later, the mica disk engine uploads chunks to S3. GUEST VM HOST · USER SPACE HOST · KERNEL DEVICES app write() ext4 virtio-blk driver mica daemon disk engine misses · FLUSH · uploads queue thread io_uring Firecracker virtio-blk device network TCP · TLS host filesystem page cache ublk driver /dev/ublkc0 /dev/mica/disk = /dev/ublkb0 S3 (remote) local SSD 1 virtqueue 2 write 3 4 request + data via io_uring 5 write the data file 6 writeback · sync on FLUSH 7 later: S3 requests
Steps 1 to 6 are one guest write. The reply takes the same path back. Step 7 runs later, in the background.
  1. In the guest, the app writes a file. ext4 turns it into a block write, and the virtio-blk driver puts it on a virtqueue that Firecracker shares with the guest.
  2. Firecracker takes the request and writes it to /dev/mica/disk on the host, with io_uring.
  3. The host kernel sends the block request to the ublk driver.
  4. The ublk driver hands the request to mica. Each mica queue thread keeps io_uring commands waiting on /dev/ublkc0. The driver completes one with the request: operation, offset and length. For a write, the data is copied into the queue thread's buffer.
  5. The queue thread finds the chunk, and writes the data into the disk's data file with io_uring. Then it tells ublk that the request is done, in the same call that waits for the next request.
  6. The host filesystem keeps the data in the page cache. It goes to the SSD with writeback, and for sure at the next FLUSH.
  7. Later, the disk engine uploads changed chunks to S3. It also downloads a chunk when a read needs one that is not local.

The queue thread serves most requests alone: reads and writes of chunks that are local, with no lock wait and no other thread. A request that needs more goes to the disk engine, on a tokio runtime in the same process. Examples: the first write to a chunk that is not local, a read that misses the cache, a FLUSH, a FUA write. Each device has one queue thread per CPU, up to 4.

If the mica daemon stops, the kernel keeps the device and holds its requests. The next daemon takes the device over with ublk user recovery, and the guest sees a pause of about 1 s.

03From a disk to chunks

To mica, a disk is a row of bytes, cut into chunks of one size. The size is set when the disk is made: 256 KiB by default, from 64 KiB to 4 MiB. A 20 GiB disk has 81,920 chunks. A chunk is the unit of everything that follows: the local data, the upload, the download and the dedup.

Take a 4 KiB write at byte 1,056,768 of a 20 GiB disk. mica finds its place with three divisions:

Chunk
1,056,768 ÷ 262,144 = 4, rest 8,192: chunk 4, 8 KiB into it
Data file
1,056,768 ÷ 1 GiB = 0: dirty/data-0, at byte 1,056,768
Page
chunk 4 ÷ 1,024 = 0, rest 4: page 0, slot 4
A 20 GiB disk is a row of 81,920 chunks of 256 KiB. A 4 KiB write at byte 1,056,768 lands in chunk 4, 8 KiB into it. On each write, chunk 4 changes in place in the data file data-0. At a checkpoint, mica hashes chunk 4 with SHA-256, uploads it as chunks/3f/3fa9c1..., writes the hash into slot 4 of page 0, and the root names page 0. A 20 GiB disk: 81,920 chunks of 256 KiB chunk 0 chunk 1 chunk 2 chunk 3 chunk 4 chunk 5 … chunk 81,919 0 256 KiB 512 KiB 768 KiB 1 MiB 1.25 MiB 1.5 MiB 20 GiB a 4 KiB write at byte 1,056,768 = 1 MiB + 8 KiB every write: in place, no sync at a checkpoint dirty/data-0 (local SSD) bytes 1 MiB to 1.25 MiB of a sparse 1 GiB file SHA-256 of the chunk 3fa9c1… chunks/3f/3fa9c1… in S3, zstd body PUT page 0, slot 4 = 3fa9c1… root page 0 = 81c0…
The same chunk has three places: its bytes in a local data file, its hash in a page, and its content as an S3 object.

On the local SSD, a disk has sparse data files, one for each GiB of the disk. Each chunk sits at its own disk offset, so a write needs no lookup table: it goes to the same offset in the data file. A data file uses space only for the chunks the guest wrote.

In S3, a chunk is an immutable object. Its key is the SHA-256 of its content, and its body is a zstd frame. So:

  • Two equal chunks are one object. Disks made from one image share their chunks.
  • mica checks each download against its key.
  • An all-zero chunk is not stored. A new disk stores nothing.

A request that crosses chunk borders is split. A 512 KiB read at byte 200 KiB covers chunks 0, 1 and 2, and each part is served on its own.

Pages, roots and snapshots

A page lists the hashes of 1,024 chunks: 32 KiB, for 256 MiB of disk. A root lists the hashes of all pages of a disk: 12.5 KiB for 100 GiB. The head of a disk names its current root. Pages and roots are also named by their hash. So a change writes only the new pages, a new root and the head, and everything else is shared.

The head of disk-1 points to root 42. A snapshot points to root 41, and so does the head of disk-2, a clone. Root 42 and root 41 share page 0. Root 42 has a new page 1 prime, which names the changed chunk c prime. disks/disk-1/head snapshots/base disks/disk-2/head root 42 root 41 page 1′ page 0 page 1 chunk c′ chunks a, b chunk c Root 42 changed one chunk, so it has one new page. Everything else is shared.
A snapshot and a clone are pointers to a root. They copy no page and no chunk.
chunks/<xx>/<chunk hash>    one chunk, zstd, immutable
pages/<xx>/<page hash>      the hashes of 1,024 chunks
manifests/<root hash>       one root: the hash of each page
disks/<disk>/head           the current root and the read profile
disks/<disk>/attached       the machine that owns the disk now
snapshots/<name>            a named root

04Writes and FLUSH

A guest write goes into the data file and returns. It does not sync. If the chunk is not local yet and the write covers only part of it, mica first copies the chunk from the cache into the data file. On XFS and btrfs that copy is a reflink. On ext4 it is a real copy. A chunk of zeros needs no copy, because every range that is not local is a hole.

A FLUSH is the guest's request for durability, for example at fsync or a journal commit. On FLUSH, mica syncs the data files written since the last FLUSH. Then it appends the chunks that became local to the dirty log, the list of a disk's local chunks, and syncs the log. In that order, the log never lists a chunk whose data a power cut can lose.

A guest write goes into the data file in the page cache, and returns. A guest FLUSH syncs the data files, appends new chunks to the dirty log, and syncs the log. Every 16 MiB of writes, mica starts writeback early. A checkpoint every 30 s or 512 MiB reads chunks and uploads them to S3. guest write data file in the page cache + chunk noted in memory checkpoint every 30 s or 512 MiB S3 returns read PUT guest FLUSH 1 fdatasync the data files 2 append new chunks to the log 3 fdatasync the log every 16 MiB: start writeback A FLUSH never waits for S3. When it returns, the data survives a power cut.
Writes and FLUSH stay on the local SSD. The checkpoint is a separate step.

Linux starts writeback late: after 10% of free memory is dirty, or after 30 s. So after each 16 MiB of writes, mica starts writeback itself, with sync_file_range. A FLUSH after a large write then finds little left to write.

A write that returned also survives a crash of the daemon before any FLUSH. The page cache keeps its data, and a bitmap in /run lists the chunks that became local since their last FLUSH. /run is a tmpfs: it survives a crash of mica, as the page cache does, and a reboot clears it, as it clears the page cache.

mica needs only plain Linux file calls: sparse files, fdatasync, copy_file_range and hole punching. It works on ext4, XFS and btrfs.

05Reads

For each chunk of a read, the first match wins:

  1. A local chunk: read the data file.
  2. A zero chunk: return zeros.
  3. A chunk in the cache: read the cache file. The cache holds clean chunks that S3 also has, and all disks on the machine share it.
  4. Otherwise: get the chunk from S3, decompress it, check its hash, store it in the cache, and read it.

Many reads that miss one chunk share one GET. Behind the guest's reads, three kinds of download keep the link busy, in this order:

  • Reads by the guest always come first.
  • Likely reads. When reads follow each other, mica fetches ahead: 1 MiB first, then up to 8 MiB. At attach it also fetches the read profile: the chunks that the guest read first in its last session, up to 64 MiB.
  • The fill. When the link has nothing else to do, mica downloads the rest of the disk, in disk order. It starts at attach, also when the guest reads nothing. Then every read is local.

06Checkpoints

A checkpoint uploads the local chunks that S3 does not have, and commits a new root. It starts 30 s after the last one, or earlier when 512 MiB of changes wait. It also runs at detach and at snapshot.

  1. Take the list of unsaved chunks. Later changes go to the next checkpoint, so a busy writer cannot make a checkpoint last for ever.
  2. For each chunk, read it into memory and PUT it, with up to 64 MiB in flight. The guest keeps writing in place.
  3. PUT the changed pages and the new root.
  4. Check that this machine still owns the disk. Then write the head.

A chunk stays local after its upload, so the next write to it costs nothing extra. Saved chunks leave the data files only when local data passes its limit, and at detach. They go into the cache.

Garbage collection (GC) deletes objects that no root needs and that are older than 24 hours. A GC can see a new upload as old only if it runs while the PUT ends. So during an upload, mica reads the GC state once a second. Until a check shows that no GC ran, the first write to an uploaded chunk keeps a copy of the uploaded content. If a GC ran, the checkpoint checks every committed chunk and page, and uploads a deleted one again.

07Moving a disk

This is the main use of mica: a sandbox stops on machine A and starts on machine B.

Machine A stops the guest and unmounts, uploads the last checkpoint, and deletes the attached marker. Machine B creates the marker with If-None-Match, reads the head and the root, makes the device and starts the guest. Then it fetches the read profile and fills the rest of the disk. Machine A S3 Machine B guest stops · umount last checkpoint: chunks, pages, root, head DELETE the attached marker PUT the marker, If-None-Match: * GET head, GET root /dev/mica/disk · guest starts read profile first, then the fill
Machine B copies nothing before the guest starts. The attach is three small requests.

Only one machine may write a disk. With S3 conditional writes, the claim is one atomic create: a PUT with If-None-Match: *. Of two machines that claim at the same moment, only one creates the marker. RustFS, AWS S3, R2 and MinIO support this. For a store without it, such as Garage, mica writes a claim, waits 1 s and reads it back, so an attach takes about 1 s.

08Crash safety

  • After a FLUSH returns, its writes survive a crash of mica and a power cut.
  • After a write returns, it survives a crash of mica, also without a FLUSH.
  • After a detach, S3 has all data, and any machine can attach the disk.

A test harness checks the first two. A writer fills a 256 MiB area with 4 KiB blocks that each name their block, their write and a CRC, and FLUSHes now and then. At a random moment, a device-mapper target under the data folder drops every write: a power cut. Then the daemon dies, and the folder is mounted again, as after a reboot. Every block must hold its last write before the last completed FLUSH, or a later one.

TestData folderRunsLost a write
Power cutbtrfs60
Power cutXFS60
Power cutext460
Daemon killed while the guest writes (every returned write must survive)btrfs60

09The lab

All tests ran on one machine. S3 is local, but its link is limited, so the numbers show how mica behaves on a slow link.

PartSetup
Machine16 CPUs, 27 GiB RAM, NVMe SSD, Fedora 44, Linux 7.0
S3RustFS 1.0.1 in Docker, 100 MiB/s down and up, 1 ms round trip (20 ms in one series)
Local diskbtrfs on the NVMe, limited to 300 MiB/s read and write for mica (cgroup io.max)
VMFirecracker 1.16.1, 2 vCPUs, 2 GiB RAM, Ubuntu 24.04 or Alpine 3.22, on a 100 GiB mica disk
mica256 KiB chunks, a checkpoint every 30 s or at 512 MiB, conditional writes on

Without mica, a 4 MiB GET or PUT stream gets 91–97 MiB/s. The disk does 300 MiB/s, and 1,799 synced 4 KiB writes per second.

Test data. The test files are random (AES-CTR), so they do not compress, and no two chunks are equal. Real system files do compress: /usr/bin and Python libraries (2.0 GiB) upload as 675 MiB.

10Results on the host

A script writes 42,048 files (7.93 GiB) into a 20 GiB mica disk with ext4: 48 files of 64 MiB, 2,000 files of 256 KiB to 2 MiB, and 40,000 files of 4 KiB to 128 KiB. Every read pass checks every file against its checksum, and all passes found all files correct. "Cold" means an empty cache: every chunk comes from S3.

Stepv0.1v0.2
Attach one disk (p50 of 10)1,035 ms24 ms
Attach 4 disks at the same time4.2 s0.05 s
Write 7.93 GiB of files (page cache), then sync13.9 + 16.0 s17.3 + 15.0 s
Start of the write until all data is in S3122.4 s120.4 s
Cold: attach and mount1.29–1.31 s0.14–0.19 s
Cold: first byte of a 64 MiB file0.16 s0.00–0.02 s
Cold: read 100 small files, one after the other0.57 s0.23–0.41 s
Cold: read and check all files, 1 reader115.2 s89.5 s
Cold: read and check all files, 8 readers83.8 s82.6 s
Whole disk local after a cold attach (the fill)never86 s
Warm: read and check all files, 1 reader26.8 s27.3 s

The link sets the cold limit: 7.93 GiB at 95 MiB/s takes at least 85 s. v0.2 comes close with one reader, because read-ahead keeps several downloads in flight. The disk limit (300 MiB/s) sets the warm limit. The upload also needs at least 85 s. Checkpoints start it during the write, but the host writes much faster than the link, so the link sets this time too.

Writes and FLUSH

A small tool writes 4 KiB blocks with O_DIRECT on the mica device, 15 s for each test. The first five rows are the mean of 3 rounds on a quiet machine. The last two come from one earlier run of both builds, one after the other. v0.2a is v0.2 with one file per local chunk, the layout before the data files.

Testv0.2av0.2
Write + fdatasync, idle disk1,515/s1,438/s
Longest FLUSH right after a 2 GiB write3.6–4.6 s0.46–0.95 s
Write + fdatasync while that 2 GiB uploads586/s695/s
Random write + fdatasync to chunks the last checkpoint saved265/s584/s
Random write to saved chunks, no sync512/s19,290/s
Random 4K read of saved local chunks, queue depth 156,326/s84,853/s
4 parallel writers, 1 GiB each, 1 MiB direct writes1,651 MiB/s1,651 MiB/s

The idle FLUSH rate is 80% of the raw disk's 1,799 per second, and 5% lower than with one file per chunk. A test without mica shows the cause: on btrfs, a synced 4 KiB write into a large file costs about 50 µs more than into a new small file.

11Results in Firecracker

The VM's root disk is a 100 GiB mica disk with ext4. The mica device goes straight to Firecracker as a virtio block device (io_engine = Async). A boot time runs from mica disk attach until ssh in the guest answers. It includes the attach, the start of Firecracker, the kernel and the init system.

Build. These numbers come from the v0.2 build before the data-file layout. Boots and restores were not measured again after that change. Guest fdatasync measured the same for both layouts.

Boot, 1 ms round tripv0.1v0.2
Cold boot, Ubuntu (empty cache)4.61 s2.33 s
Warm boot, Ubuntu / Alpine3.29 s / –2.28 / 1.44 s
Cold boot of a disk after an 8 GiB fill5.5–7.9 s2.39 s
S3 download during a cold boot (before compression)≈ 250 MiB136 MiB
Upload of a new root filesystem (270 MiB of files)5.7 s1.5 s
Guest: write 7.9 GiB of files until all data is in S3169.5 s148.6 s
Boot, 20 ms round trip (S3 in the same region)v0.1v0.2
Cold boot, Ubuntu7.46 s3.96 s
Cold boot of a disk after an 8 GiB fill8.2–9.5 s4.0 s
Warm boot, Ubuntu3.52 s2.37 s
Cold / warm boot, Alpine4.01 / 2.64 s2.68 / 1.51 s
Guest: read and check 7.9 GiB, 1 reader, cold149.6 s109.6 s

Two changes give most of the gain. Smaller chunks cut the download of a cold boot nearly in half: with 4 MiB chunks, each small read of a file or of ext4 metadata cost 4 MiB. And the attach went from about 1 s to 24 ms, because the claim is one atomic create, and each disk has its own lock.

I/O in the guest

fio in the guest, on a 4 GiB file, with direct I/O. "Idle" means a checkpoint ran before each test. "During upload" runs right after the 4 GiB file is written, while its checkpoint uploads.

fio in the guestv0.1v0.2, idlev0.2, during upload
4K random read, queue depth 32166.5k IOPS159.7k IOPS47.3k IOPS
4K random read, queue depth 126.8k IOPS27.8k IOPS20.9k IOPS
4K random write, queue depth 32124.8k IOPS110.0k IOPS100.0k IOPS
4K random write, queue depth 116.5k IOPS11.5k IOPS12.8k IOPS

Firecracker opens the device without O_DIRECT, so guest reads also hit the host page cache. v0.1 never uploaded during these tests, because it checkpointed only every 3 minutes. While an upload runs, guest reads share the SSD with it.

Guest fdatasync rates moved by up to 2 times between runs on this busy machine. In one session, both local layouts did 355 per second. Right after a 4 GiB write, while its upload ran, the data-file layout did 68 per second and the older layout none. Early writeback came after these runs, and is not measured in the guest yet.

12Memory snapshots

A Firecracker memory snapshot stores the guest RAM in a file. A restore starts a new Firecracker from that file, and the guest continues without a boot. In the test, the guest runs an HTTP server that holds 384 MiB of random data in RAM, and each GET returns a hash of all of it. So the first answer needs all app memory back, and the hash proves that it is correct. Every restore returned the correct hash.

The memory file (2 GiB) is an ordinary file on a second mica disk. mica stores it in 307 MiB: zero chunks are not stored, and the rest is compressed. Each restore uses a new clone of the root disk's snapshot.

Restorev0.1v0.2, 1 msv0.2, 20 ms
Cold: attach of the root clone and the memory disk2.43 s0.26 s0.57 s
Cold: ssh answers2.38 s0.64 s1.56 s
Cold: app answers6.71 s4.63 s5.77 s
Cold: S3 download630 MiB453 MiB–
Warm: ssh / app answers0.20 / 0.63 s0.23 / 0.71 s0.20 / 0.64 s
Memory disk in S3996 MiB307 MiB361 MiB

Warm, ssh answers 0.23 s after the snapshot load. A warm boot needs 2.28 s from attach until ssh. A cold restore is limited by bytes: the app's 384 MiB of random data does not compress, and alone it takes about 4 s on a 95 MiB/s link. A restore that touches less memory starts faster.

mica uses Firecracker's File backend: the kernel loads each page from the memory file when the guest first uses it. A userfaultfd handler that installs a recorded set of pages first was no faster cold (4.77 s against 4.82 s, both limited by the link), and slower warm on demand (3.19 s against 0.77 s). So mica stays a plain block device, not tied to Firecracker. VMs that restore from one snapshot on one machine share mica's chunk cache, so each chunk downloads once.

13Limits

  • The link sets the cold speed. mica can change the order of downloads, not the bytes that the guest needs. Compression and small chunks lower the bytes.
  • Firecracker does not pass discard to the disk. Space that a guest frees stays in mica and in S3. In the guest fill test, 4 GiB of deleted data uploaded.
  • The cache evicts by last use, from any disk. An attached disk can lose cached chunks, and the fill stops once the cache is 90% full. A mode that keeps attached disks fully local is planned.
  • An attach takes about 1 s without conditional writes, for example on Garage.
  • Writes during a large upload share the SSD with the upload and its writeback.
  • Two GC gaps. A page that GC deletes between a commit and its repair is lost if the machine loses power in that window. Without conditional writes, two GCs at the same time can hide each other.
  • One lab machine. S3 runs on the same SSD as mica, and the machine also ran other work, so tail latencies here are worse than on a dedicated node.

14Sources