mica v2: disks that live in a bucket

How the new mica works, why it is built this way, and what it costs. The first sections need no background. Each section after them adds one idea.

Plan and build log · November 2026 · branch v2 of the mica repository

New to this?Read "The idea", "Words" and "A write". The pictures carry most of it.
An engineer?Read "The head is the lock" and "Freeing objects without a garbage collector".
Deciding to use it?Read "Using mica", "The cost of a 50 GB disk" and "Limits".

1. The idea

A computer keeps files on a disk. A normal disk is a part inside one machine. When the machine breaks, or when you want the files on another machine, you must copy them.

Cloud companies sell object storage, such as Amazon S3 or Cloudflare R2. It holds files of any size, called objects, in a bucket. It is cheap, it does not break, and it has no size limit. But it is slow: each request takes many milliseconds, and an object can only be written as a whole.

mica joins the two. It gives Linux a normal disk, /dev/mica/<name>. The full content of the disk lives in a bucket. The machine keeps the newest writes and a cache on its local SSD, so most reads and writes run at the speed of the SSD. Another machine can take the disk, and it downloads only the parts that it reads.

Think of a library and a notebook. The library (the bucket) has every page, but a trip there is slow. The notebook (the local SSD) has the pages you use now. You write in the notebook. From time to time, you take the new pages to the library.

One node. A program or a VM uses /dev/mica/data like any disk. The Linux driver ublk sends each request to the mica daemon, a normal program. The daemon uses the local SSD first and the bucket when it must.

The main use is a data disk: a VM starts from its own small local disk, and keeps its database or its files on a mica disk. A VM can also start from a mica disk, and a laptop can use one as a very large folder.

2. Words

This page uses each word with one meaning only.

Node
A Linux machine that runs mica.
Daemon
The one mica program on each node. It serves all disks of the node.
Chunk
The disk is a row of chunks of the same size, 1 MiB by default. A chunk is the unit of upload and download.
Entry
The name of the content of one chunk: the transaction that wrote it (its birth) and the SHA-256 of its bytes. A chunk of zeros has the zero entry and is never stored.
Page
The entries of 1,024 chunks, stored as one object.
Root
The entries of all pages: one root names one full version of the disk.
Transaction
One upload of changed chunks, then their pages, then a new root. Each transaction makes a new version, with the next number.
Head
A small object that names the current version, the owner and the snapshots. It is the only object that mica writes again.
Owner
The node that has the disk now. Only the owner writes to the disk.
Snapshot
A name for one version, kept until you delete it.
Local chunk
A chunk whose current bytes are in the data file on the node.
Unsaved
A local chunk whose bytes are not in the bucket yet.
Cache
Files of chunks that are also in the bucket, kept on the node to read them fast.

3. What the bucket holds

Each disk has its own folder in the bucket. Each transaction has its own folder in it. An object goes into the folder of the transaction that wrote it, and nothing ever writes it again. Only the head changes.

A read path through the bucket. The head names the root. The root names each page. Each page names each chunk. An entry gives the folder of its object, so mica never lists the bucket to find data.
d/<disk>/head                          the only object that changes
d/<disk>/0000000000000029/root         version 41
d/<disk>/0000000000000029/p/0          a page written by transaction 41
d/<disk>/000000000000000c/c/6          chunk 6, written by transaction 12

Chunks are compressed with zstd. A new disk of 1 TiB costs nothing until it is written: its root is empty, and pages and chunks of zeros are never stored. In the lab, a 3.1 GB MariaDB database used 1.3 GB in the bucket, and a 4 GiB boot disk used 206 MiB.

4. A write

