Why is Linux called a monolithic kernel?

ArchitectureOperating SystemLinux Kernel

Architecture Problem Overview


I read that Linux is a monolithic kernel. Does monolithic kernel mean compiling and linking the complete kernel code into an executable?

If Linux is able to support modules, why not break all the subsystems into modules and load them when necessary? In that case, the kernel doesn't have to load all modules initially and could maintain an index of the functions in the module and load them when necessary.

Architecture Solutions


Solution 1 - Architecture

A monolithic kernel is a kernel where all services (file system, VFS, device drivers, etc) as well as core functionality (scheduling, memory allocation, etc.) are a tight knit group sharing the same space. This directly opposes a microkernel.

A microkernel prefers an approach where core functionality is isolated from system services and device drivers (which are basically just system services). For instance, VFS (virtual file system) and block device file systems (i.e. minixfs) are separate processes that run outside of the kernel's space, using IPC to communicate with the kernel, other services and user processes. In short, if it's a module in Linux, it's a service in a microkernel, indicating an isolated process.

Do not confuse the term modular kernel to be anything but monolithic. Some monolithic kernels can be compiled to be modular (e.g Linux), what matters is that the module is inserted to and runs from the same space that handles core functionality (kernel space).

The advantage to a microkernel is that any failed service can be easily restarted, for instance, there is no kernel halt if the root file system throws an abort. This can also be seen as a disadvantage, though, because it can hide pretty critical bugs (or make them seem not-so-critical, because the problem seems to continuously fix itself). It's seen as a big advantage in scenarios where you simply can't conveniently fix something once it has been deployed.

The disadvantage to a microkernel is that asynchronous IPC messaging can become very difficult to debug, especially if fibrils are implemented. Additionally, just tracking down a FS/write issue means examining the user space process, the block device service, VFS service, file system service and (possibly) the PCI service. If you get a blank on that, its time to look at the IPC service. This is often easier in a monolithic kernel. GNU Hurd suffers from these debugging problems (reference). I'm not even going to go into checkpointing when dealing with complex message queues. Microkernels are not for the faint of heart.

The shortest path to a working, stable kernel is the monolithic approach. Either approach can offer a POSIX interface, where the design of the kernel becomes of little interest to someone simply wanting to write code to run on any given design.

I use Linux (monolithic) in production. However, most of my learning, hacking or tinkering with kernel development goes into a microkernel, specifically HelenOS.

Edit

If you got this far through my very long-winded answer, you will probably have some fun reading the 'Great Torvalds-Tanenbaum debate on kernel design'. It's even funnier to read in 2013, more than 20 years after it transpired. The funniest part was Linus' signature in one of the last messages:

Linus "my first, and hopefully last flamefest" Torvalds

Obviously, that did not come true any more than Tanenbaum's prediction that x86 would soon be obsolete.

NB:

When I say "Minix", I do not imply Minix 3. Additionally, when I mention The HURD, I am referencing (mostly) the Mach microkernel. It is not my intent to disparage the recent work of others.

Solution 2 - Architecture

Monolithic kernel means that the whole operating system runs in kernel mode (i.e. highly privileged by the hardware). That is, no part of the OS runs in user mode (lower privilege). Only applications on top of the OS run in user mode.

In non-monolithic kernel operating systems, such as Windows, a large part of the OS itself runs in user mode.

In either case, the OS can be highly modular.

Solution 3 - Architecture

> ;tl-dr - No, Linux is always monolithic.

Linux modules may mean modular in some sense. As others have noted monolithic is usually representing a microkernel versus monolithic kernel. A traditional microkernel only has these features,

  1. Scheduling
  2. Memory management
  3. Inter-process communications

There are no hardware drivers, protocol stacks, filesystems, suspend/resume, clock management, etc in the main kernel. These things are identical to any user task (although they may have different privileges via the MMU/scheduler).


Tanenbaum's predictions

  1. Microkernels are the future
  2. x86 will die out and RISC architectures will dominate the market
  3. (5 years from then) everyone will be running a free GNU OS

PC and server programmers may laugh, but two and three are certainly true for the majority of cell phones in existence. Tanenbaum would be right on all accounts if BlackBerry QNX was a success.

Also, many L1-hypervisors have a micro-kernel underneath. This is because a hyper-visor usually doesn't do much beside context switch.

Apparently three predicts the success of Linux. ;-)


An argument for microkernels is that all of the monolithic sub-systems need to synchronize multiple values at one time. In order to do this, they must use locks and will suffer from Amdahl's law when extended to parallel architectures. The counter is that microkernels result in lots of IPC messages.

A major development is the use of lock-free programming to avoid contention in a monolithic kernel. This avoids the locking in a monolithic kernel while also reducing IPC overhead. Recently all CPUs have been extending their ISA to include better primitives for lock-free algorithms. So Linux will probably remain a monolithic kernel for some time.

Solution 4 - Architecture

From Wikipedia:

> A monolithic kernel is a kernel architecture where the entire operating system is working in the kernel space and alone as supervisor mode. In difference with other architectures, the monolithic kernel defines alone a high-level virtual interface over computer hardware, with a set of primitives or system calls to implement all operating system services such as process management, concurrency, and memory management itself and one or more device drivers as modules.

Recent versions of Windows on the other hand use a Hybrid kernel.

> A hybrid kernel is a kernel architecture based on combining aspects of microkernel and monolithic kernel architectures used in computer operating systems. The category is controversial due to the similarity to monolithic kernel; the term has been dismissed by some as simple marketing. The traditional kernel categories are monolithic kernels and microkernels (with nanokernels and exokernels seen as more extreme versions of microkernels).

Solution 5 - Architecture

'Monolithic' in this context does not refer to there being a single large executable, and as you say, there Linux supports the dynamic loading of kernel modules at runtime. When talking about kernels, 'monolithic' means that the entire operating system runs in 'privileged' or 'supervisor' mode, as opposed to other types of operating systems that use a type of kernel such as a 'microkernel', where only a minimal set of functionality runs in privileged mode, and most of the operating system runs in user space.

Proponents of microkernels say that this is better because smaller code means less bugs, and bugs running in supervisor mode can cause much greater problems than in user space code (such as a greater chance of having security vulnerabilities or total system crashes in the form of a 'kernel panic'). Some microkernels are sufficiently minimal that they can be 'formally verified', which means you can mathematically prove that the kernel is 'correct' according to a specification. L4 is a good example of this.

Solution 6 - Architecture

Monolithic kernel is a single large processes running entirely in a single address space. It is a single static binary file. All kernel services exist and execute in kernel address space. The kernel can invoke functions directly. The examples of monolithic kernel based OSs are Linux, Unix.

I think this post will help you more to understand the concept.

http://learnlinuxconcepts.blogspot.in/2014/03/what-are-monolithic-and-micro-kernels.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBooleanView Question on Stackoverflow
Solution 1 - ArchitectureTim PostView Answer on Stackoverflow
Solution 2 - ArchitectureCesarGonView Answer on Stackoverflow
Solution 3 - Architectureartless noiseView Answer on Stackoverflow
Solution 4 - ArchitectureBobView Answer on Stackoverflow
Solution 5 - ArchitectureDavid ClaridgeView Answer on Stackoverflow
Solution 6 - ArchitectureJIN007View Answer on Stackoverflow