Linux kernel--five subsystems

The Linux kernel has five core subsystems, namely process scheduling system, virtual file system (VFS), memory management unit (MMU), network unit, and inter-process communication (IPC).
Among the main components in the Linux kernel, the five core subsystems are the most important components, which together with the System Call Interface (System Call Interface) and the Arch layer constitute the framework of the entire Linux kernel.
Alt

Among them, the System Call Interface (SCI) provides a method to perform interface calls from user space to kernel space, which can be architecture-dependent, even within the same processor family. The SCI implementation can be found in ./linux/kernel, and the architecture-related parts in ./linux/arch.

1. Process scheduling system

This kernel subsystem is responsible for distributing CPU time fairly among all processes running simultaneously on the system and is the most important subsystem of the Linux kernel.

The focus of process management is the execution of the process. In the kernel, this is called a thread and represents a separate virtualization of the processor (thread code, data, stack, and CPU registers). In userspace, the term "process" is commonly used, but the Linux implementation does not distinguish between the two concepts (process and thread). The kernel provides application programming interfaces (APIs) through SCI to create new processes (fork, exec or Portable Operating System Interface POSIX functions), stop processes (kill, exit), and communication and synchronization mechanisms between them (signals or POSIX mechanisms) .

In process management, there is a need to share the CPU among active threads. The kernel implements a new scheduling algorithm that runs in constant time no matter how many threads are competing for the CPU, this is called an O(1) scheduler, meaning the time it takes to schedule one thread versus scheduling multiple threads same. The O(1) scheduler also supports multiple processors (called symmetric multiprocessing or SMP). (Process management source code can be found in /linux/kernel, and architecture-specific source code can be found in the /linux/arch directory.)

2. Virtual file system

This subsystem is responsible for providing a unified interface to access stored data across different file systems and physical storage media.

The Virtual File System (VFS) is an interesting aspect of the Linux kernel because it provides a common interface abstraction for file systems. VFS provides a switching layer between SCI and kernel-backed filesystems (see figure below).
![VFS provides a swap structure between users and filesystems]Alt

On top of the VFS is a generic API abstraction for functions such as open, close, read and write. The bottom layer of VFS is the file system abstraction, which defines the implementation of the upper layer functions. These are plugins for a given filesystem (there are now more than 50 of them). The filesystem source code can be found in ./linux/fs.

Below the filesystem layer is the cache, which provides the filesystem layer with a common set of functionality (independent of any particular filesystem). This caching layer optimizes access to physical devices by retaining data for short periods of time (or speculatively reading ahead to serve data when needed). Below the cache are device drivers, which implement the interface to a specific physical device.

Regarding device drivers, the vast majority of source code in the Linux kernel resides in the device drivers that make specific hardware devices available. The Linux source tree provides a driver subdirectory, which is further divided by the various devices supported (such as Bluetooth, I2C, serial, etc.). Device driver sources can be found in ./linux/drivers.

3. Memory management unit

This kernel subunit is responsible for properly allocating memory resources among the various processes running on the system. It's not just about giving each process a separate virtual address space.

Memory is an important resource managed by the Linux kernel. For efficiency, given the way hardware manages virtual memory, memory is managed in so-called pages (4KB in size on most architectures). The Linux kernel provides methods for managing available memory, as well as hardware mechanisms for physical and virtual mapping.

But memory management goes far beyond managing 4KB buffers. Linux provides virtual memory beyond the 4KB buffer, such as the slab allocator. This memory management scheme uses 4KB buffers as its basis, but then internally allocates structures that keep track of which pages are full, which are partially used, and which are already empty. This allows the scheme to dynamically grow and shrink memory based on larger system needs.

Memory for multiple users is supported, sometimes the available memory will be exhausted. Therefore, pages can be moved from memory to disk. This process is called swapping, and the memory management source code can be found in the /linux/mm directory of the Linux kernel source code.

4. Network unit

This unit allows Linux systems to connect to other systems over a network. It supports many possible hardware devices, and many network protocols that can be used. The network subsystem abstracts these two implementation details so that user processes and other kernel subsystems can access the network without having to know the physical device or protocol being used.
By design, the networking stack follows a layered architecture modeled on the protocol itself. Recall that the Internet Protocol (IP) is the core network layer protocol that sits below the transport protocols (most commonly the Transmission Control Protocol, or TCP). Above TCP is the socket layer, which is called through SCI.

The socket layer is the standard API for the networking subsystem and provides a user interface for various network protocols. From raw frame access to IP Protocol Data Units (PDUs), to TCP and User Datagram Protocol (UDP), the socket layer provides a standardized way to manage connections and move data between endpoints. The network sources can be found in the kernel at ./linux/net.

5. Inter-process communication

This unit enables processes to communicate with each other and with the kernel to coordinate their activities. Linux supports many inter-process communication (IPC) mechanisms, signals and pipes are two of them, Linux also supports the System V IPC mechanism named after the version of Unix TM.

Supongo que te gusta

Origin blog.csdn.net/hhhlizhao/article/details/131860078
Recomendado
Clasificación