Follow one write of 4 KiB from a database.

  1. The kernel gives the request to a queue thread of the daemon.
  2. The write falls into one chunk. If the chunk is local, the thread writes the bytes into the data file at once. The bytes go from the request to the file with no copy in memory.
  3. If the chunk is not local, the daemon first puts the current bytes of the chunk into the data file, from the cache or from the bucket. Then it writes. The chunk is now local and unsaved.
  4. The database asks for a flush: "make my writes safe from a power loss". The daemon syncs the data file to the SSD, then adds the new local chunks to the dirty log, a list of local chunks on the SSD.
  5. Every 5 minutes, a transaction uploads the unsaved chunks, then their pages, then the root. Last, it writes the head. That one write makes the new version real. The interval is a setting of each disk. A transaction also starts early when the unsaved data fills half of its limit.
The write path. Steps 1 and 2 are on the node and take microseconds to milliseconds. Steps 3 and 4 run in the background. A crash before step 4 leaves only objects that no version names.

The data file is sparse: a chunk that is not local is a hole and uses no space. The order in a flush matters. The dirty log never lists a chunk before its bytes are on the SSD. After a power loss, mica cuts out every part of the data file that the log does not list, because these parts can hold half-written data.

A saved chunk stays in the data file while the saved chunks are less than the cache budget of the disk. Then the oldest ones move into the cache, and their part of the data file becomes a hole again.

5. A read

mica looks for a chunk in four places, from fast to slow:

  1. The data file, for a local chunk.
  2. Nowhere, for a zero chunk: it returns zeros.
  3. The cache.
  4. The bucket. The download is checked against the hash in the entry, then kept in the cache.

Reads of the data file and of the cache go from the file to the request with no copy in memory. Three helpers download data before it is read:

The cache is per node and by hash. Ten VMs made from one image download each chunk once for the node.

6. The head is the lock

Two nodes must never write one disk at the same time. Each would make its own versions, and one would delete objects that the other needs. Many systems use a separate lock service for this. mica uses only the bucket.

S3 has conditional writes. A write with If-Match: <tag> works only if the object did not change since you read it and got that tag. If the object changed, the bucket refuses the write with status 412. mica writes the head only this way.

A race for one disk. Both nodes read the same head. Only one conditional write can win, because the first one changes the tag. The loser stops.

Before mica disk create, mica tests the bucket with a probe object. Some buckets ignore the conditions, such as Garage. mica works there too, because it reads the head before each head write and stops when the head changed. But two nodes that read at the same moment can both win, so create prints a warning: attach such a disk on one node only. A bucket that refuses conditional writes, such as Backblaze B2, cannot hold mica disks.

7. Freeing objects without a garbage collector

A transaction replaces some chunks. Their old objects can be needed by a snapshot, or by nothing. Many systems run a garbage collector: a job that lists the whole bucket and finds objects that nothing uses. That job gets slower as the bucket grows, and it must not delete objects that a running upload is about to use.

mica needs no such job. Two facts make this possible:

  1. Each object belongs to one disk, and only the owner deletes.
  2. The versions of a disk form one line. An old object is still used only if a snapshot holds a version from the time the object was alive.
The free rule at transaction 9. The newest snapshot before 9 is at 4. A replaced object born after 4 has no snapshot that uses it: delete it now. An object born at 4 or before stays.

Free rule. After transaction n, let K be the newest snapshot before n. Delete each chunk and page that n replaced and that was born after K. Then delete the old root. The root goes last, so a crash in the middle leaves a root that shows the work left.

Merge rule. To delete a snapshot S, compare it with the next version that is kept. Delete each object that only S has and that was born after the snapshot before S. Only pages that differ are read.

The result: each transaction deletes exactly what it replaced, at once, with no list of the bucket. A disk with no snapshots holds one version in the bucket, no more.

8. Moving a disk, snapshots, restore

Detach removes the device, runs transactions until nothing is unsaved, and writes the head with no owner. When it returns, any node can attach the disk. Attach claims the disk and makes the device. It downloads nothing at first.

sudo umount /mnt/photos && sudo mica disk detach photos   # shows the upload
sudo mica disk attach photos && sudo mount -o discard /dev/mica/photos /mnt/photos   # on another node

