What is a Kernel

If you work with computers, or hang around computers long enough, you might come across this term “kernel”. In this article we will see what the kernel is, why is it important and where did it come from.

Thing that most people forget is all that computers are doing is following instructions, repeating one instruction after another. Therefore, computers need software to do anything, even just to boot up. When we power on our computer or mobile phone, we end up on a user interface (desktop screen or launcher screen) where we can see apps on our device. But, there there’s lots going on underneath. For example, even if we don’t open any application ourselves, there is always a bunch of services running in the background. Below all that there is a kernel, and it is the core of the whole system.

Different Kernels

Every multi-tasking computer operating system uses a kernel, including Windows, macOS, iOS, Android and all other Linux distributions. Now, Windows kernel is commonly referred to as NT kernel, macOS and iOS call it the Darwin kernel, and Android uses the Linux kernel. These aren’t the only kernels that are available. There are a whole plethora of kernels out there, with some being proprietary while other are open sources.

Kernel Tasks

The kernel manages CPU and memory resources, system processes and manages device drivers. When looking at the system as a whole, kernel is the lowest layer above the available hardware. For example, when you start an app it is in fact the kernel that starts the process for that app and enables the app to be loaded. If that app, needs some memory, CPU or networking resources it will be the kernel that will allocate it to it. Eventually, when the app closes, all resources that it used will be tidied up by the kernel.

Kernel Designs

Kernels can be quite complicated since they’re doing a lot of essential work, and there are actually different ways in which kernels can be designed. The two main designs known today are what’s called a monolithic kernel and a micro kernel.

Linux is a monolithic kernel and that means that all of the kernel work is done inside one program that occupies one memory space. In the alternative micro kernel design the kernel itself is in a very very small piece of memory space and then other things like device drivers and networking and file system drivers are running as user level programs. The kernel communicates to them by giving them instructions. The idea being micro kernel design is that if one of those separate programs crashes, the kernel itself won’t automatically crash. Monolithic kernel can be quite big and complicated, and there are 15 million lines of code in the Linux kernel. Not all of that code is used at once, because there’s a whole range of different device drivers in there. In fact, the 70% of that 15 million lines of code is just device drivers.

Customization

When you build the Linux kernel, you say which bits you want and which you don’t want. Also, you do more than just say what you want – you can also tweak the way the operating system works. That makes sense because if you’re running Linux on a mainframe you might want it to behave differently than if you’re running it on a desktop, mobile, or a wearable device.

This is where we get into the idea of custom kernels because you can download the Linux software (it is open source under the GPL), it’s very possible to build your own kernel. There is a whole community of people that build custom kernels just for different devices (smartphones being the most popular ones). Kernel are highly configurable, so custom kernels may have extra features built into it compared to the standard stock kernel. Also, by tweaking them they can operate with different CPU, governors different IO schedulers, different priorities for different things and you might get a better kernel than the stock kernel. Companies like Samsung, Google, Apple, LG, Sony and others are spending millions of dollars developing smartphones and if they could get better battery life or better performance just by tweaking a thing in software, they certainly will. Of course, you can get better performance but you get less battery life, you can get better battery life but it means you have to run your processor at a slower speed, so companies are trying to find that medium where you get good battery life and good performance.

Summary

The kernel is the lowest level of any operating system that comes just above hardware. It is responsible for the CPU resources, the memory resources, for the drivers and for the networking. The kernel can tweak different parameters about how the scheduling occurs, how the IO scheduling occurs, and how the CPU is controlled.