CS PAPERS DEEP-READ · PAPER 67

Firecracker: Lightweight Virtualization for Serverless

Agache et al. · Amazon Web Services · NSDI 2020

中文 →

What did this paper do?

There is a kind of cloud service called "functions": you upload a small piece of code, never think about servers, and it runs only when someone calls it — billed by the millisecond. AWS Lambda is the biggest of them. In 2020 Amazon published the thing that actually runs your code underneath Lambda: Firecracker, a virtual machine shaved down to a skeleton. It lets one physical machine hold thousands of mutually distrusting customers' code at once, with each one booting in an eighth of a second.

First, a dilemma

Running a stranger's code on your own machine has always meant choosing between safe and fast.

A traditional virtual machine is safe: it hands each guest an entire fake computer, and whatever they do inside, they can't get out. The price is a boot that takes seconds and a few hundred megabytes of overhead — absurd for a function that runs for 20 milliseconds.

At the other end are containers: no fake computer, everyone shares one operating system and is merely shut into their own room. Light, and they start in milliseconds. But the walls of those rooms are that shared operating system, which keeps more than three hundred doors open to the outside — and those doors have been pried open before. Amazon was not willing to let mutually distrusting strangers share one operating system. The default assumption was: pick one.

The idea

Firecracker's idea is to interrogate that default: what exactly is slow about a virtual machine?

The answer: not the isolation, but the fact that it tries so hard to be a real computer. To be able to run any operating system at all, a general-purpose VM faithfully fakes an entire PC — power-on self test, floppy and optical drives, sound and graphics cards, USB ports, a whole expansion bus. On boot the guest has to walk that cabinet of fake hardware item by item, and that is where the seconds go. But a cloud function only needs to run a piece of code, not any antique PC. So shave the fake computer down to the few parts that are actually needed.

Shaved down to what?

The "computer" Firecracker hands each guest has exactly four things on it: a network card, a disk, one wire for printing logs, and a keyboard with a single key — and that key is power-off. No self test, no expansion bus, not even a boot screen: it drops the operating system straight into memory and starts at the first instruction.

Think of a capsule hotel that stops fitting every room with a kitchen, a garage and a garden, and leaves only a bed, a lock and the utilities — the guest only wanted a night's sleep anyway. Small rooms mean thousands per floor; quick turnaround means the next guest checks in as fast as the last one leaves.

Two more things came along with it. First, new building material: the program that hands out the rooms was rewritten in a language where security bugs are much harder to write, in about fifty thousand lines — where the veteran equivalent runs to over a million. Less code, fewer seams to pry at. Second, a second lock outside the door: if someone really did climb out of a room, what they land in is not the corridor but a small cage that was stripped of nearly every privilege in advance.

What it bought

Each of these "microVMs" costs under 5 MB of extra memory, takes about 125 milliseconds from creation to running customer code, and one machine can mint 150 of them per second. So a single physical machine can be packed tight with different customers' functions, none of them able to touch the others — safe and fast, no longer a choice of one. It was open-sourced in 2018, and both Lambda and Fargate run on it today.

One honest cost: this computer is deeply specialized — no graphics card, no expansion slots, so work that needs them simply cannot run here.

The one-line takeaway

Virtual machines are slow and heavy not because isolation is expensive, but because they pretend to be a real computer with everything on it. Shave the fake hardware down to a network card, a disk, a log wire and a power-off key, rewrite the manager in a safer language, and wrap a cage around it — the isolation is still virtual-machine grade, yet boot is an eighth of a second and the overhead is a few megabytes. That is how cloud functions got to be safe and cheap at the same time.

Want the architecture diagrams, the rejected alternatives, and the measured numbers? → switch to the deep read