A snapshot is a name for a version. It is free: it only stops the free rule from deleting objects of that version.

mica has no rollback. To go back, make a new disk from a snapshot. mica disk restore db before-upgrade db-old copies the objects inside the bucket with S3 CopyObject. The node downloads nothing, and the new disk does not depend on the old one.

9. Crashes and restarts

What happensWhat mica does
mica restarts, for example for an upgradeThe kernel keeps each device paused. The new daemon takes it over with the user recovery feature of ublk. The guest sees a pause of about one second. File systems stay mounted.
mica crashesThe same. The kernel sends the requests in flight again. A recent bitmap in memory lists the chunks written since the last flush, so none is lost.
Power loss or rebootWrites after the last flush can be lost, as on any disk with a write cache. The dirty log makes sure that no half-written data comes back. At boot, the daemon claims each disk of the node again and makes a new device, before systemd mounts the disks of fstab. When the network is not up yet, it tries again every 10 seconds. It gives up the local data only when the bucket says that another node has the disk.
The bucket is downLocal and cached data still work. Writes go on until the unsaved data reaches its budget, then wait. Transactions try again.
Another node takes the diskThe old owner fails its next head write and stops.
The SSD fails a syncThe disk stops for good. Linux reports such an error only once, so a later sync that works proves nothing.

In the lab, the daemon was killed twice with SIGKILL while a guest wrote files with fsync. All 400 of 400 synced files were correct after each takeover, and again after a full download on a new node.

A power-cut test goes further. The data folder of the daemon sits on a device-mapper device that can drop every write from one moment on, as a power cut does. A writer fills a disk with blocks that name their own version and flushes often. At a random moment, the writes stop reaching the device. Then the daemon is killed, the device is deleted, and the folder comes back as the device had it: a reboot. The daemon serves the disk again, a detach uploads all, and every block is checked against the last flush. In 6 of 6 cuts and 4 of 4 daemon kills, no flushed write was lost.

10. Bugs the tests found

One MariaDB run failed after a restart of the daemon: InnoDB found a redo log of zeros. A chunk of that log was stored in the bucket as the zero entry, and the data file had a hole in its place.

The cause was two daemons on one data folder. A stopped daemon runs its last transactions for up to one minute. The lab script started the next daemon after two seconds. The new daemon read the dirty log and took the chunk as local. Then the old daemon moved the chunk to the cache and cut its hole. The new daemon read zeros there and uploaded them.

systemd waits for the old process before it starts a new one, so a normal service restart was safe. But a correct program must not depend on the care of its user. Now each daemon locks its data folder and its run folder, and a second daemon refuses to start. A replay with 1 GiB written just before the restart gave the same SHA-256 before and after the restart, and on a new node.

The second bug hid in mica status. The status of a disk read several values, each under its own lock, in one Rust expression. In such an expression, each lock stays held until the whole expression ends. One of the values took the lock of the limits a second time, so the status waited for itself. This happened only when the disk had unsaved data, and then it also held the locks that writes need. A test of the CLI with real writes found it. Now each lock is taken alone, and a test calls the status of a disk with unsaved data.

The power-cut test found the third. The daemon wrote a few small files without a sync: the random id of the node, the keys of a bucket, and the bucket of each disk. A cut soon after the first start left the id file empty. At the next start, the daemon did not know its own id, so it took its own disk for the disk of another node, and kept the local data aside as orphaned. Now each of these files is written as the state file always was: a new file, synced, renamed into place, and then the folder synced.

A reboot of a real server found the fourth. A disk in /etc/fstab was not mounted at boot. mica made the link /dev/mica/<disk> itself, but systemd knows only the devices that udev names, so the mount waited for a device that never came. Now mica service install writes a udev rule, and udev names each mica device. After two reboots with unsaved data on the disk, the server mounted it each time, and the files had the same SHA-256.

11. Measurements

