top of page
Keet Malin Sugathadasa

An Introduction to Kernels. The Heart of Computing Devices.


Have you ever heard the expression, "Computers are just dumb machines?" Computers can really run, only when it is given instructions. So what it really does is, run instructions one at a time and execute according to what the user needs. But for this, the computer needs software. For every piece of the computer like (even to boot up the computer), you need a software. The kernel is the first program that is loaded on Start-up and it also handles the rest of the startup process. This also acts as the mediator between the software and hardware.

All you need to know about Kernels is given in this blog, and it will provide you the basic concepts of Kernels and a brief history on how Kernels developed over time. Following are the sections being addressed in this blog.

  1. What is a Kernel

  2. How the Kernel works

  3. Three types of kernels

  4. The Flame War between Andrew Tannenbaum and Linus Torvalds

1) What is a Kernel?

A kernel is a computer program that manages the I/O (input - output) requests from software and translate the requests into CPU instructions or other electronic instructions (communications with integrated circuits on the motherboard) for a computer. It acts as an user interface between the user application and the hardware. With this in mind, you can see that its main task is to manage communication between the software and the hardware like a bridge connecting these two segments.

A kernel is considered as a core component of an operating system that directly controls the hardware. Operating system kernels are specific to the hardware in which they are running, which makes most operating systems distributed with different kernel options that is configured when the system is installed. The two major Operating System Kernels are Windows and Unix-like. The Windows kernel is a proprietary software written and distributed by Microsoft. The Unix-like kernel is a series of kernels that is based on Bell-Labs UNIX operating system, such as Linux, BSD, Mac OS X.

Everything that is based on computing, has a kernel. Whether it is your android device, computer, iphone or any other device, it has a kernel. The image given below, shows the android kernel version used in Sony Xperia Z (C6603).

Let's try and understand this with a simple example.

Just imagine you have a mobile device and you wish to play some songs. So you launch your default music player, and then it will call the Kernel and give the user's request. The kernel will contact the hardware and get the job done accordingly. This is illustrated in the figure given below.

2) How the Kernel Works

Before we try to understand how the Kernel works, let's first understand the main two memory areas, namely Kernal Space and User Space. If we look at modern day computers, the operating system divides the virtual memory into two segments. Primarily, this serves memory protection and hardware protection from malicious or errant software behaviour.

Kernel space is strictly reserved for privileged services like the operating system kernel, kernel extensions, and most device drivers. Usually the critical code of the kernel is usually loaded into this protected area of memory, so that it is prevented from being overwritten by applications or other parts of the operating system. In contrast, the User space is the memory area where application software and some drivers execute. This separation prevents user data and kernel data from interfering with each other and causing instability and slowness.

What is a System Call?

When a software or a process makes a request to the CPU, this is called a system call. Each kernel will handle each request differently. Each of the kernel designs differ in the way they handle these system calls and hardware resources. The interface provided by a kernel is very low level.

3) Three Types of Kernels

  1. Monolothic Kernel

  2. Microkernel

  3. Hybrid Kernel

The image given below, depicts the Monolithic kernel and the Microkernel with the user space and kernel space separation as shown by the red colour lines.

1) Monolithic Kernel

All the device services such as the device drivers, file systems, memory handling, all occur inside one program that occupies one memory space. Eg: Linux.

With this type of kernel, the entire Operating System is working in Kernel space and is alone in supervisor mode. Processing, Memory Management, I/O Handling, File Systems, Virtual Memory, device drivers etc, are in a single module in Kernel Space. The major problem is that, having everything in a single module made it necessary to recompile the entire kernel from scratch, if a modification is to be done to one of the modules within the kernel. Also if one of the services inside the kernel crashes, there is a possibility for the entire kernel also to crash.

On advantage of the Monolithic kernel is that it is faster, because it runs all the operating system instructions in the same address space. In contrast, the Microkernel runs most processes in user space for modularity.

Advantages of Monolithic Kernels

  • It is faster because, less software is involved.

  • As it is a single piece of code, it should be small in both source and compiled code

  • Less code generally means fewer bugs which can translate to fewer security problems

  • Since all the services are in the same place, communication and execution are faster.

Disadvantages of Monolithic Kernel

  • Coding in kernel is very challenging. (lack of common libraries, hard debugging etc)

  • Bugs in one side of the kernel have strong side effects.

  • Kernels often become very large and difficult to maintain

  • Code integration and removal is very hard.

  • Since the modules run in the same address space, a bug can bring down the entire system.

  • Monolithic kernels are not portable; therefore, they must be rewritten for each new architecture that the operating system is to be used on

2) Microkernel (Samuel Kernel)

This was made as a solution to the increasing size of the kernels, which allows device drivers, file systems, and others to run in user space. This reduces the kernel size. The Microkernel itself is a very small piece of program, and other services (also known as servers) like device drivers, file systems, memory handling and all are running as user level programs.

In the microkernel approach, the kernel itself only provides basic functionality that allows the execution of servers like device drivers, file systems etc.

