This document discusses the key components and architecture of the Linux kernel. It begins by defining the kernel as the central module of an operating system that loads first and remains in memory, providing essential services. It then describes the major subsystems of Linux, including process management, memory management, virtual file systems, network stacks, and device drivers. It concludes that the modular design of the Linux kernel has supported its growth and success through independent and extensible development of these subsystems.
1. Operating System
Assignment
On
Submitted To :
Sir JUBAYER AL MAHMUD
Lecturer, Bangladesh University
Department of CSE
Submitted By :
MD. SADIQUR RAHMAN
ID : 201531043092
Batch No : 43
Department of CSE
BANGLADESH UNIVERSITY
15/1, Iqbal Road, Mohammadpur, Dhaka-1207
2. 1
What Is Kernel ?
The kernel is the central module of an operating system (OS).
It is the part of the operating system that loads first, and it
remains in main memory. Because it stays in memory, it is
important for the kernel to be as small as possible while still
providing all the essential services required by other parts of
the operating system and applications. The kernel code is
usually loaded into a protected area of memory to prevent it
from being overwritten by programs or other parts of the
operating system.
A kernel connects the application software to the hardware of a computer.
Typically, the kernel is responsible for memory management,
process and task management, and disk management. The
kernel connects the system hardware to the application
software. Every operating system has a kernel. For example
the Linux kernel is used numerous operating systems
including Linux, FreeBSD, Android and others.
3. 2
Types Of Kernel
Kernels may be classified mainly in two categories
1. Monolithic
2. Micro Kernel
1. Monolithic Kernel
Earlier in this type of kernel architecture, all the basic system
services like process and memory management, interrupt
handling etc were packaged into a single module in kernel
space. This type of architecture led to some serious
drawbacks like 1) Size of kernel, which was huge. 2) Poor
maintainability, which means bug fixing or addition of new
features resulted in recompilation of the whole kernel which
could consume hours.
In a modern day approach to monolithic architecture, the
kernel consists of different modules which can be
dynamically loaded and un-loaded. This modular approach
allows easy extension of OS's capabilities. With this
approach, maintainability of kernel became very easy as only
the concerned module needs to be loaded and unloaded
every time there is a change or bug fix in a particular
module. So, there is no need to bring down and recompile
the whole kernel for a smallest bit of change. Also, stripping
of kernel for various platforms (say for embedded devices
etc) became very easy as we can easily unload the module
that we do not want.
Linux follows the monolithic modular approach.
4. 3
2. Micro Kernel
This architecture majorly caters to the problem of ever
growing size of kernel code which we could not control in
the monolithic approach. This architecture allows some basic
services like device driver management, protocol stack, file
system etc to run in user space. This reduces the kernel code
size and also increases the security and stability of OS as we
have the bare minimum code running in kernel. So, if
suppose a basic service like network service crashes due to
buffer overflow, then only the networking service's memory
would be corrupted, leaving the rest of the system still
functional.
In this architecture, all the basic OS services which are made
part of user space are made to run as servers which are used
by other programs in the system through inter process
communication (IPC). eg: we have servers for device drivers,
network protocol stacks, file systems, graphics, etc.
5. 4
Linux Kernel Architecture
The Linux kernel is a monolithic kernel, supporting
true preemptive multitasking (both in user mode and, since
the 2.6 series, in kernel mode), virtual memory, shared
libraries, demand loading, shared copy-on-write executables
(via KSM), memory management, the Internet protocol suite,
and threading.
Device drivers and kernel extensions run in kernel space (ring
0 in many CPU architectures), with full access to the
hardware, although some exceptions run in user space, for
example file systems based on FUSE/CUSE, and parts of
UIO. The graphics system most people use with Linux does
not run within the kernel. Unlike standard monolithic kernels,
device drivers are easily configured as modules, and loaded
or unloaded while the system is running. Also, unlike
standard monolithic kernels, device drivers can be pre-
empted under certain conditions; this feature was added to
handle hardware interrupts correctly, and to better
support symmetric multiprocessing. By choice, the Linux
kernel has no binary kernel interface.
The hardware is also incorporated into the file hierarchy.
Device drivers interface to user applications via an entry in
the /dev or /sys directories. Process information as well is
mapped to the file system through the /proc directory.
6. 5
The following illustration shows the architecture of a
Linux system −
The architecture of a Linux System consists of the
following layers −
Hardware layer − Hardware consists of all peripheral
devices (RAM/ HDD/ CPU etc).
Kernel − It is the core component of Operating System,
interacts directly with hardware, provides low level
services to upper layer components.
Shell − An interface to kernel, hiding complexity of
kernel's functions from users. The shell takes
commands from the user and executes kernel's
functions.
7. 6
Utilities − Utility programs that provide the user most
of the functionalities of an operating systems.
Properties of the Linux kernel
When discussing architecture of a large and complex
system, you can view the system from many perspectives.
One goal of an architectural decomposition is to provide
a way to better understand the source, and that's what
we'll do here.
The Linux kernel implements a number of important
architectural attributes. At a high level, and at lower
levels, the kernel is layered into a number of distinct
subsystems. Linux can also be considered monolithic
because it lumps all of the basic services into the kernel.
This differs from a microkernel architecture where the
kernel provides basic services such as communication,
I/O, and memory and process management, and more
specific services are plugged in to the microkernel layer.
Each has its own advantages, but I'll steer clear of that
debate.
Over time, the Linux kernel has become efficient in terms
of both memory and CPU usage, as well as extremely
stable. But the most interesting aspect of Linux, given its
size and complexity, is its portability. Linux can be
compiled to run on a huge number of processors and
platforms with different architectural constraints and
needs. One example is the ability for Linux to run on a
process with a memory management unit (MMU), as well
8. 7
as those that provide no MMU. The uClinux port of the
Linux kernel provides for non-MMU support.
Major subsystems of the Linux kernel
Let's look at some of the major components of the Linux
kernel using the breakdown shown in the Figure as a
guide.
System Call Interface
The SCI is a thin layer that provides the means to
perform function calls from user space into the kernel. As
discussed previously, this interface can be architecture
dependent, even within the same processor family. The
SCI is actually an interesting function-call multiplexing
and demultiplexing service. You can find the SCI
implementation in ./linux/kernel, as well as architecture-
dependent portions in ./linux/arch.
9. 8
Process Management
Process management is focused on the execution of
processes. In the kernel, these are called threads and
represent an individual virtualization of the processor
(thread code, data, stack, and CPU registers). In user
space, the term process is typically used, though the
Linux implementation does not separate the two
concepts (processes and threads). The kernel provides an
application program interface (API) through the SCI to
create a new process (fork, exec, or Portable Operating
System Interface [POSIX] functions), stop a process (kill,
exit), and communicate and synchronize between them
(signal, or POSIX mechanisms).
Also in process management is the need to share the
CPU between the active threads. The kernel implements
a novel scheduling algorithm that operates in constant
time, regardless of the number of threads vying for the
CPU. This is called the O(1) scheduler, denoting that the
same amount of time is taken to schedule one thread as
it is to schedule many. The O(1) scheduler also supports
multiple processors (called Symmetric MultiProcessing,
or SMP). You can find the process management sources
in ./linux/kernel and architecture-dependent sources in
./linux/arch).
10. 9
Memory Management
Another important resource that's managed by the
kernel is memory. For efficiency, given the way that the
hardware manages virtual memory, memory is managed
in what are called pages (4KB in size for most
architectures). Linux includes the means to manage the
available memory, as well as the hardware mechanisms
for physical and virtual mappings.
But memory management is much more than managing
4KB buffers. Linux provides abstractions over 4KB buffers,
such as the slab allocator. This memory management
scheme uses 4KB buffers as its base, but then allocates
structures from within, keeping track of which pages are
full, partially used, and empty. This allows the scheme to
dynamically grow and shrink based on the needs of the
greater system.
Supporting multiple users of memory, there are times
when the available memory can be exhausted. For this
reason, pages can be moved out of memory and onto
the disk. This process is called swapping because the
pages are swapped from memory onto the hard disk.
You can find the memory management sources in
./linux/mm.
11. 10
File Systems
The term filesystem has two somewhat different
meanings, both of which are commonly used. This can be
confusing to novices, but after a while the meaning is
usually clear from the context.
One meaning is the entire hierarchy of directories (also
referred to as the directory tree) that is used to organize
files on a computer system. On Linux and Unix, the
directories start with the root directory (designated by a
forward slash), which contains a series of subdirectories,
each of which, in turn, contains further subdirectories,
etc.
A variant of this definition is the part of the entire
hierarchy of directories or of the directory tree that is
located on a single partition or disk. (A partition is a
section of a hard disk that contains a single type of
filesystem.)
The second meaning is the type of filesystem, that is,
]how the storage of data (i.e., files, folders, etc.) is
organized on a computer disk (hard disk, floppy disk,
CDROM, etc.) or on a partition on a hard disk. Each type
of filesystem has its own set of rules for controlling the
allocation of disk space to files and for associating data
about each file (referred to as meta data) with that file,
12. 11
such as its filename, the directory in which it is located,
its permissions and its creation date.
An example of a sentence using the word filesystem in
the first sense is: "Alice installed Linux with the filesystem
spread over two hard disks rather than on a single hard
disk." This refers to the fact that [ the entire hierarchy of
directories of ] Linux can be installed on a single disk or
spread over multiple disks, including disks on different
computers (or even disks on computers at different
locations).
An example of a sentence using the second meaning is:
"Bob installed Linux using only the ext3 filesystem
instead of using both the ext2 and ext3 filesystems." This
refers to the fact that a single Linux installation can
contain one or multiple types of filesystems. One hard
disk can contain one or multiple types of filesystems
(each z can be spread across multiple hard disks.
Virtual file system
The virtual file system (VFS) is an interesting aspect of the
Linux kernel because it provides a common interface
abstraction for file systems. The VFS provides a switching
layer between the SCI and the file systems supported by
the kernel (see the Figure).
13. 12
Figure. The VFS provides a switching fabric between users and file systems
At the top of the VFS is a common API abstraction of
functions such as open, close, read, and write. At the
bottom of the VFS are the file system abstractions that
define how the upper-layer functions are implemented.
These are plug-ins for the given file system (of which
over 50 exist). You can find the file system sources in
./linux/fs.
Below the file system layer is the buffer cache, which
provides a common set of functions to the file system
layer (independent of any particular file system). This
caching layer optimizes access to the physical devices by
keeping data around for a short time (or speculatively
read ahead so that the data is available when needed).
Below the buffer cache are the device drivers, which
implement the interface for the particular physical device.
14. 13
Network stack
The network stack, by design, follows a layered
architecture modeled after the protocols themselves.
Recall that the Internet Protocol (IP) is the core network
layer protocol that sits below the transport protocol
(most commonly the Transmission Control Protocol, or
TCP). Above TCP is the sockets layer, which is invoked
through the SCI.
The sockets layer is the standard API to the networking
subsystem and provides a user interface to a variety of
networking protocols. From raw frame access to IP
protocol data units (PDUs) and up to TCP and the User
Datagram Protocol (UDP), the sockets layer provides a
standardized way to manage connections and move data
between endpoints. You can find the networking sources
in the kernel at ./linux/net.
Device drivers
The vast majority of the source code in the Linux kernel
exists in device drivers that make a particular hardware
device usable. The Linux source tree provides a drivers
subdirectory that is further divided by the various
devices that are supported, such as Bluetooth, I2C, serial,
and so on. You can find the device driver sources in
./linux/drivers.
15. 14
Conclusion
The Linux kernel is one layer in the architecture of the
entire Linux system. The kernel is conceptually composed
of five major subsystems: the process scheduler, the
memory manager, the virtual file system, the network
interface, and the inter-process communication interface.
These subsystems interact with each other using function
calls and shared data structures.
The conceptual architecture of the Linux kernel has
proved its success; essential factors for this success were
the provision for the organization of developers, and the
provision for system extensibility. The Linux kernel
architecture was required to support a large number of
independent volunteer developers. This requirement
suggested that the system portions that require the most
development -- the hardware device drivers and the file
and network protocols -- be implemented in an
extensible fashion. The Linux architect chose to make
these systems be extensible using a data abstraction
technique: each hardware device driver is implemented
as a separate module that supports a common interface.
In this way, a single developer can add a new device
driver, with minimal interaction required with other
developers of the Linux kernel. The success of the kernel
implementation by a large number of volunteer
developers proves the correctness of this strategy.