Modular and hybrid kernels
Loadable kernel modules, the module life cycle, and how Linux, Windows, macOS and Android mix structures.
Modular and hybrid kernels
How Linux adds drivers and file systems while it is running, and why every real OS mixes structures.
The modular idea
A modular kernel has a small set of core components — scheduling, memory management, the module loader — and links in other services as loadable kernel modules (LKMs), at boot time or at run time.
Each module plugs into a defined interface of the core — and may call any other module directly.
The developer writes a module in C with an init and an exit function and compiles it against the kernel headers into a .ko (kernel object) file.
sudo modprobe ext4 (or insmod file.ko). The kernel checks the module, resolves its symbols against exported kernel functions, links it into kernel memory and calls its init function. Dependencies are loaded first by modprobe.
The module registers itself — e.g. a file system registers with the virtual file system (VFS); a driver registers for a USB vendor/device id. From now on it runs in kernel mode exactly like built-in code; calls into it are plain function calls.
lsmod lists loaded modules with their size and how many users each has; modinfo shows file, licence, description and parameters.
sudo rmmod name calls the module's exit function and frees its memory. The kernel refuses if the module is still in use (use count > 0).
$ lsmod | grep -w loop # not loaded yet: no output
$ sudo modprobe loop # load
$ lsmod | grep -w loop
loop 32768 0
$ modinfo loop | grep description
description: Loopback device support
$ sudo rmmod loop # unloadModular vs layered vs microkernel
vs layered
Both use defined, protected interfaces. But a layered system forces calls to go only downward; any module may call any other module.
vs microkernel
Both have a small core. But modules run inside the kernel's address space, so there is no message passing — faster, but a bad module can crash the kernel.
Hybrid systems in practice
| System | Structure | Why |
|---|---|---|
| Linux | Monolithic kernel + loadable modules | Speed of one address space; flexibility of modules for thousands of drivers. |
| Windows | Largely monolithic, with microkernel-style subsystems and loadable drivers | Performance, plus the ability to support several API “personalities”. |
| macOS / iOS | Darwin/XNU: Mach microkernel + BSD UNIX in one address space + kernel extensions | Mach's IPC and memory model with BSD's POSIX services, without message-passing cost between them. |
| Android | Linux kernel + HAL + native libraries + ART runtime | Re-use Linux drivers; run apps in a managed runtime; vendors plug in hardware through the HAL. |
A new Wi-Fi adapter works after `sudo modprobe` without a reboot. Which property of the kernel made that possible?
Why can a buggy loadable module still crash Linux?
macOS combines Mach and BSD in one kernel address space. That makes it a…