Understanding Kernel Architecture and its Relationship with the OS
As we know, the operating system is a remarkable piece of technology. This program gives us many tools that allow us to perform our professional duties, as well as provide many entertainment options. Have you ever wondered how the computer makes it all possible?
Consider the computer as a complex machine similar to the human body. Just like the human body is controlled by our brain, the computer is controlled by a program called the “Kernel”. The purpose of this post is to explain what the kernel is, what functions it performs, and everything else relating to it.
What is a Kernel? [Definition]
An operating system (OS) is a collection of different software programs/snippets that are designed to perform different functions. The Kernel is a computer program at the core of these snippets. It always resides in your system memory when your computer is running, handling all functions and allowing you to do various tasks. It has complete control over every component of the OS, and it facilitates smooth interaction between your hardware and software.
The Kernel is the first program loaded on computer start-up, even before the boot loader. It has quite a sophisticated architecture, comprising different layers. Let’s try looking at these layers and other important parts of the Kernel.
Different Components of Kernel
Since Kernel architecture is specific to the OS, its components may vary with each OS and with each version. Thus, there’s a different unique kernel that’s used for Windows, Linux, and Mac operating systems.
Even though it may seem surprising, Apple too uses open source technologies for building the Kernel and other parts of its macOS and iOS. This is the reason why Apple can deliver incremental updates to its OS ever so often. Another extremely popular Kernel is the Linux Kernel. It has several components like memory management, process management, network management, file system drivers, hardware device drivers, and several other software bits and pieces. Of all of them, memory management and process management are the most important components.
Memory Management handles the task of allocating and releasing memory across processes. It is responsible for maintaining the buffer cache while monitoring the smooth completion of the OS processes. Process management creates processes and enforces multitasking by switching the active process on the processor. The Linux kernel works at different levels and the lowest one is the hardware driver for each device that the OS supports.
There are different types of kernel architecture, just as there are different types of operating systems.
Different Types of Kernel Architecture
There are three main types of Kernel architecture – Monolithic, Microkernel, and Hybrid. Further, each one works in two modes – User Mode and Kernel Mode. The user-mode refers to the one where user-installed applications have limited access to memory and hardware resources. The Kernel mode is the privileged mode where all applications have unrestricted access.
1. Monolithic Architecture
Monolithic Kernel architecture uses single address space. Operating systems assign virtual addresses to all processes/programs for execution. These virtual memory addresses are referred to as address space. In Monolithic Kernel architecture, all processes and programs of the OS are executed within a single kernel as one large process. In other words, the OS runs only one process in single address space in memory. This architecture is more flexible than the other two and allows developers to enhance existing features or add more features easily. It also enables higher performance.
All essential kernel processes like memory management, process management, file system management, I/O management, device management, and concurrency are performed in kernel mode in this architecture. The other remaining processes are taken care of by the user mode.
Some operating systems that use Monolithic kernel architecture are:
- Windows 1, Windows 2, Windows 3, Windows 95, Windows 98, Windows ME
- All Linux distributions, including Ubuntu, CentOS, Red Hat’s Fedora, Red Hat Enterprise, Open SUSE, and several other popular ones.
- Android uses a modified Linux Monolithic Kernel architecture
2. Microkernel Architecture
Unlike monolithic architecture where every process is managed within the kernel, Microkernel architecture uses the core Kernel for basic inter-process communication mechanisms and hardware interaction. All remaining processes exist outside the Kernel. While this architecture allows for new features to be added to the OS, it comes with reduced performance.
Unlike monolithic architectures, this architecture manages application IPC, processes, memory management, I/O management, device drivers, and file servers from user mode, whereas low-level address space management, low-level process management, and inter-process communication are managed from kernel mode.
Some of the operating systems that use Microkernel architecture are
- QNX, seL4, PikeOS, Fiasco.OC, Codezero, OKL4, and Mach (not to be confused with Macintosh)
3. Hybrid Kernel Architecture
The hybrid kernel architecture offers the best of both worlds by providing the features of Monolithic and Microkernel architecture in a single kernel. It gives OS developers the flexibility to upgrade or modify kernel services and also maintain optimal performance.
In this architecture, core processes like process management, memory management, I/O management, and file servers are handled by the user mode. The other operations like device driver management, low-level address space management, low-level process management, and inter-process communication are taken care of by the kernel mode.
Modern and most popular operating systems like the latest versions of Windows and MacOS use hybrid kernel architecture.
- Windows NT, Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10
- Apple’s macOS for desktop machines
- Apple’s iOS for mobiles uses hybrid (XNU)
How Kernel Interacts with the OS
The OS is the underlying programming code that is designed to directly collaborate with the hardware. It gives the user an environment to run programs and determines how they can be executed efficiently. The Kernel, which is a part of the OS, runs the instructions and offers a secure approach to hardware. Since there are several assets and programs requesting resources, the Kernel decides which program will run. This mechanism is called “organizing.”
Every system’s hardware has a different design and depending on its complexity, it can be difficult to pass instructions directly. Hence, the kernel uses a hardware abstraction layer which is a set of instructions to a specific type of device. This allows developers to create programs without worrying about a specific device. The Kernel depends on software drivers that convert generic commands into instruction codes that specific devices can interpret.
And now let’s move to an interesting part. Let’s find out what kernel components Windows, macOS and UNIX have.
Kernel Components of Different Operating Systems
Apple OS and its Kernel
You would be surprised to know that Apple has made the macOS and iOS kernel for ARM processors open-source, and the most recent version can be found on GitHub. Apple OS is based on the NeXTSTEP project, which was created from open-source BSD. That is the reason why Apple’s OS relies heavily on open source technologies.
Mac OS has the following components – Kernel and device drivers, cocoa application, media, core services, and core OS. The Kernel and device drivers handle most hardware including disk drives, RAM, networking, file system, BSD sockets, and POSIX thread support.
The Core OS includes the following:
- Image processing
- Graphics
- Handling mounting and unmounting of storage volumes
- Increasing performance of processes
- Sharing of system resources to other computers/devices across the network
- Parallel processing
- Accessing shared resources over the network.
- Information about Users / Groups / Printers and Network computers
Windows NT Kernel
As mentioned earlier, the latest version of Windows uses hybrid kernel architecture which gives it the ability to handle Uni Processor and Symmetric Multi-Processors. The Windows NT architecture’s Kernel mode has a simple kernel known as Hardware Abstraction Layer (HAL), and a collection of services known as Executive Services. The User mode is divided into two systems – the environment subsystem and the integral subsystem.
- Environmental Subsystem – In the newer version of Windows, the environmental subsystem has Win32 subsystem and Windows subsystem for Linux. The inclusion of Windows subsystem for Linux allows the developers to run GNU/Linux environments and command-line tools, utilities, and applications without making any modifications. It removes the need to use virtual machines or dual boot-setup while writing programs.
- Integral Subsystem – It has three main components – security subsystem, server service, and workstation service. The security subsystem takes care of login authentication and logout. It also grants and denies user requests for resources. The server service allows the external systems to access printers, files, and resources in the machine. The workstation services allow the operating system to access printers and files across the network.
Linux OS Kernel Architecture
The Linux kernel is composed of five subsystems: memory manager, the process scheduler, the virtual file system, the inter-process communication interface, and the network interface. The Linux subsystems interact with each other through function calls and data structures.
Wrapping Up
The operating system kernel has the highest level of privileges in modern computers. It mediates access to protected hardware and controls how the resources are used by the system. The kernel is a piece of software that determines if it is appropriate for a process to perform a certain action and whether it should be allowed to carry out these actions. While a normal computer user may not feel the need to know the kernel architecture and its working details, you need to understand it in detail if you want to become an embedded programmer. Also, it is never a bad idea to know how your computer works, and knowing the kernel and its architecture might help you understand BSODs better and resolve them with confidence.