Replace C by Golang in Linux Kernal

By Xah Lee. Date: . Last updated: .

What happens when you replace c by golang in Linux?

would it be still fast enough to be practically usable?

Bit Diddler's Obsession with Manual Memory Management

there exist a bunch of coding idiots of the c cpp rust types, who get super excited by the so-called garbage-collection, and hates it.

they insist, any programing language must let them control the memory manually.

these types, think they are the real men, like c cpp rust, but hates golang java csharp.

in particular is cpp with game programing association. they say, any programing language with the technologically advanced automatic memory management is no good.

but if you ask them, just how much slower would a operating system written in golang, they dunno.

Here's a real answer. A great article answering this question exactly.

The benefits and costs of writing a POSIX kernel in a high-level language

by Cody Cutler, M. Frans Kaashoek, Robert T. Morris.

MIT CSAIL

Abstract:

This paper presents an evaluation of the use of a high-level language (HLL) with garbage collection to implement a monolithic POSIX-style kernel. The goal is to explore if it is reasonable to use an HLL instead of C for such kernels, by examining performance costs, implementation challenges, and programmability and safety benefits.

The paper contributes Biscuit, a kernel written in Go that implements enough of POSIX (virtual memory, mmap, TCP/IP sockets, a logging file system, poll, etc.) to execute significant applications. Biscuit makes lib- eral use of Go's HLL features (closures, channels, maps, interfaces, garbage collected heap allocation), which sub- jectively made programming easier. The most challenging puzzle was handling the possibility of running out of ker- nel heap memory; Biscuit benefited from the analyzability of Go source to address this challenge.

On a set of kernel-intensive benchmarks (including NG- INX and Redis) the fraction of kernel CPU time Biscuit spends on HLL features (primarily garbage collection and thread stack expansion checks) ranges up to 13%. The longest single GC-related pause suffered by NGINX was 115 microseconds; the longest observed sum of GC delays to a complete NGINX client request was 600 microsec- onds. In experiments comparing nearly identical system call, page fault, and context switch code paths written in Go and C, the Go version was 5% to 15% slower.