Benefits of writing a Linux-like kernel using Golang include:

Costs of writing a Linux-like kernel using Golang include:

Abstract

In the early 1970s, Dennis Ritchie and a team of computer scientists at Bell Labs designed a new programming language, C. It played a crucial role in the development of the UNIX OS by researchers like Ken Thompson. Since then, C has became the dominant progamming language in operating system design. Almost all mainstream OSes, including Windows, MacOS and Linux, are written in C.

C is popular in system programming because of its flexible low-level memory control mechanism and the delivery of high performance machine code. However, in the last three decades, high-level languages like Java, C# and Go have emerged with a promise of reducing programmers’ burden of memory management by a mechanism called garbage collection.

The popularity of these high-level languages (HLL) make a few researchers at MIT, Cody Cutler, Frans Kaashoek, and Robert Morris, to ponder what exactly are the trade-offs of writing a POSIX-like kernel using them. They conducted an experiment of a monolithic POSIX kernel written completely in Go and Assembly in a paper titled “Biscuit: The benefits and costs of writing a POSIX kernel in a high-level language” OSDI ‘18

Here are the results. The garbage collection costs up 3% of CPU. The longest single garbage collector pause was 115 microseconds in NGINX server and the longest NGINX client request was delayed was 600 miliseconds. Go performance costs about 10% of CPU and its GC needs a factor of 2-3 of heap headroom to run efficiently. Lastly, they did some stress system call tests with identical source-level code paths and found that C is 5-15% faster than Go versions.

Based on these results, the authors concluded that Go is more suited for exploring new kernel designs, and VMMs, but can’t replace the current C-based Linux kernel. If the goal is to experiment with OS ideas, Go’s HLL features may help; if the goal is avoiding common security pitfalls, Go can help with its safe memory management. If the CPU performance or memory efficiency is critical, then C is more favorable than Go.

Related Work