← Sun, Nov 22 digest

A real Linux kernel, compiled to WebAssembly

read article ↗ hn thread ↗

Unkernel compiles a real Linux kernel and an aarch64 CPU emulator to WebAssembly, allowing unmodified Linux distributions to boot in browser and Node environments.

read it The detailed breakdown of how it pairs a native WASM kernel with a custom aarch64 user-space emulator and JIT is a masterclass in systems engineering.

summary

Unkernel packs a real Linux kernel and an aarch64 CPU emulator written in Zig directly into WebAssembly, bypassing traditional whole-machine emulation or syscall-reimplementation approaches. It uses WebAssembly.Suspending for task switches and features a JIT that compiles hot user code blocks on the fly. This architecture allows standard Alpine and Debian binaries to run with a real MMU and persistent disk support in browsers and Node. While compute-heavy tasks lag behind native execution, syscalls and fork operations execute near native speed.

key points

  1. The kernel compiles to a single WebAssembly module and boots Alpine Linux in under a second using 48 MiB of guest memory.
  2. It implements a real MMU (Sv39 page tables) via a custom aarch64 CPU emulator called kwemu, enabling unmodified distribution binaries and copy-on-write functionality.
  3. A runtime JIT translates hot aarch64 code blocks into WebAssembly modules, significantly accelerating execution loops compared to the interpreter alone.

who should read it

Systems engineers, WebAssembly developers, and anyone curious about running unmodified operating systems inside browsers.

discussion warm

consensus

Commenters are fascinated by the technical achievement and practicality of running full Linux distributions like Alpine and Debian locally in the browser, noting successful tests with tools like Docker, Postgres, and Doom.

pushback

Some question the practical utility compared to established server-side environments, while others note the inherent performance penalties of emulating an MMU in WebAssembly.

best comment by jaen ↗

The slowest part is always emulating the MMU, as that adds a 2-3× overhead to every memory access. In that sense ARM Sv39 is not a great choice.

Usually emulators use a direct-mapped cache (basically a software TLB).

In this case though, since you control the kernel, it could use something like the MIPS software-managed TLB of the olden days, with bespoke paging data structures and fast-path page fault handlers, perhaps also using PowerPC Inverted Page Tables as inspiration. (and eg. changing page allocation strategies to constrain pages in the lower address space region to simplify cache …

It provides deep technical critique on the MMU emulation overhead and suggests alternative software-managed TLB strategies.

Generated by an LLM from the article and thread. Check the sources before relying on it.