What is Kernel?

Photo of author

By Vijay Singh Khatri

Kernel: The Heart of an Operating System

Linus Torvalds invented the first-ever kernel for his own operating system in 1991, and it was quickly accepted as the kernel for the GNU operating system. GNU was built as a free alternative to UNIX, and it has been used to model a vast variety of operating system distributions since then. You may know GNU by its more common name – Linux.

Coming back to the kernel, in a very literal sense, the meaning of the word “kernel” is a soft, typically edible component of a nut or seed. Essentially, it refers to a very significant or core aspect of something. For instance, you must have heard the phrase “this is the kernel of the argument” informal conversations. What it thus implies is the key point. Keeping the same analogy in mind, in the computing world, a kernel is computing software that runs at the heart of the operating system (OS) and has control over its entire operation.

In this post, let’s see the essence of kernels, their working and their types.

What is Kernel? [Definition]

An operating system’s kernel, as mentioned above, is a software component that serves as its heart and soul. The OS has full control over the computer system, and the kernel is what makes that possible. It is the most crucial and the very first program loaded into the computer’s memory after the bootloader since it is responsible for the rest of the system’s working.

The kernel remains in the system memory till the last moments of shut-down. It serves as a link between the user and the system’s hardware components. Whenever a process makes a request to the kernel, it’s called a “System Call.” The kernel responds to these system calls and facilitates the processes.

In addition to responding to system calls and facilitating processes, the kernel also performs various other functions vital to the operation of the system. Here is an overview of some of those functions.

A brief overview of the Functions of Kernel

A kernel performs various functions such as process management, memory management, device management, interrupt handling and a lot more. Let’s go over each one.

  • Process management: When a user wishes to perform any task on the computer, a process is created in the system to handle the user’s instructions. At any point, there are multiple processes running inside the system. The management of these processes in an efficient manner is the kernel’s responsibility.
  • Memory management: Each process requires a certain amount of memory to execute smoothly. But since the total memory of the system is limited, it is allocated and de-allocated appropriately to facilitate the different tasks. The kernel is in charge of this allocation and deallocation task.
  • Interrupt handling: Interrupts are intentional breaks that the kernel puts in the middle of a task that’s executing. Sometimes, your system might be performing a task when you request the execution of another higher priority task (for example, if you’ve sent a document for printing and side-by-side you launch the web browser). In such a case, the kernel will need to create an interrupt to pause the printing activity for a nanosecond to allocate resources towards the browser launch, and then it will resume the printing. This activity is known as interrupt handling, and usually, it happens so fast that you barely even notice it.
  • Device management: Peripheral devices like external hard drives, printers, scanners, etc. are linked to a computer to augment its functionality. To make each such device work, an appropriate set of drivers and processes needs to be involved. The kernel’s duties include activating and deactivating drivers and processes, ensuring external devices function as expected, and cleaning up after the devices have been detached from the system.
  • Input-Output communication: Further to the device management function explained above, the kernel also manages the communication between the computer and the device connected to it. Communication here refers to the exchange of data.

What is “kernel space” and how is it different from “user space”?

This section is very important to understand before progressing any further. Kernel space and user space are two frequently used words on kernel forums. Let’s find out what they actually mean.

1. User Space

The code that is executed outside the kernel of an operating system is known as userspace. UNIX-like operating systems, including Linux, come pre-installed with software programs, programming languages, and graphical tools. This is often referred to as “userland.”

2. Kernel Space

A kernel has its own secured space in the computer’s memory called kernel space, which is a separate storage space that is inaccessible to other software programs. When you boot the system, the kernel’s code is loaded into this safe and secured kernel space.

3. Types of kernels

There are five types of kernels supporting different operating systems. Each type has its own advantages and disadvantages. Let’s have a brief look at all of them.

4. Monolithic Kernel

Kernels with monolithic storage are those in which both user and kernel operations are performed. As a result, the kernel takes up more space and the OS takes up more space as well. The processes run faster since there is no distinction between user space and kernel space. The best example of an OS having a monolithic kernel is Linux.

Biggest Advantage:

This product has a high level of performance. Because there is no separate memory for the user and kernel, operations run faster.

Biggest Disadvantage:

Several different system components are interdependent on each other. When one component fails, the entire system shuts down.

5. Microkernel

A microkernel is the complete opposite of the monolithic kernel, meaning that the user and kernel operations are processed in separate spaces in this case. Because the user space and kernel space are separated in terms of memory, the size of the kernel is smaller, and this in turn reduces the size of the whole OS. The best example of a microkernel-based OS is macOS.

Biggest Advantage:

It’s more stable. New services can be added very easily without much impact.

Biggest Disadvantage:

The number of system calls and context shifts is very high.

7. Hybrid Kernel

As its name suggests, this is a hybrid of the monolithic and microkernel. It combines the monolithic kernel’s performance and design with the flexibility and reliability of a microkernel. The best example of an OS having a hybrid kernel is Windows.

Biggest Advantage:

It combines the best aspects of both monolithic and microkernels.

8. Exo Kernel

The kernel implements the end-to-end principle. As a result, it uses the fewest hardware abstractions, which are a set of software routines connecting different applications to the hardware. The Cheetah web browser is a good example of an exokernel-powered application.

Biggest Advantage:

The least amount of hardware abstraction results in the fastest performance.

Biggest Disadvantage:

Application developers have to spend a lot of time and resources to find their way around this kernel. Modifications too can be really hard.

9. Nano Kernel

This is a kernel that provides hardware abstraction but doesn’t provide system services. As the name implies, the entire kernel code in this case is very compact. A kernel that offers a nanosecond clock resolution is referred to as a nano kernel. The best example of an OS running on a nano kernel is KeyKOS.

Biggest Advantage:

It has the advantage of providing hardware abstractions without the need for system services.

Kernel Panics – what are they?

As previously stated, kernels have full control over the computing device; therefore, if it malfunctions, the entire system will be brought to a halt. “Kernel Panic” is a term used in macOS and Linux to describe an unwanted situation. A system must be restarted to recover from a kernel panic. Such a situation is typically caused by problems with device communication. If you’re experiencing frequent kernel panics, try unplugging any external devices that aren’t absolutely necessary and see if the problem goes away.

Windows kernel VS Linux kernel

The fundamental difference between Windows kernel and Linux kernel is that Windows kernel is commercial software that comes with the Windows OS, whereas Linux kernel is open source software that comes with the Linux OS. Let’s dig a little deeper.

Windows Kernel

Windows kernel is based on the hybrid kernel type. It has full access to the system’s hardware and operations and it runs the code in secure memory space. There are various layers that make up the Windows kernel:

  1. Executive layer – Takes care of the core functions like storage management, input and output management, thread management, connectivity, safety, and service management.
  2. Main kernel – This is present between the executive layer and the HAL and is in charge of multiprocessor synchronization, driver initialization, and communication with the process management.
  3. Driver layer – As the name suggests, this layer is responsible for driver-related functions.
  4. Hardware Abstraction Layer (HAL) – The HAL is a software layer that sits between the operating system and the computer hardware. It’s in charge of input and output interfaces, interrupt controllers, and a variety of processors.

Linux Kernel

Linux kernels follow a monolithic kernel architecture comprising both kernel space and userspace. The combined space consists of components such as hardware, kernel, system call interface (called Shell), and user programs.

Conclusion

The kernel is the heart and core of an operating system. It serves as a link between the system’s software and hardware. Memory, process, and device management are some of the critical tasks handled by the kernel. However, in addition to the above-mentioned functions, it is crucial to maintain the security, integrity, and protection of the system.

Leave a Comment