Introduction:The Linux kernel is the core of a large and complex operating system. However, although it is large, it is well organized by the concept of subsystems and layers. In this article, you will explore the overall structure of the Linux kernel and learn some major subsystems and core interfaces.
As the goal of this article is to introduce the Linux kernel and explore its architecture and main components, we should first review the brief history of Linux and then review the Linux kernel architecture at a higher level, finally, we will introduce its main subsystems. The Linux kernel has more than 6 million lines of code, so this article cannot be a complete introduction. Use a link pointing to other content for further learning.
Although Linux is definitely the most popular open-source operating system, the history of Linux is very short compared with that of other operating systems. In the early days of the emergence of computers, programmers used hardware languages for development on bare hardware. The absence of an operating system means that only one application (and one user) at a time can use these large and expensive devices. The early operating system was developed in 1950s to provide a simple development experience. This includes General Motors Operating System (GMOS) developed for IBM 701 and FORTRAN Monitor System (FMS) developed for IBM 709 for North American Aviation ).
In 1960s, MIT and some companies developed an experimental operating system named Multiplexed Information and Computing Service for GE-645. AT&T, one of the developers of this operating system, later withdrew from Multics and developed its own operating system named Unics in 1970. C language was born with this operating system. C language was developed for this purpose. Then they used C language to rewrite the operating system, making the Operating System Development portable.
Twenty years later, Andrew Tanenbaum created a microkernel version of UNIX named MINIX (representing minimal UNIX) that can run on a small PC. This open-source operating system inspired Linus Torvalds to develop Linux in 1990s (see figure 1 ).
Linux quickly evolved from a personal project to a development project involving thousands of people around the world. For Linux, one of the most important decisions is to use GPL (GNU General Public License ). Under the Protection of GPL, the Linux kernel can prevent commercial use, and it also benefited from the user space development of the GNU project (Richard Stallman, whose source code is much larger than the Linux kernel. This allows the use of some very useful applications, such as GCC (GNU Compiler Collection) and various shell support.
Now let's take a high-level look at the GNU/Linux operating system architecture. You can consider the operating system at two levels, as shown in figure 2.
The top is the user (or application) space. This is where your application runs. The user space is the kernel space, and the Linux kernel is located here.
Gnu c Library (glibc) is also here. It provides a system call interface to connect to the kernel, and a conversion mechanism between the user space application and the kernel. This is very important because the kernel and user space applications use different protective address spaces. Each user space process uses its own virtual address space, while the kernel occupies a separate address space. For more information, see the link in the references section.
The Linux kernel can be further divided into three layers. At the top is the system call interface, which implements some basic functions, suchreadAndwrite. The kernel code under the System Call interface can be more accurately defined as the kernel code independent of the architecture. These codes are common to all the processor architectures supported by Linux. The code that relies on the architecture forms part of the BSP (Board Support Package. These codes are used as processors and platform-specific code for a given architecture.
Systems can be viewed from many perspectives when discussing the architecture of large and complex systems. One goal of Architecture Analysis is to provide a way to better understand the source code, which is the purpose of this Article.
The Linux kernel implements many important architecture attributes. At a high or low level, the kernel is divided into multiple subsystems. Linux can also be seen as a whole because it will integrate all these basic services into the kernel. This is different from the microkernel architecture, which provides some basic services, such as communication, I/O, memory and process management, more specific services are inserted into the microkernel layer. Each kernel has its own advantages, but this is not discussed here.
As time passes, the Linux kernel has high efficiency in memory and CPU usage, and is very stable. But for Linux, the most interesting thing is that it still has good portability on the premise of this size and complexity. After Linux compilation, it can run on a large number of processors and platforms with different architecture constraints and requirements. One example is that Linux can run on a processor with a memory management unit (MMU) or on a processor that does not provide MMU. The Linux kernel's uClinux port provides support for non-MMU. For more information, see references.
Use the classification shown in Figure 3 to describe the main components of the Linux kernel.
The SCI layer provides some mechanisms for executing function calls from user space to the kernel. As discussed earlier, this interface relies on the architecture, even within the same processor family. SCI is actually a very useful function call multiplexing and multi-path decomposition service. In./linux/kernel, you can find the SCI implementation, and find the architecture-dependent part in./linux/arch. For more information about this component, see references.
Process Management focuses on process execution. In the kernel, these processes are calledThreadRepresents a separate processor Virtualization (thread code, Data, stack, and CPU register ). In user spaceProcessThis term, however, does not differentiate between the two concepts in Linux (process and thread ). The kernel uses SCI to provide an application programming Interface (API) to create a new process (fork, exec, or Portable Operating System Interface [POSIX] function ), stop processes (kill and exit) and communicate and synchronize between them (signal or POSIX mechanism ).
Process Management also includes the need to process CPU sharing between active processes. The kernel implements a new scheduling algorithm. No matter how many threads compete for the CPU, this algorithm can be operated within a fixed period of time. This algorithm is called the O (1) scheduler, and the name indicates that the time used to schedule multiple threads is the same as the time used to schedule one thread. O (1) scheduler can also support multi-processor (called Symmetric multi-processor or SMP ). You can find the source code of process management in./linux/kernel, and find the source code dependent on the architecture in./linux/arch. For more information about this algorithm, see references.
Another important resource managed by the kernel is memory. To improve efficiency, if the virtual memory is managed by hardwareMemory Page(4 kb for most architectures ). Linux includes the management of available memory and the hardware mechanism used by physical and virtual ing.
However, memory management requires more than 4 kb of buffer. Linux provides an abstraction of a 4 KB buffer, such as an slab distributor. This memory management mode uses a 4 KB buffer as the base, then allocates the structure from it, and tracks the Memory Page usage, such as which memory pages are full and which pages are not fully used, which pages are empty. In this way, the memory usage can be dynamically adjusted according to the system requirements.
To support memory usage by multiple users, the available memory is sometimes consumed. For this reason, the page can be removed from the memory and placed into the disk. This process is calledExchangeBecause the page is switched from memory to hard disk. The source code for memory management can be found in./linux/mm.
Virtual File System (VFS) is a very useful aspect of the Linux kernel, because it provides a general interface abstraction for the file system. VFS provides an exchange layer between the SCI and the file systems supported by the kernel (see figure 4 ).
In VFS, it is a general API abstraction for functions such as open, close, read, and write. Under VFS is the file system abstraction, which defines the implementation method of upper-layer functions. They are extensions of a given File System (more than 50. The source code of the file system can be found in./linux/fs.
The file system layer is a buffer cache, which provides a common function set for the file system layer (not related to a specific file system ). This cache layer optimizes access to physical devices by retaining data for a period of time (or by pre-reading the data to be available as needed. The buffer cache is a device driver that implements interfaces for specific physical devices.
The network stack is designed to follow the layered architecture of the simulation protocol. In retrospect, Internet Protocol (IP) is the core network layer Protocol under the Transport Protocol (usually known as transport control Protocol or TCP. TCP is the socket layer, which is called through SCI.
The socket layer is the standard API of the network subsystem. It provides a user interface for various network protocols. From accessing the original frame to the IP Protocol Data Unit (PDU), to TCP and User datamprotocol (UDP), the socket layer provides a standardized method to manage connections, move data between endpoints. The network source code in the kernel can be found in./linux/net.
The Linux kernel contains a large amount of code in the device drivers that can run specific hardware devices. The Linux source code tree provides a sub-directory of the driver, which is further divided into various supporting devices, such as Bluetooth, I2C, and serial. The device driver code can be found in./linux/drivers.
Although Linux is largely independent from the operating architecture, some elements must consider the architecture to operate normally and achieve higher efficiency .. The/linux/arch sub-directory defines the architecture-dependent part of the kernel source code, which contains various architecture-specific sub-directories (BSP ). For a typical desktop system, the i386 directory is used. Each architecture subdirectory contains many other subdirectories. Each subdirectory focuses on a specific aspect of the kernel, such as boot, kernel, and memory management. The code that depends on the architecture can be found in./linux/arch.
If the portability and efficiency of the Linux kernel are not good enough, Linux also provides other features that cannot be classified into the above categories.
As a production operating system and open-source software, Linux is a good platform for testing new protocols and their enhancements. Linux supports a large number of network protocols, including typical TCP/IP and high-speed network extensions (larger than 1 Gigabit Ethernet [GbE] and 10 GbE ). Linux can also support protocols such as the stream control transmission protocol (SCTP), which provides many more advanced features than TCP (the successor of the transport layer protocol ).
Linux is also a dynamic kernel that supports dynamic addition or deletion of software components. These modules are called dynamic and Rewritable kernel modules, which can be inserted by the user at any time or as needed during boot.
One of the latest Linux enhancements is the operating system (called the system administrator) that can be used as another operating system ). Recently, the kernel has been modified, called a kernel-based Virtual Machine (KVM ). This modification enables a new interface for the user space, which allows other operating systems to run on the kernel with KVM enabled. In addition to running Linux instances, Microsoft Windows can also be virtualized. The only restriction is that the underlying processor must support new virtualization commands. For more information, see references.
This article briefly introduces the Linux kernel architecture, features, and functions. For more information about the kernel, see the Documentation directory attached to each Linux release. Please be sure to refer to the reference section at the end of this article to learn more about the topics discussed in this article.
Reprinted statement: This article from http://www.ibm.com/developerworks/cn/linux/l-linux-kernel/
========================================================== ======================================
Recommended:In-depth analysisLinuxKernel source code
Http://oss.org.cn/kernel-book/index.htm