The coming era of OS kernel modularity
Tags: computerscience, operatingsystems, linux, fuchsia
Published: 2019-05-29 15:28:33

---
title: The coming era of OS kernel modularity
published: true
description: Slouching toward better design, one system at a time
tags: computerscience, operatingsystems, linux, fuchsia
---

There used to be [a debate](https://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate) between folks about whether monolithic kernels or microkernels were the superior architecture. It might have been interesting, but it got pretty ugly at times. While the flame war raged on, research and development continued in parallel within both the academic and industrial worlds. Looking back on it now, it's clearly not merely a matter of monolith vs. microkernel architecture. Rather, it's a larger discussion about code modularity. 

The last few years have shown us a few key trends hidden among the often-overlooked activity in the world of Operating System (OS) development. Chief among them is the idea that the future need not look like the past. From [Google's Fuchsia](https://en.wikipedia.org/wiki/Google_Fuchsia) project to [BPF](https://en.wikipedia.org/wiki/Berkeley_Packet_Filter) in Linux, the era of kernel modularity has arrived.

![](https://source.unsplash.com/z508Zk08HNU)

# Modular kernels currently under development

If you keep your ear to the ground, you'll inevitably hear the excited rumblings of folks watching the not-so-secret development of Google's new open source [Fuchsia operating system](https://fuchsia.googlesource.com/?format=HTML). The Fuchsia kernel is called [Zircon and is written in C++](https://fuchsia.googlesource.com/zircon). Zircon is notable for a variety of reasons, not the least of which is the eschewing of the traditional POSIX standard in favor of what it's supporters refer to as "more modern" conventions. Of particular note is the intentional [deprecation of dotdot filesystem conventions](https://fuchsia.googlesource.com/fuchsia/+/master/docs/the-book/dotdot.md) for security reasons. Anyone interested in what else Google's Fuchsia team considers to be modern conventions should be referred to the [Fuchsia docs](https://fuchsia.googlesource.com/fuchsia/+/master/docs), with the most popular destination being [The Book](https://fuchsia.googlesource.com/fuchsia/+/master/docs/the-book/). This recent [set of notes](https://bzdww.com/article/163937/) from China may also be of interest.

Though Google Fuchsia has forsaken POSIX, not all modular kernels have followed suit. For example, the [Redox](https://www.redox-os.org/) project has opted to continue the POSIX tradition while clearly going for a microkernel approach. Since the goal of Redox is to make a reliable, secure, general purpose OS, the team chose to write everything in the [Rust programming language](https://www.rust-lang.org/). This seems like a great idea as Rust has really wonderful safety guarantees and very ergonomic error handling.

On the Rust front, Redox isn't the only game in town as the new [Tock](https://www.tockos.org/) OS receives more attention for targeting embedded and low-power systems. The website touts the ability for Tock to run on everything from industrial sensors to security keys to watches. If you're into IoT and value security and reliability, keep an eye on Tock.

Moreover, there's even an experimental research OS called [Manticore](https://github.com/manticoreos/manticore), also written in Rust, aiming to explore the world and concepts of [parakernels](http://penberg.org/parakernel-hotos19.pdf).

No discussion of modular kernels would be complete without a mention of the [Genode](https://genode.org/) project. Genode isn't an actual kernel so much as a microkernel construction kit. Even though it's written in C++, Genode claims that it offers a security-first approach to OS development with sights set on both IoT as well as more traditional workloads.

![](https://source.unsplash.com/xFjti9rYILo)

# The monolith strikes back

Despite its roots as a monolithic kernel, Linux was always able to sidestep an entire class of problems by leveraging [dynamically linked kernel modules](https://en.wikipedia.org/wiki/Loadable_kernel_module#Linux) at run time. However, while this has proven a successful strategy, the discussion of modularity has shifted with the advent of kernel support for running programs written using the [Berkeley Packet Filter (BPF)](https://en.wikipedia.org/wiki/Berkeley_Packet_Filter) mechanism. Originally developed for controlling network IO, BPF has since been extended (eBPF) to allow for attaching filters to various OS functions. The upshot of ePBF support in Linux is that it allows for tying code deep into the kernel without modifying the kernel itself.

[Brendan Gregg has a terrific compilation](http://www.brendangregg.com/blog/2019-01-01/learn-ebpf-tracing.html) of eBPF learning resources available on his blog and the [IO Visor project also maintains](https://www.iovisor.org/technology/ebpf) a pretty solid overview. Also, there is a [performance-oriented BPF book](https://learning.oreilly.com/library/view/linux-observability-with/9781492050193/) set to be published in October of 2019.

Even though they're certainly smaller than classical OSes, the newer world of [Unikernels](http://unikernel.org/) borrows heavily from the research world's development of nanokernels carrying with them the concept of a [LibraryOS](https://en.wikipedia.org/wiki/Operating_system#Library). Standing tall among them is the venerable [MirageOS](https://mirage.io/) project, a library OS written entirely in [OCaml](https://en.wikipedia.org/wiki/OCaml). For people interested in the "mini-monolith" (minilith?) approach of Unikernels looking to develop in languages other than OCaml, the [Unikernels website maintains a list of projects](http://unikernel.org/projects/) from which you can pick anything from Go to BEAM languages.

Another exciting option, geared more toward traditional development, is the [UniK project started by my friend Idit Levine](http://unikernel.org/), which can take almost any existing program and produce a Unikernel from it. There are examples for common languages and platforms such as [Node.js](https://github.com/solo-io/unik/blob/master/docs/getting_started_node.md), [Python3](https://github.com/solo-io/unik/blob/master/docs/getting_started_python3.md), and even [Java](https://github.com/solo-io/unik/blob/master/docs/getting_started_java.md). One of the cooler things about UniK is how clean the code is, you can read through the (Go) source and understand a great deal about how it provides a pluggable backend supporting flavors such as [rumprun](https://github.com/solo-io/unik/blob/master/docs/compilers/rump.md) and even [Firecracker](https://firecracker-microvm.github.io/).

![](https://source.unsplash.com/hsPFuudRg5I)


# What about a language VM as the kernel?

There have been multiple attempts to write OS kernels in interpreted or semi-compiled languages. Two of the most notable are actually the now defunct [JNode](http://jnode.org/) and [JX](http://www4.cs.fau.de/Projects/JX/index.html) projects. However, one additional effort from the past also stands out as significant.

The [Singularity OS](https://en.wikipedia.org/wiki/Singularity_(operating_system)) research project at Microsoft has been discontinued now for the better part of a decade, but has continued to intrigue me whenever I think about it. An attempt to make an entire OS in nothing but C# and a minimal VM, it was rumored to have heavily leveraged a Just-In-Time (JIT) compiler to provide runtime profile and optimizations far beyond what a traditional Ahead-Of-Time (AOT) compiled kernel could offer. Additionally, the supposed memory safety of such [managed](https://en.wikipedia.org/wiki/Managed_code) languages could offer some terrific security guarantees like runtime memory inspection and execution supervision.


In recent months, I have watched the development of WebAssembly (WASM) and the [announcement](https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/) of the [WebAssembly System Interface (WASI)](https://wasi.dev/) with great interest. While tools like [wasmer](https://wasmer.io/) make it easy to run applications compiled to WASM, I was just exposed to [this effort by the NanoVM folks to run WASM unikernels](https://nanovms.com/dev/tutorials/running-wasm-unikernels). Pretty cool.

![](https://source.unsplash.com/eMc0lpn1P60)

# Great, so what's the point?

There's clearly a larger discussion happening about code and system modularity in a variety of areas. As people explore techniques like [microservice architectures](https://microservices.io/) (which are NOT a solution for every problem), the community continues to develop a variety of viewpoints. Therefore, it seems only natural that OS development would have a contribution to make to such discussions and that it would be influenced in return. Let's see what develops (pun intended).