Part 3 of 8 · 2 min read
Monolithic kernels
Think of a one-room workshop where every tool, worker and customer shares the same space. Work is fast because everyone reaches everything at once, and one mistake can upset the whole room. The analogy stops in one place: workers see each other's errors, while code in one kernel address space cannot always tell which part broke.
In plain words: The simplest way to build a kernel is to put all of it into one large program that runs in one address space, all in kernel mode. This is a monolithic kernel. The original Unix worked like this, and Linux is built the same way. The kernel holds the file systems, the process scheduler, memory management, networking and the device drivers. Everything below the system-call interface and above the hardware belongs to it.
user programs: shell, editor, compiler, browser
----------------------------------------------
C library (glibc)
---------------------------------------------- system-call interface
| file systems | CPU scheduler | memory manager |
| networking | block devices | char devices | <- one kernel,
| device drivers | one address space
----------------------------------------------
hardware
Strengths: speed. A call from the file system into a driver is an ordinary function call, with no copying of messages and no switching of address spaces. The system-call interface has little overhead.
Weaknesses: the parts are tightly coupled. A change in one part can affect many others, so the kernel is hard to extend. Because all of it runs with full privilege, a bug in one driver can corrupt the whole kernel and crash the machine.
A worked example.
A rough size comparison (made up to show the idea). A kernel with 20 million lines of code, of which 70 per cent are device drivers, has 14 million lines of driver code. All of those lines run in kernel mode. A bug density of one serious fault per 10,000 lines would put the expected number of serious faults in drivers at about 1,400 (14,000,000 / 10,000). That is the main argument for keeping drivers out of the kernel, and it leads to microkernels (section 4).
Monolithic kernel
A monolithic kernel is a kernel in which all operating-system services (scheduling, memory management, file systems, device drivers and networking) are compiled into a single program. That program executes wholly in kernel mode and shares one address space, so any part can call any other part directly.
Example: Linux has its file systems, scheduler and drivers all inside one kernel image.
Check yourself: 1. Why is a call between two parts of a monolithic kernel fast? 2. What is the main risk of running every driver in kernel mode? 3. Does a monolithic kernel have a system-call interface?