views:

1545

answers:

5

I read that Linux is a monolithic kernel. Does monolithic kernel means compiling the 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, kernel doesn't have to load all modules initially and maintain index of the functions in the module and load them when necessary.

A: 

Linux can be a monolithic and a modular kernel. It can be considered a monolithic kernel because all of the modules can be compiled into one binary executable. It is considered a modular kernel because the kernel can be customizible into smaller components that can be added/removed at runtime.

One would want to make the kernel to be monolithic to get minor performance increases. Also, it would shrink the overall size of the kernel as well. Typically monolithic kernels are best found in embdedded devices.

monksy
sorry, that's simply not correct :)
David Claridge
A monolithic kernel is _sometimes_ modular, depending on how it was compiled. However, even a modular kernel is monolithic, as every module is inserted to and run within kernel space.
Tim Post
Folks, -1 or (preferably) 0 is enough for this question. Down voting beyond that only costs you rep and discourages its author from participating in the future. Lighten up?
Tim Post
@I'm done with SO: putting it at 0 rep then, hopefully no one will change it
Edison Gustavo Muenz
+2  A: 

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.

CesarGon
Can you explain how a monolithic kernel can be modular, which I assume you mean that you can take out some of the core features (drivers for example) and have them be separate modules.
James Black
Windows is most definitely a monolithic kernel.
Adam Rosenfield
@James: A monolithic kernel **OS** can be modular, such as Linux. Linux is composed of multiple executable files that run as daemons and processes; you may choose to run some of them or not run others, selecting different configurations. That is modularity. From Wikipedia, "Most modern monolithic operating systems such as OpenVMS, Linux, BSD, and UNIX variants such as FreeBSD, NetBSD, SunOS, AIX and MULTICS can dynamically load (and unload) executable modules at runtime".
CesarGon
@Adam: I disagree. The old-style 16-bit Windows *was* monolithic kernel, as was Windows 95 and the like. But NT-based editions of Windows, including all Server versions plus Vista and 7, are clearly microkernel or perhaps hybrid, depending on what definition of "microkernel" you use.
CesarGon
Just because the printer drivers don't run in ring0 doesn't make it a microkernel :)
caf
@caf a driver running in ring0 also doesn't make it part of a monolithic kernel... The thing is if the driver has it's own process (running with privileges or not) or it is a function inside the unique process that a monolithic kernel is.
fortran
@caf: I suggest you take a look at http://en.wikipedia.org/wiki/Windows_NT_kernel and http://en.wikipedia.org/wiki/Comparison_of_operating_system_kernels. You'll see that Windows NT and their successors, including Vista, 7 and the Servers, are described as "hybrid kernel". Two large subsystems of the OS run fully in user mode, not just a printer driver. :-)
CesarGon
My comment was somewhat tongue-in-cheek - the "hybrid" designation seems so information-free as to be useless.
caf
+1  A: 

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,[1] 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 Hybric kerkel.

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).

Bob
If I ever do anything in kernel space, I have to remember to use "hybric kerkel" somewhere. SCNR ;-)
jae
A: 

Hi Bala,

'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 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.

David Claridge
Check your sources. The wikipage is uncited. http://www2.cs.uh.edu/~rzheng/course/COSC6397sp2008/Linux_Essentials.ppt
monksy
+32  A: 

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 micro kernel.

A micro kernel 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 its a module in Linux, its a service in a micro kernel, 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 (i.e. Linux), what matters is that the module is inserted to and run from the same space that handles core functionality.

The advantage to a micro kernel is that any failed service can be easily re-started, for instance .. no kernel halt if the root file system throws an abort.

The disadvantage to a micro kernel 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. Micro kernels 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 / tinkering with kernel development goes into a micro kernel, specifically HelenOS.

Edit

If you got this far though my very long winded answer, you will probably have some fun reading the 'Great Torvalds-Tanenbaum debate on kernel design'. Its even funnier to read in 2009, almost 18 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 micro kernel. It is not my intent to disparage the recent work of others.

Tim Post
Thanks for the detailed answer.
Algorist
Interestingly Linus Torvalds was greatly influenced by Andew Tanenbaum's MINIX when he created Linux. However, MINIX is based on a micro kernel design while Linux uses a monolithic kernel.
Martin Liversage
@Martin Liversage: More frustrated than influenced :) I edited my answer to reflect that.
Tim Post
Hehe, yes, LT developed into one of the net's most consistent flamers...
DigitalRoss
@DigitalRoss: You should see my inbox after answering this, Linus is tame compared to Minix and Mach enthusiasts.
Tim Post