Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp02.tex V2 - 09/04/2008 6:09pm Page 1142

Appendix B: Working with the Source Code


The main kernel directory contains a number of subdirectories to roughly classify their contents. The key
kernel components reside in the following directories:

❑ Thekerneldirectory contains the code for the components at the heart of the kernel. It accom-
modates only about 120 files, with a total of approximately 80,000 lines of code — a surprisingly
small number for a project of this size. Developers stress how important it is to not add to the
contents of this directory unless absolutely necessary — patches that modify the files in the
directory are handled with extreme care and are very often the subject of long and controversial
discussions before final acceptance.
❑ High-level memory management resides inmm/. The memory management subsystem comprises
around 45,000 lines of code and is about the same size as the kernel itself.
❑ The code needed to initialize the kernel is held ininit/. It is discussed in AppendixD.
❑ The implementation of the System V IPC mechanism resides inipc/, which was discussed in
Chapter 5.
❑ sound/contains the drivers for sound cards. Because there are devices for many of the supported
buses, the directory includes bus-specific subdirectories with the corresponding driver sources.
Although they are kept in their own directory, the sound card drivers are not much different
from other device drivers.
❑ fs/holds the source code for all filesystem implementations and takes up approximately 25 MiB
of space in the kernel sources.
❑ net/contains the network implementation, which is split into a core section and a section to
implement the individual protocols. The network subsystem is 15 MiB in size and is one of the
largest kernel components.
❑ lib/contains generic library routines that can be employed by all parts of the kernel, including
data structures to implement various trees and data compression routines.
❑ drivers/occupies the lion’s share (130 MiB) of the space devoted to the sources. However, only
a few of its elements are found in the compiled kernel because, although Linux now supports
a huge number of drivers, only a few are needed for each system. The directory is further sub-
divided in accordance with varying strategies. It includes bus-specific subdirectories (such as
drivers/pci/) that group all drivers for accessory cards used with a specific bus type — the
drivers for the bus itself are also held in this directory. There are also a few category-specific sub-
directories, such asmedia/andisdn/, that contain cards of the same category but for different
buses.
❑ include/contains all header files with publicly exported functions. (If functions are only
used privately by a subsystem or are used in a single file only, the kernel inserts an include
file in the same directory as the C source code.) A distinction is made between two types
of include files — processor-dependent information is given in the subdirectory named
include/arch-arch/, and general architecture-independentdefinitions are provided in
include/linux/. A symbolic link (include/asm) to the directory appropriate to the architecture
is created when the kernel is configured. When the kernel sources are compiled, the header
search path of the C compiler is set so that files frominclude/linuxcanbelinkedinby
means of#include<file.h>— normally, this is only possible for the standard include files in
/usr/include/.
Free download pdf