Linux kernel structure detailed

xiaoxiao2021-03-06  39

The Linux kernel is mainly composed of five subsystems: process scheduling, memory management, virtual file system, network interface, inter-process communication. 1. Process Scheduling: Control Process Visits for CPUs. When you need to select the next process run, select the most prominent process by the scheduler. The running process is actually a process that is only waiting for the CPU resource. If a process is waiting for other resources, the process is not running process. Linux uses a relatively simple priority-based process scheduling algorithm to select new processes.

2. Memory Management (MM) allows multiple process secure shared master memory areas. Linux's memory management supports virtual memory, that is, the total amount of the program, its code, data, and stack can exceed the actual memory size, and the operating system is just reserved in memory, the rest of the block Then retain it in the disk. If necessary, the operating system is responsible for switching the block and memory interval. Memory management is logically divided into hardware-independent sections and hardware-related parts. The hardware independent section provides the process's mapping and logical memory of the logical memory, the hardware-related part provides a virtual interface for memory management hardware. 3. Virtual Filesystem, VFS) Hide specific details of various hardware, providing unified interfaces for all devices, VFS provides up to dozens of different file systems. Virtual file systems can be divided into logical file systems and device drivers. The logical file system refers to the file system supported by Linux, such as EXT2, FAT, etc., refers to the device driver module written by each hardware controller. 4. Network Interface (NET) provides access to various network standards and various network hardware support. The network interface can be divided into network protocols and network drivers. The Network Protocol part is responsible for implementing each possible network transport protocol. The network device driver is responsible for communicating with hardware devices, each of which has a corresponding device driver. 5. Process Communication (IPC) Supports various communication mechanisms between processes. Process schedules in the center location, all other subsystems rely on it because each subsystem needs to hang or recover processes. In general, when a process waits for the hardware operation to complete, it is suspended; when the operation is true, the process is resumed. For example, when a process sends a message over the network, the network interface needs to hang the transmission process until the hardware successfully completed the transmission of the message, and when the message is successfully sent, the network interface returns a code to the process, indicating the success of the operation. Or fail. Other subsystems depends on process schedules with similar reasons. The dependencies between each subsystem are as follows: The relationship between process scheduling and memory management: these two subsystems depend on each other. In a multi-channel program environment, the program is to run to create a process, and the first thing to create a process is to load the program and data into memory. The relationship between processes communication and memory management: Process communication subsystems To rely on memory management to support shared memory communication mechanisms, this mechanism allows two processes to have their own private space, and can also access common memory areas. The relationship between virtual file system and network interface: Virtual file system supports network file system (NFS) using network interfaces, and also supports RAMDisk devices using memory management. The relationship between memory management and virtual file system: Memory Management Using Virtual File System Support Switching, Exchange Process (SWAPD) regularly scheduled schedule, which is the only reason for memory management dependent on process schedule. When the memory mapping of a process is replaced, the memory management issues a request to the file system, while hanging the process currently running. In addition to these dependencies, all subsystems in the kernel have to rely on some common resources. These resources include the process of all subsystems. For example: the process of distributing and releasing memory space, printing a warning or error message, and there is a debug routine of the system, etc. In the implementation of the system data structure in Linux kernel, some data structures have been used in frequency, they are: task_struct. Linux kernel uses a data structure (task_struct) represents a process, representing the data structure pointer representing the process forms a Task array (In Linux, tasks and processes are the same term), which is sometimes referred to as pointer vector.

The size of this array is made from NR_TASKS (default to 512), indicating the number of processes that can run at the same time in the Linux system. When a new process is created, Linux assigns a task_struct structure for the new process and saves the pointer in the Task array. The scheduler has always maintained a Current pointer, and he points to the process currently running. MM_STRUCT virtual memory represents a mm_struct structure, which actually includes information about the currently executing image, and includes a pointer to the VM_Area_STRUCT structure, and the VM_AREA_STRUCT structure describes a region of virtual memory. The file, directory, etc. in the Inode Virtual File System (VFS) are represented by the corresponding index node (inode). The content in each VFS index node is provided by the file system exclusive routine. The VFS index node exists only in the kernel memory, actually saved in the VFS index node cache. If the two processes are opened with the same process, INADE's data structure can be shared, which is completed by the data blocks in two processes to complete. The specific structure of Linux so-called concrete structure refers to the structure of the system. The specific structure of Linux is similar to the abstract structure. This correspondence is because the abstract structure is derived from the specific structure, and our division does not strictly depending on the directory structure of the source code, and the packets of the subsystem do not match, but it is very close to the source Catalog structure of the code. Although the abstract structure of the previous discussion shows that there is only a few dependencies between the individual subsystems, there is a high dependency between the five subsystems of the specific structure. We can see that many dependencies in the specific structure have not appeared in the abstract structure. Linux kernel source code is currently 20.x and 2.2.x, because the version is different, so if you want a new driver to support 2.0.x and support 2.2. x, you need to compile according to the core version. To do this, you must support macro Linux_version_code. If the version of the kernel is represented by ABC, the value of this macro is 216A 28B C. To use the value of the specified kernel version, we can use the kernel_version macro, we can also define it. The modification of the kernel is published in the way of patch files. The PATCH utility is used to use a series of modifications to the kernel source file. For example: You have 2.2.9 source code, but want to move to 2.2.10. You can get 2.2.10 patch files, apply PATCH to modify 2.2.9 source files. For example: $ CD / USR / SRC / Linux $ PATCH-PL

转载请注明原文地址:https://www.9cbs.com/read-60065.html

New Post(0)