Setup. These runs used the first settings of v2: chunks of 256 KiB and a transaction every 30 seconds. A Firecracker VM with 2 vCPUs and 2 GiB of RAM. It starts from a local root disk, and its data disk holds MariaDB with 3.1 GB of data: sysbench, 12 tables of 1 million rows, 8 threads, a 512 MiB buffer pool. The bucket is RustFS in a container on the same laptop, behind a link shaped to 800 Mbit/s with a round trip of 1 ms or 20 ms. "Local" is the same disk image as a plain file on the same SSD. "Cold" is a new node with an empty cache and no fill: each first read goes to the bucket.

sysbench transactions per second. Read-only is as fast as local, even cold and at 20 ms. Read-write is 40 to 50 % of local.
RunRead-only tpsRead-write tpsRead-write p95
Local file (btrfs)2,180497–70325–28 ms
mica, cold, round trip 1 ms2,131–2,203217–242119–128 ms
mica, cold, round trip 20 ms2,14024998 ms
mica, warm2,229–2,270207–250105–137 ms
Local file (ext4)—421–48531–36 ms
mica on ext4, warm—213–22472–83 ms

Cold start

A cold disk is slow only at the start. At 1 ms, the read-only run gave 1,056 tps in its first 10 seconds and full speed after 30 seconds. At 20 ms, it gave 772 tps in the first 10 seconds and full speed after 30 seconds.

Boot of the VMssh readyMariaDB ready
Local root disk, mica data disk, cold2.2 s2.4 s
Root disk and data disk on mica, cold, no fill2.3 s7.3 s
Both on mica, new node, profile and fill2.3 s4.4 s

Why read-write is slower than local

The time goes to flushes. In a 60-second run, the syncs of the data file took 55 seconds: about 7,500 flushes of 7 ms each, one at a time. A flush must be one at a time, because Linux reports a write error only once per file. Flushes that wait at the same time already share one sync.

Three things make a mica flush more expensive than a flush of a plain file:

One change helped: saved chunks now stay local up to the cache budget. On ext4, this made read-write steady at 213–224 tps. Before it, three runs gave 217, 157 and 164 tps, and the chunk copies were about ten times more. Two other changes did not help speed. One data file for each disk, in place of one file per GiB, made the code simpler but gave the same results. With 64 KiB chunks, read-write fell to 120–185 tps.

12. The cost of a 50 GB disk

A bucket bills three things: the stored bytes, the requests, and sometimes the bytes downloaded (egress). The stored bytes are cheap: 50 GB in Cloudflare R2 costs $0.60 a month. mica stores compressed chunks, so 50 GB of data can take less. The requests are the part to watch.

Each transaction uploads each chunk that changed since the last one, once. So the bill follows the number of different chunks that change in each interval, not the number of writes. Two settings of the disk set it: the interval and the chunk size.

How it was measured

A 3 GB MariaDB database ran sysbench at a fixed rate for 15 minutes, with the reads and writes of the database. Most writes go to a few hot rows (a Pareto distribution), as in a real app. The kernel traced each write to the data disk. A script then counted the different chunks in each interval. A transaction also writes one page per 1,024 chunks, a root and a head.

Workload, all dayFirst v2: 30 s, 256 KiBNow: 5 min, 1 MiB5 min, 4 MiB
Small app$67$19$7
Business app$923$108$25
Busy app$2,136$114$26

Cloudflare R2 requests per month, in USD, after the free million. Add $0.60 for the storage of 50 GB. AWS S3 costs about 15 % more for the same requests.

The new defaults cut the bill by 3 to 19 times. A longer interval helps because a hot chunk that changes 10 times in 5 minutes is uploaded once. From the business app up, the bill stops growing with the load. Almost the whole database changes in each 5-minute round: about 3,000 of its 3,100 chunks of 1 MiB. InnoDB writes its changed pages back about every 8 minutes, and the updates of secondary indexes fall all over the tables. So the cost is about one upload of the database for each interval.

