Why would one rewrite Mach?
Over the past few months, I have been writing a microkernel aiming at being effectively a Mach rewrite.
The response to this, when I shared my plans with friends who share my interests, was a simple, almost desperate question: Why, Gianluca, why would you do that?.
Definitely an interesting question, so I thought this would be a good time to write about it.
The many reasons behind a personal project.
In the spring of 2024, I picked up an old project of mine, NUX, and brought it to a state where I could easily build portable kernels that would run on real, modern hardware.
The first test I made was to port Murgia Hack to NUX. The port, which allowed MH to run on two new architectures, RISCV64 and AMD64, was straightforward. But the architecture of NUX is heavily influenced by the design choices of MH, so it was not meant to be difficult.
What I needed was a challenging kernel. I briefly considered a classical UNIX system, but then it occurred to me that there's always been a microkernel-shaped hole in my life: Mach.
Mach and me, a personal story.
I remember the first time I downloaded the GNU Hurd sources. It was the mid-to-late 1990s. The first thing I've heard about the Hurd was this famous Linus Torvalds quote:
In short: just say NO TO DRUGS, and maybe you won't end up like the Hurd people.
Truth is, the promise of GNU Hurd was exciting. It was considered the next big thing. It was an architecture that allowed to play with the fundamentals of a UNIX system by providing translators.
It took me days to finally build the toolchain and the sources, and being able to boot GNU Mach on my 486.
At that time – I was a high school student – I was able to understand some parts of the Linux Kernel code, and so I decided to study Mach. And so, with the usual youth optimism and fearlessness, I printed the "Mach 3 Kernel Principles" on my super-slow early ink jet printer, and spent nights reading it. Then I started looking at the code.
Me and the Mach source code
If you have ever looked at Mach's source code, you know where this story is going. I was unprepared for that code. I finally understood something my mediocre Italian Literature teacher was failing to explain at the time: Dante's trip to the Inferno.
There was something off about the purity, clarity of the Mach principles and architecture, as explained in the documentation, and its code.
I was always interested in memory management, and the VM code seemed to me, at the time, designed to bring the worst doubts about one's own capacity to understand things.
As a reaction, I went on and decided to start writing my own kernel. But this is another story.
I stayed around the Hurd community for quite some time. Despite what Linus said about them – us? –, there were some really nice people in the project. Many of them I still consider my friends.
Sto-Mach
With the years, I started being a bit more at ease with the Mach
source code, and in 2005, as a late computer engineering student at
university, I presented Sto-Mach at the Hurd Meeting in
Madrid. Sto-Mach was my reaction to a project called
oskit-mach
. Based on
oskit, oskit-mach
removed
much of the Mach core and substituted it with oskit
components. Sto-Mach did the opposite. Kept the core of Mach
intact, removed the Linux 2.0 driver glue code, and used oskit
components as drivers.
The result was slightly better. Now we had Linux 2.2 drivers, but more importantly a COM-based interface – yes, oskit packaged other operating system source code in this Microsoft standard – to write drivers.
I have recently found the source code of Sto-Mach in my archives. I will be writing a blog post about it. For now, only slides of that presentation are available on my talks page.
Shortly after that, I left university, and started my career as a hypervisor engineer. And I forgot many details about Mach.
MACHINA: a NUX-based Mach clone.
Now, should be clearer why, when faced with the choice of a challenging kernel architecture to implement in NUX, I chose Mach.
By coincidence, right when I was thinking about doing it, I found, while unpacking the boxes after the move to a new flat, my old printed version of Mach 3 Kernel Principles I spent so many nights reading, decades ago.
On re-reading it, I re-discovered my fascination for that architecture, and decided that I wanted to rewrite Mach, to answer questions that now, as a seasoned system engineer, I can finally face:
- Does Mach have to be this complex to achieve this functionality?
- What would a modern Mach implementation look like?
- What architectural decisions of Mach would not be made today?
Is Mach easy to rewrite? No, it is not. Is this going to be a replacement for Mach? No, it will not. But sometimes, the best way to understand a system is reimplementing it.
I will introduce MACHINA at FOSDEM 2025. See you there!