Kernel in OS

Learn via video courses
Topics Covered

The kernel is the core of an operating system, managing hardware and coordinating memory and CPU operations. It serves as an intermediary, facilitating inter-process communication and system calls for hardware-level data processing.

When the OS starts, the kernel loads into memory and remains active until shutdown. It manages disk resources, schedules tasks, and allocates memory. The kernel keeps a process table to monitor active processes, including per-process region tables. It loads executable files during the 'exec' system call, allocates processes to the CPU, and decides which processes stay in main memory.

Essentially, the kernel bridges user applications and hardware, efficiently managing communication between software and hardware components like the CPU and memory. Common examples of kernels include Linux, Zircon, Windows NT kernel, etc. Kernels are categorized as being of four types- monolithic, microkernel, hybrid, and exokernel.

Objectives of Kernel

  • Scheduling Processes: The kernel allocates time to each process. After one process completes its execution, the kernel starts the next one and assesses its state (running, waiting, or ended).
  • Resource Allocation: The kernel manages memory, peripheral devices, and CPU processes. It serves as a bridge between resources and processes, distributing memory and hardware component access.
  • Device Management: The kernel oversees system devices, including I/O and storage devices. It facilitates data exchange between these devices and applications, handling information flow.
  • Interrupt Handling and System Calls: The kernel manages task priorities, allowing high-priority tasks to take precedence. It also handles system calls, which are essentially software interrupts.
  • Memory Management: The kernel allocates and deallocates memory for processes. It stores active processes in memory and releases memory when processes end.
  • Process Management: The kernel is responsible for creating, executing, and terminating processes within the system. It takes charge of process management during task execution.

Types of Kernels

Kernels are of following 5 types:

1. Monolithic Kernel:

A Monolithic Kernel implements core computer system features like file and memory management, associating all resources with the kernel space. Examples of Monolithic Kernel-based operating systems include Dos, Solaris, AIX, Linux, OpenVMS, etc.

It suits tasks like CPU scheduling and system calls due to limited resource management. Financial projects favor Monolithic Kernel-based OS for reliability, security, and speedy access.

All hardware-controlling software components for processing are embedded within the kernel, facilitating direct communication. Monolithic kernels can load modules with minimal overhead compared to embedding modules into the OS image.

Advantages

  • A monolithic kernel is fast because services like memory management, file management, etc are implemented in the same address space.
  • A process runs entirely in a single address space in monolithic kernels.
  • A monolithic kernel is a single static file.
  • Few bugs and security problems are also less.
  • System calls are used to do operations in monolithic kernels.
  • Execution of the process is fast due to separate memory space for user and kernels.

Disadvantages

  • If any service fails, then the entire system fails too.
  • If any new features are added then the issue is to modify the complete system.
  • Coding and debugging in the kernel space is difficult.
  • Bugs in one part of kernel space produce strong effects in other parts also.
  • These Kernels are huge and difficult to maintain and not always portable.

2. Microkernel Kernels

A microkernel is an OS architecture used for file and memory management, process scheduling, and more. It's similar to a monolithic kernel but allocates space for tasks like file sharing and scheduling. Each service has its address, reducing the kernel and overall OS size.

The core idea of a microkernel is enhancing reliability by breaking the OS into smaller modules. It offers communication between client programs and user-space services. New services are added to user space without kernel modification, ensuring high security, as service failures don't affect the rest of the OS.

Advantages

  • Microkernels are secure as only those parts which might influence the system's functionality are added.
  • The various modules of a microkernel can be swapped, reloaded, and modified without affecting the kernel.
  • A microkernel architecture is compact and isolated, so it performs better.
  • Due to the modular structure of microkernels, they have fewer system crashes and are simply handled.
  • New functionality can be added to a microkernel without having to recompile it later.

Disadvantages

  • When the drivers are implemented as procedures, a context switch or a function call is needed.
  • In a microkernel-based OS, providing services is costlier in comparison to a monolithic system.
  • The performance of a microkernel system might stay uniform and cause issues.

3. Hybrid Kernels

Hybrid kernels blend monolithic and microkernel features, extending the microkernel idea with added code in kernel space and some monolithic kernel attributes for enhanced performance. They can't load runtime modules. XNU, short for "X Is Not Unix," influenced MacOS, IOS, WatchOS, and tvOS development. Unlike pure microkernels where everything resides in user-level servers and drivers, hybrid kernel designers choose which components to keep inside the kernel and which to place outside. This optimizes performance, simplifies the system, and reduces vendor lock-in. Hybrid kernel development starts as monolithic kernels and progressively shifts components to user-land.

Advantages

  • A hybrid kernel is easy to manage due to its layered approach.
  • Number of layers is not very high generally.
  • Kernel is small in size and isolated.
  • Provides better security and protection.

Disadvantages

  • Since a hybrid kernel strikes a balance between the gains in monolithic kernel and microkernel, there are certain benefits of both that are lost out or compromised.

4. Nano Kernel

It's a minuscule kernel, primarily housing privileged hardware code that operates with nanosecond clock resolution.

For example, KeyKOS, an object-oriented, capability-based OS established in 1983, adopts a nanokernel design. This architecture prioritizes reliability, security, and continuous software availability. KeyKOS was developed to support multiple concurrent operating systems on a single system. Remarkably, the KeyKOS nanokernel operates with a mere 100KB of memory and comprises approximately 20,000 lines of C code.

Advantages

  • The source code is very small and binaries likewise.
  • Very efficient in terms of performance.

Disadvantages

  • Does not include a lot of features directly incorporated.
  • It is less in use because of it's being similar to microkernels.

5. Exokernels

An exokernel OS provides app-level hardware resource management. It isolates protection from management, allowing customization. In typical OS architecture, high-level abstractions shield apps from hardware complexity, impacting performance and supported app types. Exokernels aim to minimize these abstractions, empowering developers to manage hardware directly, setting their own levels of abstraction.

Advantages

  • Better Support for Application Control.
  • Separates Security from Management.
  • Abstractions are moved securely to an untrusted "Library Operating System".
  • Provides a low-level interface.
  • Library operating systems offer Portability and Compatibility.

Disadvantages

  • When it comes to application/OS development, each developer will develop them the way they see fit. Due to this reason, the level of consistency will be a bit reduced.
  • Design of the interface in an exokernel is complicated.

What is Kernel Panic?

A kernel panic is a computer malfunction that the system's operating system (OS) cannot swiftly or readily resolve. It arises when a severe, low-level error occurs, and the OS's core component, the kernel, is incapable of resolving it.

The purpose of a kernel panic is to halt the system to prevent potential harm to the system's software, hardware, or memory. This interruption safeguards data and permits technicians to employ a debugger for diagnosing the issue.

A kernel panic can be initiated when the operating system makes an improper effort to access or modify memory or due to software glitches and malicious software. Additional typical factors contributing to a kernel panic encompass:

  • An error in the kernel itself, such as within a driver integrated into the kernel.
  • Malfunction or incorrect installation of random access memory (RAM) modules.
  • Hard disk impairment or data corruption.
  • Faulty or corrupted system files, processor, or memory components.
  • Usage of unsupported hardware.
  • Missing or malfunctioning drives or partitions.
  • Device drivers that are incompatible with the system.

Conclusion

  1. Kernel is the central module of an operating system. It is that part of an OS that loads first and remains in the main memory.
  2. Kernel examples are Zircon, Linux, WindowsNT, etc.
  3. Kernels are of five types, namely monolithic, microkernel, nanokernel, hybrid kernel and exokernel.
  4. Functions of a kernel include scheduling processes, resource allocation, device management, interrupt handling, memory management, and process management.