An operating system is a large and complex program. Its internal design, or structure, affects how reliable, fast and easy to change it is.

Simple (Monolithic) Structure

Early systems such as MS-DOS had a simple structure, with no clear division between parts, and application programs could reach the hardware directly. A monolithic kernel, as in traditional UNIX and Linux, puts all the services, such as scheduling, memory management, file systems and drivers, into one large program that runs in kernel mode. It is fast, since parts call each other directly, but a fault in one part can crash the whole system, and it is hard to maintain.

Definition: Microkernel. An operating system structure in which only the most basic functions run in the kernel, while other services run as separate user-level processes that communicate by message passing.

Layered Structure

In a layered structure, the OS is divided into layers, each built on the one below. Layer 0 is the hardware and the top layer is the user interface. Each layer uses only the services of the lower layers. This makes the system easy to build, debug and verify, one layer at a time, as in the THE system of Dijkstra. Its drawbacks are that defining the layers is hard, and passing through many layers makes calls slower.

Microkernel Structure

A microkernel keeps only the essential functions in the kernel: basic process and memory management and inter-process communication. Other services, such as file systems and device drivers, run as user-level server processes, and they communicate by message passing through the microkernel. It is more reliable and secure, since a failing server does not crash the kernel, and easier to extend and port. But message passing adds overhead, so it can be slower. Examples are Mach, QNX and MINIX.

Modular and Hybrid Structure

A modular kernel has a small core and loadable kernel modules, which can be added or removed while the system runs, such as a new device driver. It combines the speed of a monolithic kernel with the flexibility of a microkernel, and is used by Linux and Solaris. Hybrid systems, such as Windows and macOS, mix these ideas. macOS uses the Mach microkernel together with BSD UNIX parts.

Virtual Machines

A virtual machine structure gives each user the illusion of a separate computer, by running guest operating systems on a hypervisor that shares the real hardware. Examples are VMware and VirtualBox.

Table 1.5: Comparison of OS structures

Structure Strength Weakness
Monolithic Fast Hard to maintain, one fault crashes all
Layered Easy to debug and verify Slower, layers hard to define
Microkernel Reliable, secure, extensible Message-passing overhead
Modular Fast and flexible Modules run in kernel mode

Example 1.5: Choosing a structure

Problem: Which structure suits (a) a safety-critical car controller that must not crash if a driver fails, (b) a desktop OS that must load new drivers without restarting, (c) a teaching OS whose parts must be checked one at a time?

Solution:

  1. Isolating failing drivers suggests a microkernel.
  2. Loading drivers at run time suggests a modular kernel.
  3. Checking parts in turn suggests a layered structure.

Result: (a) microkernel, (b) modular, (c) layered.

#include <stdio.h>
#include <sys/utsname.h>
int main(void) {
    struct utsname u;
    if (uname(&u) == 0)
        printf("Kernel name: %s\n", u.sysname);
    printf("uname() is a system call answered by the kernel.\n");
    return 0;
}

Output

Kernel name: Linux
uname() is a system call answered by the kernel.

Common mistakes

  • Thinking that a microkernel is always faster. Message passing adds overhead.
  • Confusing a modular kernel with a microkernel. Modules run in kernel mode.
  • Believing that Linux is a microkernel. It is a modular monolithic kernel.

Key takeaways

  • Monolithic kernels are fast but fragile.
  • Layered systems are easy to debug but slower.
  • Microkernels move services to user space and use message passing.
  • Modern systems are modular or hybrid.

Practice questions

  1. What is a microkernel?
  2. Give one advantage of the layered structure.
  3. What is a loadable kernel module?

Answers to the practice questions

  1. A small kernel with only basic functions, other services running as user processes that communicate by messages.
  2. Each layer can be built, tested and verified on its own.
  3. A part of the kernel, such as a driver, that can be added or removed while the system runs.

Sources

  • Official BCA syllabus Operating Systems, course code 25BCA402DS03, Unit I