Kernel Designs
Every operating system has a kernel, but there are different opinions on how much code belongs inside it. The answer is a trade-off between speed, simplicity and robustness. Linux and Windows made different choices, and both borrowed from the other camp over time.
Monolithic kernels
In a monolithic kernel all core services (scheduling, memory management, file systems, the network stack and device drivers) run together in kernel mode, in one address space. A file system calls the disk driver with an ordinary function call.
user mode app app app
------------------------------------------------- syscalls
kernel mode +-------------------------------------+
| scheduler memory VFS ext4 TCP/IP |
| USB driver GPU driver NVMe driver | one big program
+-------------------------------------+- Fast: no extra mode switches or message copies between components.
- Risky: a bug in any driver can overwrite kernel memory and crash the whole machine (a Linux kernel panic, a Windows blue screen / bug check).
Linux is monolithic, but modular: drivers and file systems can be loaded and unloaded at run time as
modules (.ko files), so the kernel image stays small and hardware support is added on demand. Modules still run in
kernel mode with full privileges. A sample session (yours will differ):
ada@ubuntu:~$ lsmod | head -4
Module Size Used by
nvme 61440 3
nvme_core 212992 4 nvme
ext4 1105920 2
ada@ubuntu:~$ sudo modprobe vfat # load the FAT file system driverMicrokernels
A microkernel keeps only the bare minimum in kernel mode: address spaces, threads, scheduling and inter-process communication (IPC). File systems, drivers and even the network stack run as ordinary user-mode servers that talk by sending messages through the kernel.
user mode app file-system server disk driver network server
| ^ | ^
---------------|------------|----|--------------|------- IPC messages
kernel mode [ tiny microkernel: threads, memory, IPC ]- Robust and secure: a crashed driver is just a crashed process; it can be restarted. The trusted code is small enough to verify formally (seL4 has a machine-checked proof of correctness).
- Slower in naive designs: one request may cross the user/kernel boundary several times.
Examples: MINIX 3, QNX (cars, medical devices), seL4, L4 variants, and Google's Zircon (Fuchsia).
The simulation counts how many times the CPU must switch between user and kernel mode to read a file in each design.
Each -> is one hop between components:
def monolithic_read():
path = ["app", "kernel:VFS", "kernel:ext4", "kernel:disk-driver",
"kernel:ext4", "kernel:VFS", "app"]
return path
def microkernel_read():
path = ["app", "kernel:IPC", "fs-server", "kernel:IPC", "disk-driver",
"kernel:IPC", "fs-server", "kernel:IPC", "app"]
return path
def crossings(path):
count = 0
for a, b in zip(path, path[1:]):
if a.startswith("kernel:") != b.startswith("kernel:"):
count += 1 # user <-> kernel mode switch
return count
for name, design in [("monolithic", monolithic_read), ("microkernel", microkernel_read)]:
path = design()
print(f"{name:12} {crossings(path)} mode switches")
print(" " + " -> ".join(path))monolithic 2 mode switches
app -> kernel:VFS -> kernel:ext4 -> kernel:disk-driver -> kernel:ext4 -> kernel:VFS -> app
microkernel 8 mode switches
app -> kernel:IPC -> fs-server -> kernel:IPC -> disk-driver -> kernel:IPC -> fs-server -> kernel:IPC -> app
Modern microkernels make each IPC very cheap, so the gap is smaller than it looks, but the extra crossings are why mainstream desktop systems did not go fully micro.
Hybrid kernels: Windows NT and macOS
A hybrid kernel is structured like a microkernel (separate managers communicating through well-defined interfaces) but runs most of those components in kernel mode for speed.
- Windows NT:
ntoskrnl.execontains a small kernel layer plus the executive managers (object, process, memory, I/O, security, configuration), all in kernel mode, with the HAL below. Drivers (.sys) also run in kernel mode. Some pieces moved out of the kernel over time: many printer and USB device drivers now use the User-Mode Driver Framework (UMDF), so a faulty driver cannot blue-screen the machine. - macOS (XNU): the Mach microkernel and a BSD layer compiled together into one kernel-mode image; Apple now pushes third-party drivers out to user-space DriverKit extensions.
Fault isolation, simulated
What happens when a driver dereferences a bad pointer? In a monolithic or hybrid kernel the fault happens in kernel mode and the whole system goes down; in a microkernel the driver process dies and a supervisor restarts it:
def run(design):
print(f"--- {design} ---")
services = ["scheduler", "file system", "usb driver", "network"]
for s in services:
if s == "usb driver":
print(f"{s:12} BUG: invalid pointer access")
if design == "microkernel":
print(f"{'':12} driver process killed, supervisor restarts it")
print(f"{s:12} restarted, other services unaffected")
continue
print(f"{'':12} fault in kernel mode -> whole system halts")
return
print(f"{s:12} ok")
run("monolithic")
run("microkernel")--- monolithic ---
scheduler ok
file system ok
usb driver BUG: invalid pointer access
fault in kernel mode -> whole system halts
--- microkernel ---
scheduler ok
file system ok
usb driver BUG: invalid pointer access
driver process killed, supervisor restarts it
usb driver restarted, other services unaffected
network ok
On Linux the halt is a kernel panic or an "oops" (a recoverable fault that kills the current task but taints the
kernel); on Windows it is a bug check with a stop code such as DRIVER_IRQL_NOT_LESS_OR_EQUAL (the blue screen).
Other designs
| Design | Idea | Examples |
|---|---|---|
| Monolithic (modular) | everything in kernel mode, drivers loadable | Linux, FreeBSD |
| Microkernel | minimal kernel, services as user processes | MINIX 3, QNX, seL4, Zircon |
| Hybrid | microkernel structure, kernel-mode speed | Windows NT, macOS XNU |
| Exokernel | kernel only multiplexes hardware; libraries implement abstractions | research systems (MIT Aegis) |
| Unikernel | application and a minimal kernel linked into one image for a VM | MirageOS, Unikraft |
Linux also gained ways to run code safely inside the kernel without writing a module: eBPF programs are checked by a verifier before they run, and are used for tracing, networking and security. Windows has its own eBPF port. Both trends (verified kernel extensions, drivers moving to user mode) aim to keep the speed of a big kernel with fewer of its risks.
Learn more: User Mode & Kernel Mode · Kernel Modules & Drivers · Windows NT Architecture
Test yourself
Which kernel design does Windows NT use?
- Pure microkernel
- Monolithic without modules
- Hybrid
- Exokernel
Linux can load a new file system driver at run time. Where does that module's code run?
- In user mode, as a server process
- In kernel mode, with full privileges
- In a virtual machine
- In the BIOS
What is the main advantage of a microkernel?
- Fewest mode switches
- A failing driver can be restarted without crashing the system
- No need for IPC
- It needs no scheduler