346 points · by jmmv · 3y ago · 129 comments
Thanks to KVM, and to the minimal hardware support (no PCI, no ACPI, etc), Firecracker's source is rather simple and even relatively readable for non-experts.
... as long as they're experienced at writing Rust. As a Rust newbie it took me a long time to figure out simple things like "where is foo implemented", due to the twisty maze of crates and uses directives.
I totally get why this code is written in Rust, but it would have made my life much easier if it were written in C. ;-)
Out of curiosity, what development setup do you use?
I imagine that with vanilla EMacs or vanilla Vim you’d have to do quite a bit of spelunking to answer that sort of question.
With a full-blown IDE like for example JetBrains CLion with Rust plug-in installed, it is most of the time a matter of right-click -> go to definition / go to type declaration. (Although heavy use of Rust macros can in some cases confuse the system and make it unable to resolve definitions/declarations.)
And with JetBrains CLion you still have Vim keybindings available as a plug-in.
I switched from Vim to CLion + plug-ins years ago and haven’t looked back since. (Vanilla Vim is still on my servers though so that when I ssh in and want to edit some config files or whatever I can do so in the terminal.)
I won't speak for AWS, but your assumption about what "enterprise grade" cloud vendors do is dead wrong. I know, because I'm working on maintaining one of these systems.
The "process sandbox" wars are over. Everybody lost, hypervisors won. That's it. It feels incredibly wasteful after all. Hypervisors don't share mm, scheduler, etc. It's a lot of wasted resources. Google came in with gvisor at the last minute to try to say "no, sandboxes aren't dead. Look at our approach with gvisor". They lost too and are now moving away from it.
Saying gVisor is "ultimately enforced by a normal kernel" is about as misleading & accurate as "KVM is enforced by a normal kernel" -- it is, but it's a very narrow boundary, not the usual syscall ABI.
I don't think your beliefs are well founded. AWS's EC2 by default only supoprts shared tenancy, and dedicated instances are a premium service.
But yes, they do virtualize hardware not the kernel. I'm willing to bet you could swap out vanilla containerd with firecracker-containerd for most users and they wouldn't notice a difference given they initialize so fast.
[1]: And for the non-hyperscalers with less tuning, you may be buffering I/O pages both in the guest and the host.
Beside Firecracker, there're all sorts of micro-VM being developed right now, such as crosvm, cloud-hypervisor, Kata's Dragonball, all on top of KVM.
The "hardest" part is probably sufficiently emulating Linux userspace accurately: it's a big surface area. That's why I think creating a pseudo-OS target is the best route.
1. Mechanism to capture syscalls (systrap)
2. Reimplementation of parts Linux kernel
3. Narrow set of calls to outside using Linux syscalls
This thing could be envisioned as
1. Linux syscall ABI as-is, same mechanism[a]
2. Reimplementation of parts Linux kernel
3. virt-io hardware drivers for calls to outside
So the middle part of the sandwich could look the same.
Also, I think it's worth saying that I think the work in maintaining #2 there is exactly why Google Cloud Run migrated away from gVisor. People just kept asking for more and more kernel features.
[a]: Alternatively, #1 could be replaced with unikernel like linking directly with #2.
Me personally, I think HTTP/3's move away from TCP could be really interesting for this sort of stuff. The responsibilities of the kernel could be hugely simplified if all you had were UDP/IP directly hardcoded to virtio (no need for routing, address configuration, ARP, etc), no paging etc, and the only filesystems were EROFS & tmpfs. Of course, Cloud Run's move away from gVisor shows that Enterprise clients would hate it.
https://qemu.readthedocs.io/en/latest/system/i386/microvm.ht...
The "print a message telling the user that we're rebooting, then wait a second to let them read the console before we go ahead and reboot", on the other hand...
If anyone in the OpenBSD world is interested in speeding up your boot process I'd be happy to share tips and code. It's a bit daunting to start with but with some good tools it becomes a lot of fun.
I use FreeBSD for everything from my colocated servers, to my own PC. By no means am I developer; seasoned Unix Admin at best. Bare-metal forever but welcome to the future. Especially anything that contributes to the OS.
However I hear buzz words like Lambda and Firecracker and really have no idea where the usage is. I get docker, containers, barely understand k8s but why do you need to spin up a VM only to tear it down compared to where you could just spin up a VM and use it when you really need to. Always there, always when.
Is it purely a cloud experience, cost saving exercise?
Allows you to build a compute plane where any node in the plane can service the traffic for any application.
Any one application can dynamically grow to consume the available free compute of the plane as needed in response to changes in traffic patterns.
Applications use no resources when they aren't handling traffic.
Growing the capacity of the compute plane means bringing more nodes online.
Can't come up with a use case for this beyond managing many large-scale deployments. If you aren't working "at scale" this is something that would sit below a vendor boundary for you.
As it turns out, a lot of APIs for phone apps fit this category. You don't want a machine sitting around idle 99% of the time to answer those API calls.
and always charging you :)
Firecracker has a much amaller overhead compared to regular VMs - which makes the (time and compute) costs of spinning up new VMs really low. This can be an advantage, depending on how chunky your workloads are - the less chunky they are - the more they can take advantage of finer-grained scaling.
Sometimes you just want to slap some lines pf code together and run them from time to time, and don’t need a whole server (physical or virtual) for that.
Sometimes you have no idea if you’ll have to run a piece of code 100 times a day or 10’000’000 times a day.
Sometimes you don’t feel like paying a whole month for and maintaining a whole instance for a cronjob that lasts 20 seconds, and maybe it runs once a week.
Actually you can do virtualisation on any instance type afaik, but only with .metal instances you can use hardware acceleration.
A huge thank you to Colin Percival for sharing this.
Particularly love the "Once the low-hanging fruit was out of the way" line... which to Colin means custom bus_dma patch(es).
Now anyone can now enjoy for free:
"with 1 CPU and 128 MB of RAM, the FreeBSD kernel can boot in under 20 ms"
If you're used to devops with k8s clusters or lots of docker, this is absolutely amazing.
Oh, my... how could I achieve the same on real hardware without VMs ? ;)
It's everything else that's slow. For example, this is my machine
Startup finished in 14.552s (firmware) + 2.885s (loader) + 741ms (kernel) + 23.116s (initrd) + 11.191s (userspace) = 52.488s
I've had libvirt bog standard qemu-kvm (not a microvm) creating a new Ubuntu VM from a disk image & booting to a login prompt in under 10 seconds for more than a decade. This is without fiddling with virtio, doing hardware scans for PCI, VGA, SATA and such, and booting via Grub (your "loader"). Those should be pretty comparable!