For comparison, a 50 GB gp3 disk on AWS EBS costs $4 a month.

Tune the database

The bill of a database depends most on one thing: does its data fit in its memory? Three more runs lasted 60 minutes each, long enough for the redo log to fill and wrap. They set innodb_log_file_size=2G, innodb_adaptive_flushing_lwm=50 and innodb_max_dirty_pages_pct=90. The 3 GiB buffer pool ran in a VM with 4 GiB of RAM.

RunBuffer poolWritten each minute1 MiB chunks changed in 5 minR2, 1 MiBR2, 4 MiB
Business app, default settings512 MiB383 MiB2,878$108$25
Business app, 2 GiB redo log512 MiB322 MiB2,904$109$26
Business app, 2 GiB redo log, data in memory3 GiB54 MiB138$1.10free
Busy app, default settings512 MiB1.1 GiB3,050$114$26
Busy app, 2 GiB redo log, data in memory3 GiB226 MiB446$13$0.21

Cloudflare R2 requests per month, in USD, at a 5-minute interval. "Free" means fewer than the free million requests. The runs with default settings lasted 15 minutes.

A larger redo log alone changes nothing. A small buffer pool must write changed pages back to make room, so each round still changes almost the whole database. When the data fits in the buffer pool, InnoDB keeps the changed pages in memory and writes them back rarely. Most writes then go to the redo log, which is sequential and changes few chunks. The bill falls about 100 times for the business app, and about 9 times for the busy app.

ProviderWorks with micaStorage onlyLaptopBusiness app
Cloudflare R2Yes: documented If-Match and If-None-Match$0.60$0.60$108
AWS S3 StandardYes: documented$1.15$2.36$126
Hetzner Object StorageProbably: not tested$7.01$7.01$7.01
WasabiNot checked$7.99$7.99$7.99
Your own Garage serverYes, with a warning: it ignores conditional writesthe serverthe serverthe server
Backblaze B2No: rejects conditional writes$0.28——

USD per month, November 2026, 5-minute interval and 1 MiB chunks. The laptop writes 1 GB and reads 3 GB from the bucket each day. R2 includes 10 GB, one million writes and ten million reads free each month, and has no egress fee. Hetzner is a flat €6.49 for up to 1 TB with no request fees. Wasabi bills 1 TB at minimum, for at least 90 days.

Recommendation. For a laptop or a quiet data disk, use Cloudflare R2: about $0.60 a month for 50 GB, and the first 10 GB are free. For a database that writes all day, give it a buffer pool that holds its data and a 2 GiB redo log: in the lab, this cut the bill of the business app from $108 to about $1 a month on R2. When the data cannot fit in memory, make the disk with 4 MiB chunks, for about $25 a month. Or use a store with no request fees, such as Hetzner or a Garage server of your own. Run mica bucket add on a new store first: its probe tells you if the store works with mica.

13. Using mica

The mica command talks to the daemon. You give the bucket only once: with mica bucket add, at the first disk create, or at the first disk attach of a disk that another machine made. The daemon keeps each bucket that works, readable by root only, and that is the only copy of its keys on the machine. After that, a command needs only the name of the disk. A machine with more than one bucket picks one by name, such as --bucket photos, with no keys. New keys for a bucket replace the old ones, and the attached disks use them at once.

sudo mica service install                                 # start mica now and at each boot
sudo mica disk create data --size 50G --store s3.toml     # the bucket file, once
sudo mica disk attach data                                # makes /dev/mica/data
sudo mkfs.ext4 /dev/mica/data                             # once, for a new disk
sudo mount -o discard /dev/mica/data /mnt/data

The bucket file has the endpoint, the bucket and the keys. Each value can also come from a flag, such as --bucket, or a variable, such as OBJECT_STORAGE_BUCKET. Each answer ends with the next step as a command to copy:

