OVERVIEW OF LINUX KERNEL STRUCTURE
Naveenraja S II MCA “A” 08MCR057
CONTENTS Abstract 1. Introduction 2. What is Kernel? 2.1. Definition 2.2. Categories of Kernel 2.2.1. Monolithic 2.2.2. Microkernel 2.2.3. Hybrid Kernel 2.2.4. Exo Kernel 3. Features of Linux Kernel 4. Linux Kernel Structure 5. Linux Kernel System Data Structures 5.1 Task List 5.2 Memory Map 5.3 I-nodes 5.4 Data Connection 6. Conclusion
OVERVIEW OF LINUX KERNEL STRUCTURE Abstract Linux is one of the most widely used Open Source operating system in the world. It meets the current demands like Multi tasking, Multi-User Process, Architecture independence, Paging, Different file systems etc., with the best architecture of the kernel, Linux has been successfully adopted by many users. This paper describes the general outline of the Linux kernel Architecture. Linux kernel is monolithic and it consists of more than 5 million lines of codes. Linux kernel is designed in a manner that every function of the kernel has been repeatedly altered and expanded. Linux kernel source consists of more than ten directories and it can be loaded in any architecture computers. These directories are factors of success behind the overall system. 1. Introduction Linux is a member of the large family of Unix-like operating systems. Linux was initially developed by Linus Torvalds in 1991 as an operating system for IBM compatible personal computers based on the Intel 80386 microprocessor. Linus remains deeply involved with improving Linux, keeping it up-to-date with various hardware developments and coordinating the activity of hundreds of Linux developers around the world. Over the years, developers have worked to make Linux available on other architectures, including Alpha, SPARC, Motorola MC680x0, PowerPC, and IBM System/390. One of the more appealing benefits to Linux is that it isn't a commercial operating system: its source code under the GNU Public License is open and available to anyone to study. Technically speaking, Linux is a true UNIX kernel, although it is not a full UNIX operating system, because it does not include all the applications such as filesystem utilities, windowing systems and graphical desktops, system administrator commands, text editors, compilers, and so on. However, since most of these programs are freely available under the GNU General Public License, they can be installed into one of the filesystems supported by Linux.
Since Linux is a kernel, many Linux users prefer to rely on commercial distributions, available on CD-ROM, to get the code included in a standard Unix system. Alternatively, the code may be obtained from several different FTP sites. 2. What is Kernel? 2.1. Definition The kernel is
a
program
that
constitutes
the
central
core
of
a
computer operating system. It has complete control over everything that occurs in the system. The kernel is the first part of the operating system to load into memory during booting (i.e., system startup), and it remains there for the entire duration of the computer session because its services are required continuously. Thus it is important for it to be as small as possible while still providing all the essential services needed by the other parts of the operating system and by the various application programs. However, larger kernels can provide more functionality. 2.2. Categories of Kernel Kernels can be classified into four broad categories:: 2.2.1. Monolithic Monolithic kernels, which have traditionally been used by Unix-like operating systems, contain all the operating system core functions and the device drivers (small programs that allow the operating system to interact with hardware devices, such as disk drives, video cards and printers). Modern monolithic kernels, such as those of Linux and FreeBSD, both of which fall into the category of Unix-like operating systems, feature the ability to load modules at runtime, thereby allowing easy extension of the kernel's capabilities as required, while helping to minimize the amount of code running in kernel space. 2.2.2. Microkernel A microkernel usually provides only minimal services, such as defining memory address spaces, interprocess communication (IPC) and process management. All other functions, such as hardware management, are implemented as processes running independently of the kernel. Examples of microkernel operating systems are AIX, BeOS, Hurd, Mach, Mac OS X, MINIX and QNX. 2.2.3. Hybrid Kernel Hybrid kernels are similar to microkernels, except that they include additional code in kernel space so that such code can run more swiftly than it would were it in user space. Most modern operating systems use hybrid kernels, including Microsoft
Windows NT, 2000 and XP. Dragonfly BSD, a recentfork (i.e., variant) of FreeBSD, is the first non-Mach based BSD operating system to employ a hybrid kernel architecture. 2.2.4. Exo Kernel Exo type kernel is not yet stabilized. It's under design and research. The user mode processes running in this type of kernel has the ability to access kernel resources like process tables, etc directly. 3. Features of Linux Kernel By itself, the Linux kernel is not very innovative. When Linus Torvalds wrote the first kernel, he referred to some classical books on UNIX internals, like Maurice Bach's The Design of the Unix Operating System (Prentice Hall, 1986). Actually, Linux still has some bias toward the UNIX baseline described in Bach's book (i.e., SVR4). However, Linux doesn't stick to any particular variant. Instead, it tries to adopt good features and design choices of several different UNIX kernels. Linux kernel consists of following features. 1. The Linux kernel is monolithic. It is a large, complex do-it-yourself program, composed of several logically different components. In this, it is quite conventional; most commercial UNIX variants are monolithic. 2. Linux Kernel Supports Modules, since it is able to automatically load and unload modules on demand. 3. Linux uses kernel threads in a very limited way to execute a few kernel functions periodically; since Linux kernel threads cannot execute user programs, they do not represent the basic execution context abstraction. 4. Multithreaded application support. 5. Linux is a non-preemptive kernel. This means that Linux cannot arbitrarily interleave execution flows while they are in privileged mode. Several sections of kernel code assume they can run and modify data structures without fear of being interrupted and having another thread alter those data structures. 6. Linux kernel supports most of the available file systems.Eg: VFS, JFS etc.
4. Linux Kernel Structure 1. Process management The scheduler handles all the active, waiting, and blocked processes. 2. Memory management It is responsible for allocating memory to each process and for protecting allocated memory against access by other processes. 3. File system In UNIX, almost everything is handled over the file system interface. Device drivers can be addressed as files. /proc file system allows us to access data and parameters in the kernel 4. Device drivers Abstract from the underlying hardware and allow us to access the hardware with well-defined APIs 5. Networks Incoming packets are asynchronous events and have o be collected and identified, before a process can handle them. Most network operations cannot be allocated to a specific process. The given below illustration shows that the above described kernel structure.
Kernel Applications and tools
User Space
System Calls Process Management
Memory Management
Multitasking
Virtual Memory
Scheduler Architecture
Memory
Specific
Manager
Code
File Systems Files,Directories File System types Block Devices
Component
Device Drivers Device Access
Network Network Functionality Functionality Network
Character
Protocols
Devices
Network
Software Support
Hardware support
Drivers CPU
RAM
Hard disk, CD,floppy
Terminals
Network Adapter
Hardware
Figure 1: Linux Kernel Structure (General Diagram) 5. Linux Kernel System Data Structures 5.1 Task List The process scheduler maintains a block of data for each process that is active. These blocks of data are stored in a linked list called the task list; the process scheduler always maintains a current pointer that indicates the current process that is active. 5.2 Memory Map The memory manager stores a mapping of virtual to physical addresses on a per-process basis, and also stores additional information on how to fetch and replace particular pages. This information is stored in a memory-map data structure that is stored in the process scheduler's task list. 5.3 I-nodes The Virtual File System uses index-nodes (i-nodes) to represent files on a logical file system. The I-node data structure stores the mapping of file block numbers to physical device addresses. I-node data structures can be shared across processes if two processes have the same file open. This sharing is accomplished by both task data blocks pointing to the same I-node. 5.4 Data Connection All of the data structures are rooted at the task list of the process scheduler. Each process on the system has a data structure containing a pointer to its memory mapping information, and also pointers to the I-nodes representing all of the opened files. Finally, the task data structure also contains pointers to data structures representing the entire opened network connections associated with each task. 6. Conclusion Linux is a modular, UNIX-like monolithic kernel. Kernel is the heart of the OS that executes with special hardware permission (kernel mode). “Core kernel” provides framework, data structures, and support for drivers, modules, subsystems. Kernel designers must consider many competing goals. Linux source tree mirrors kernel structure. All the architecture dependent source sub trees live in /arch. The “main” source of kernel lives in /kernel/init.c. lxr.linux.no is a nice web-based source browser.