CSE Roadmap

Core tier · about 2 hours · 8 parts

Part 5 of 8 · 3 min read

Microkernels

Think of a small town hall with a few clerks that only pass messages. The library, the school and the market are run by separate offices in the town. The analogy stops in one place: offices are reached on foot, and kernel services are reached by copying messages between address spaces.

In plain words: A microkernel keeps only the essentials in the kernel and moves everything else into ordinary programs. Typically the kernel keeps basic process and memory management and a way for programs to send messages. The file system, device drivers and network stack become servers in user mode, each in its own address space.

   application    file server    disk driver     <- user mode
        \             |             /
         \------ message passing ---/
   ------------- microkernel ----------------    <- kernel mode
   hardware

A client that wants a file never talks to the file server directly. It sends a message through the microkernel, and the reply comes back the same way.

The benefits, as OSC lists them:

  • New services are added in user space, with no change to the kernel.
  • The kernel is small, so fewer changes are needed and it is easier to port to new hardware.
  • It is more secure and reliable, since most services run in user mode. If a service fails, the rest of the system keeps going.

The cost is speed. Two user-level services that must talk have to copy messages between address spaces, and the OS may need to switch from one process to another to deliver them.

A worked example.

A worked comparison (made up to show the idea). A program reads a block of a file.

  • Monolithic kernel: one system call. The file system calls the disk driver inside the kernel with a function call. Extra cost for crossing between parts: about 0.

  • Microkernel: the program sends a message to the file server (1), the file server sends one to the disk driver (2), the driver replies (3), and the file server replies to the program (4). With 4 messages at 1.5 microseconds each, the crossing cost is 4 × 1.5 = 6 microseconds, and 4 switches between address spaces add more.

If the device read itself takes 100 microseconds, the monolithic read costs about 100 microseconds and the microkernel read about 106, which is 6 per cent more. For fast operations the gap matters more.

Examples: Mach is the best-known early microkernel, and the macOS and iOS kernel (Darwin) contains it. QNX, a real-time system for embedded devices, is another.

Microkernel

A microkernel is a kernel reduced to the few services that must run in kernel mode, typically address-space management, basic scheduling and message passing between processes. All other services, such as file systems and drivers, run as separate user-mode processes that communicate by messages.

Example: in a microkernel system, the disk driver crashes and is restarted as a user program, while the rest of the OS keeps running.

Check yourself: 1. What stays in a microkernel? 2. Why is a microkernel read slower than a monolithic one? 3. In the worked comparison, how many messages does one read need?