There even smaller kinds of kernels like exokernel, nanokernel and MINIX.

If a modification is needed to one of the services, then you can simply modify it without having to completely restructure the kernel code. Also if one of them fails, the kernel will still be able to run without any issues. So this is where Microkernels are advantageous over Monolithic kernels. Microkernels are easier to maintain than monolithic kernels, but the large number of system calls and context switches might slow down the system because they typically generate more overhead than plain function calls.

Advantages of Microkernels

  • Easy to maintain

  • Patches can be tested in separate instance, and moved into the production instance

  • Rapid development time and new software can be tested without rebooting the kernel.

  • More robust. If one system goes haywire, it can be easily replaced by a copy

Disadvantages of Microkernels

  • Larger running memory footprint

  • There is a potential for performance lost due to more software interfacing

  • Handling bugs can be tough due to long trip they take, versus the one off copy in monolithic kernels.

  • Process management in general can be very complicated.

3) Hybrid Kernels (Modular Kernels)

This is a combination of the above two, where the key idea is that Operating System services are in Kernel Space, and and there is no message passing, no performance overhead and no reliability benefits, of having services in user space. This is used by Microsoft's NT kernels, all the way up to the latest Windows version.

Advantages of Hybrid Kernels

  • Faster development time for drivers that can operate from within modules.

  • On demand capability versus spending time recompiling a whole kernel for things like new drivers or subsystems.

  • Faster integration of third party technology

Disadvantages of Hybrid Kernels

  • With more interfaces to pass through, the possibility of increased bugs exists

  • Maintaining modules can be confusing for some administrators when dealing with problems like symbol differences.

4) The Flame War between Andrew Tannenbaum and Linus Torvalds

The merits of Monolithic kernels vs Microkernels. Let's breifly look at where Linux is today, and then see a summary of the argument that these two had regarding the Linux kernel and kernel architecture in general.

Linus who was later famously known as the father of Linux, at his time was writing a Monolithic Kernel, and this is what we have today. The Linux Kernel, which is a Monolithic kernel, can be quite big and complicated. In fact, it says that there are over 15 million lines of code in the Linux Kernel. It is so complex that it provides support for IBM's mainframes, support for Personal Computers, support for SPARC processors, and support for ARM processors. Also it includes a whole set of device drivers, where 70% of the 15 million lines of codes are just device drivers.

The power of the Linux kernel comes with the ability to provide the flexibility for the user to pick which features he/she wants. You can also pick what to execute and what not to execute. You can even tweak certain parts of the system to cater to your need with a balance between performance and power.

Due to this reason, the concept of custom kernels was introduced, where you can download the Linux Kernel code and customize it the way you want. In the Android community, there are many user groups that create ROMs or Custom Kernels to suit different purposes in Smartphones.

But according to Andrew Tannenbaum, in his talk about the "Lesson's learned from 30 mins of MINIX", he mentions that:

"one of the adopters of MINIX is Linus Torvalds, who studies very carefully and developed linux, using MINIX's base system. if he hadn't had that, he would have never developed Linux, and there would even be Android, because Android is based upon Linux. If it wasn't for Android, the market for Samsung and Apple would have been way different by now."

Summary of the Famous Tanenbaum–Torvalds debate

Andrew Tanenbaum began the debate in early 1992 on the Usenet Discussion group, with the argument that microkernels are way superior than monolithic kernels. During this period, Linux was outdated. Initially the debate started off as a moderate discussion, but with every post and message, it progressively turned into a flame war. With time, they were joined by three other Linux kernel developers, Peter MacDonald, David S. Miller and Theodore Ts'o.

First Argument

The first argument was made by Tanenbaum, as a criticism on the Linux Kernel, noting how the monolithic design was detrimental to its abilities, in a post titled "LINUX is obsolete". He also mentioned that, "writing a monolithic kernel in 1991, is a giant step back into the 1970's."

Second Argument

As a reply, Torvalds pointed out the design flaws in MINIX, and claimed that since he was developing the Linux kernel in his spare time and giving it away for free (Tanenbaum's MINIX was not free at that time), Tanenbaum should not object to his efforts.

Third Argument

As a counter argument, Tanenbaum replied that, him being a professor, MINIX was developed for the use of the students who can afford a rather limited hardware for an average price. He noted that, even though Linux was free, it would not be a viable choice for his students. He stated that the Linux kernel would eventually fall out of style as hardware progressed, due to it being so closely tied to the 386 architecture.

A third party, Kevin Brown brought in an argument against Tanenbaum, mentioning that "an explicit design goal of Linux was to take advantage of the special features of the 386 architecture. So what exactly is your point? Different design goals get you different designs." He also stated that designing a system specifically for cheap hardware would cause it to have portability problems in the future.

Final Statement

Torvalds attempted to end the discussion at that point, stating that he felt he should not have overreacted to Tanenbaum's initial statements, and that he was composing a personal e-mail to him to apologize.[6] However, he would continue the debate at a later time.

References

1,272 views4 comments

Recent Posts

See All
bottom of page