Microkernel and Monolithic Kernel Based Operating System
Introduction
Real-time operating systems, such as Blackberry QNX, usually uses microkernel, whereas some general operating systems, such as Linux, uses monolithic kernel.
In this blog post, I would like to the difference between microkernel based operating system and monolithic kernel based operating system and their advantages and disadvantages for real-time applications.
Kernel
What exactly is kernel for an operating system? Wikipedia has very good explanations to it. In short, kernel is
- The core of operating system.
- A computer program that will be loaded into a specific area of memory.
- Usually the first program loaded on startup after the bootloader.
- The connection between applications and hardware.
Kernel Space VS User Space
Kernel space is the memory area where the kernel is loaded and is protected from access by application programs or other, less critical parts of the operating system. This protection is important because it could prevent the user from changing the kernel runtime accidentally or intentionally.
In contrast, user space is the memory area where the applications is loaded.
Microkernel VS Monolithic Kernel
Monolithic kernel contains all services that the application will use and thus the code size is very large. All the services run under the same address space. If any service fails, the entire system will crash. If the user wants to add a new service, the entire operating system needs to be modified and reloaded from startup.
Microkernel, on the contrary, only contains the most basic services including low-level address space management, thread management, and inter-process communication (IPC), and thus the code size is very small. Traditional operating system functions, such as device drivers, protocol stacks and file systems, are typically removed from the microkernel itself and are instead run in user space. Therefore, even if device driver or file system crashes, the entire operating system will not crash.
Because of the modularity of microkernel based operating system, only the required module will be loaded. So microkernel based operating system is very suitable for running on embedding device, especially for those whose computation resource is limited.
The application execution efficiency of microkernel based operating system, however, could be slower than monolithic kernel based operating system. In the monolithic system, the service is obtained by a single system call, which requires two mode switches (changes of the processor’s ring or CPU mode). In the microkernel-based system, the service is obtained by sending an IPC message to a server, and obtaining the result in another IPC message from the server. This requires a context switch if the drivers are implemented as processes, or a function call if they are implemented as procedures. In addition, passing actual data to the server and back may incur extra copying overhead, while in a monolithic system the kernel can directly access the data in the client’s buffers. Performance is therefore a potential issue in microkernel systems.
Microkernel and Monolithic Based OS
Blackberry QNX and Linux are both Unix-like operating systems. QNX is a real-time operating system which uses a priority-driven preemptive architecture which makes task scheduling deterministic and high-priority task run immediately, whereas Linux does not have “hard” real-time scheduling scheme thus the determinism cannot be guaranteed.
QNX is designed for embedding devices so it uses microkernel, whereas Linux uses monolithic kernel.
We mentioned previously that monolithic kernel based operating system has higher performance than microkernel system. Then assuming we are running an extremely powerful embedding device which is not constrained by computation resources, why would a real-time operating system, such as QNX, still choose to use microkernel instead of monolithic kernel? There are many reasons to it. But the key reason is that in a monolithic kernel based operating system the failure of any service can crash the OS and we don’t want that to happen. This feature is more important than the program execution efficiency.
References
Microkernel and Monolithic Kernel Based Operating System
https://leimao.github.io/blog/Microkernel-VS-Monolithic-Kernel-OS/