✔ Attached disk data as /dev/mica/data
  The disk is new. Make a filesystem on it once: sudo mkfs.ext4 /dev/mica/data
  Mount it: sudo mkdir -p /mnt/data && sudo mount -o discard /dev/mica/data /mnt/data

mica status shows the disks of this machine at work. --watch shows it again each second. This is a real run of dd that writes to a new disk:

mica 0.2.0 on laptop. 1 disk attached.

DISK     DEVICE             READ  WRITE   UPLOAD  DOWNLOAD  UNSAVED     CACHE     LAST SAVE  STATE
dx-demo  /dev/mica/dx-demo  -     150M/s  -       -         1000M / 4G  0 / 512M  never      ok

Unsaved is the data that is only on this machine. Cache is a local copy of data that is in the bucket. mica disk ls shows the disks of every bucket that the machine knows, and where each one is attached:

Bucket https://s3.example.com/my-disks/laptop
DISK     SIZE  WHERE                      UNSAVED  CACHE  LAST SAVE  SNAPSHOTS
dx-copy  3G    ● here: /dev/mica/dx-copy  0        1M     1 min ago  0
dx-demo  4G    ○ detached                 -        859M   1 min ago  2

A detach uploads all unsaved data first, and shows the upload. This one went from a laptop to a bucket in Mumbai:

⠙ Uploading dx-demo  ━━━━━━━━━━━━━─────────── 103M / 200M  7.3M/s  13s left
✔ Detached disk dx-demo. The bucket has all its data, so any machine can attach it
CommandWhat it does
mica status [--watch]The disks of this machine: speed, unsaved data, cache, last save
mica disk lsThe disks in the known buckets, and where each one is attached
mica disk info <disk>One disk: where it is, its limits and its snapshots
mica disk create <disk> --size 50GA new disk. Options: --chunk-size (1M), --cache-size (512M), --unsaved-size (4G), --interval (5m)
mica disk attach / detach <disk>Make the device, or upload all and give the disk free
mica disk set <disk>New limits, or a larger size. The limits follow the disk to other machines.
mica disk restore <disk> <snapshot> <new disk>A new disk from a snapshot, copied inside the bucket
mica disk release <disk>Free a disk whose machine is gone for good
mica disk delete <disk>Delete a disk and its snapshots
mica snapshot create / delete <disk> <name>Keep a version under a name. A create uploads all changes first.
mica bucket add / ls / forgetThe buckets that the machine keeps keys for
mica service install / uninstall / statusThe systemd service and the udev rule. An install after an upgrade restarts mica. An uninstall deletes the saved keys.

14. A large disk for a laptop

mica can give a laptop a folder that holds terabytes, with the data in a bucket. sudo is needed once, to set it up. After that, you use the folder with no sudo. The disk is a normal line in /etc/fstab:

sudo mica service install
sudo mica disk create photos --size 1T --chunk-size 4M --cache-size 20G --store s3.toml
sudo mica disk attach photos
sudo mkfs.ext4 /dev/mica/photos
echo "/dev/mica/photos /home/me/photos ext4 discard,nofail,x-systemd.requires=mica.service 0 0" | sudo tee -a /etc/fstab
mkdir -p ~/photos && sudo mount ~/photos && sudo chown "$USER:" ~/photos

At boot, the daemon attaches the disk again before it tells systemd that it is ready, and udev names the device, so the fstab mount finds it. This was tested with two reboots of a server. At shutdown, mica runs one last transaction for at most one minute, and the rest of the unsaved data stays on the laptop. So a shutdown never waits for a full upload. Give the disk a large cache, so that most reads stay local without a network.

mica uses only ublk, a part of Linux 6.16 and later. It does not use FUSE.

15. Limits and next steps

The code of v2 is about 7,200 lines of Rust in 39 files, against 9,000 in v1, with 32 tests. Two tests run random writes, flushes, transactions and restarts against a plain array, and many writers against background transactions.

Sources