← See all my articles

A love note to Plan9

(Sorry for longer post than usual)

A few days ago, I was randomly bored and decided to start reading about Plan9, because everybody seems to love it so much for some reason. I am now part of said cult.

Unix has always been that one system design that has just kind of... been. Right back since the original Unix in the 70s, a massive amount of operating systems, old and modern, have been based on it. For good reason too - its design was genuinely smart. I mean, `fork()` is kind of inefficient (I love modern vfork... but that's a whole different blog post), but overall it's a good design for its time.

However, Unix devs in the 90s came together and were kinda just like, "look we made a cool thing but that was decades ago for a non-networked world which was built for monolithic systems and half-assed everything-is-a-file, let's do this for REAL, for a modern networked world that works well in a microkernel or hybrid kernel with minimal speed sacrifices... and most importantly, make it ACTUALLY everything-is-a-file."

And so Plan9 was born. A beautiful experimental OS that had a stable system by using a microkernel, was actually quite performant, had much cleaner APIs, was made for networking, and of course, was still based on Unix design at heart.

I won't go through the exact details because my knowledge of Plan9 is limited, but here is a brief summary of the basic big things that are so great about Plan9.

Namespaces

These ended up actually coming to Linux to some lesser extent - basically, in Plan9 when you mount a filesystem to a mountpoint, it isn't a global thing like a single mountpoint list. Instead, there is one for each process, and these mountpoints are passed down. Like if I mount a filesystem from my shell then try access it from another already running shell, it won't work. But, it's passed down to children, so if I then run a new shell from the shell I mounted it on, I'll be able to access the mountpoint. This gives you a bunch of nifty tricks you can do with driver devices and such, but really it's just another layer of process separation where each process can have it's own entire view of the filesystem.

Everything-is-actually-a-file

Normal Unix likes to call everything a file, just because of stuff like `/dev` and `/proc`. But you know what isn't a file? Syscalls.

Imagine if every time you wanted to do a system call, you just access a file and write the command to it? That's honestly pretty much the biggest thing of Plan9, at least to me. It's a huge speed boost and gives a pretty clean API. You just have some basic IO syscalls, then the rest is writing commands to files. For example, here's how you would kill a process:

fd_t fd = procfd(pid); // get the file resource for the process it is meant to kill
write(fd, "kill", 4);

Absolutely beautiful. Plus, you now can `mmap()` the resource into memory so you can write to it without even needing a `write()` syscall - nearly zero actual syscalls needed! Tell me a better way to improve speed than to just barely ever need actual syscalls. Yes, a microkernel design can slow things down, but I daresay this compensates for that a fair bit. But that microkernel design goes a bit more to the next point...

Drivers are anonymous

Similar to how I can post ragebait takes on Reddit without anybody tracing it back to me (well you could pretty easily if you bothered, my full name is scarily easily avaliable online... but most people don't luckily!), drivers on Plan9 are the same. Of course, just like in classic Unix, they are just devices. Like any microkernel-design OS, including Unix microkernels, most of said drivers are handled in userspace. But in Plan9, these drivers are completely anonymous because there is no kind of normal IPC to handle them: a process can simply create a device and set up handlers, then another process can access it, not caring what process handles it, or even whether it's handled by the kernel or by a user program. It just does not matter. At all.

And thus ends my rant for the most part. All I'll add is, yes, it may be an experimental OS that isn't designed for real use, but that doesn't mean it's been useless in the real world. Linux has partially taken it's concept of namespaces, albeit not completely, but possibly even more importantly, Plan9 was the first to implement UTF-8, and now pretty much every modern OS supports it! Experimental doesn't mean useless, it means instead of bringing features to users, it means bringing ideas for features to other systems which can then bring them to users.

If my article was interesting...

can I send you some emails? 😔 I promise I won't spam 🌳

I will never spam you, and you can unsubscribe at any time through the emails. I don't want to sell you anything.