The composition of the Linux system

Source: Internet
Author: User
Tags numeric value

<linux System 7 Large subsystem >

A:sci (System call Interface)

———— the user program through the software interrupt , call the system kernel provides the function, this user space and the kernel provides the service between the interface is called the system call. System calls are provided by the Linux kernel, and user space cannot be directly used by system calls. The use of system calls in a user process must span the bounds of the application and the kernel.

———— The Linux kernel provides the user with a unified system invocation interface, but the method of system invocation on different processors varies. The Linux kernel provides a number of system calls, and now explores the methods of Linux system invocation from the basic principles of system invocation. When the index and parameters of the system C library call are loaded, the 0X80 software interrupt is called, which executes the System_call function, which handles all system calls as marked by the EAX register contents. After several unit tests, the index of the contents of the EAX register is used to check the System_call_table table for the entry of the system call, and then the system calls are executed. After returning from the system call, finally call the kernel function system_exit and call the Resume_userspace function to return the user space.

B:PM (Process Management)

———— the Linux kernel implements process-related operations through the process management subsystem, on Linux systems, all computations are performed through processes, which can be short-term (executing a command) or long-term (a network service). A Linux system is a dynamic system that can adapt to changing computing needs through process management.

———— in user space, processes are represented by process identifiers (PID). From the user's point of view, a PID is a numeric value that uniquely identifies a process, and a PID value does not change throughout the lifetime of the process, but the PID can be reused after the process is destroyed. There are several ways to create a process, you can create a new process, or you can create a child process for the current process.

———— the Linux kernel space, each process has a separate data structure that holds information about the process's ID, priority, space for the address, and is called the Process control block. The so-called process management is the management of the Process control block

PM (Process Management)

The process of ———— Linux is generated through the fork () function system call. The process called fork () is called the parent process, and the resulting process is called a child process. When a child process is created, other data structures are exactly the same as the parent process, except for the process ID. After the fork () system call creates memory, the child process is immediately added to the kernel's process debug queue and then uses the EXEC () system call to add the program's code to the child process's address space, after which the child process begins executing its own code.

———— can have multiple processes on a system, but in general there is only one CPU, and at the same time only one process is working, even if there are multiple CPUs, it is not as many as the number of processes. This is the work of the process management subsystem if you have a number of processes that can work on the CPU. The Linux kernel designs the structure that holds the process queue, and there are several queues on a system that hold different state processes. A process can have several states, specifically defined by the operating system, but with at least a running state, a ready state, and a wait of 3 states, the kernel designs the corresponding queue to hold the corresponding state of the process Control block.

———— When a user process is loaded, it enters the ready state, is added to the Ready state queue, the CPU time is rotated to the ready state queue, and the process is switched to the code of the process, which is executed when the time slice of the process is swapped out later. If the process occurs I/O operations are also swapped out in advance and stored in the wait queue, when the I/O request returns, the process is placed in the ready queue. The Linux system designs a number of different methods for process queue management, and the main purpose is to improve the stability of process debugging.

C:MM (Memery Management)

———— memory is an important resource of the computer and an important part of the kernel. Computers that use virtual memory technology, memory-managed hardware manages memory in paging mode. Paging means that the physical memory of the computer system is equal to the same size, each memory shard is called a memory page, usually the memory page size is 4KB. The memory management subsystem of the Linux kernel manages the mapping between virtual memory and physical memory, as well as the available memory space of the system.

———— memory management is not only a 4KB buffer to manage. Linux provides an abstraction of the 4KB buffer, such as the slab allocator. This memory management mode uses 4KB buffers as cardinality, then allocates structures from it, and tracks memory page usage, such as which pages are full, which pages are not fully used, and which pages are empty. This allows the pattern to dynamically adjust memory usage as required by the system.

———— on a system that supports multiple users, it is prone to the depletion of physical memory due to the increased memory footprint. To solve the problem of exhaustion of physical memory, the memory management subsystem specifies that the page can be moved out of memory and placed on disk, a process known as swapping. The source code for memory management can be found in./linux/mm

D:DD (device driver)

———— with the increasing of modern computer external equipment, the more devices are developed, the development of computer bus is also very rapid, the function of the operating system is also increasing, the system software is more and more complex, the access to external devices can not be like the DOS era of direct access to equipment hardware, Device drivers are required for almost all devices. Modern operating systems almost all provide a specific hardware-independent device driver interface, the advantage is to block the details of the operation of the specific device, the user through the interface provided by the operating system can access the device, and the specific device operation details are driven by the device, driver developers only need to provide the appropriate interface to the operating system.

———— Unlike other operating systems for complex classification of devices, the Linux kernel divides devices into 3 categories: block devices, character devices, and network devices. This is an abstract classification method, which abstracts 3 different data reading and writing methods from the features of the device.

? Block devices

The concept of block devices is that one I/O operation can operate multiple bytes of data, data read and write buffer, when the read-write buffer full after the transfer of data, such as the hard disk can read one sector of data at a time, the block device supports random read and write operations, can read and write data from the specified location;

? character device

Character device access is linear, and can be accessed in bytes, such as serial devices, can read and write data according to characters, but only in order to operate, can not specify an address access;

? Network equipment

Compared with the previous two methods, the network device is special, the kernel specifically divides such drivers separately, the network equipment can read and write data through the socket interface.

———— The Linux kernel accesses the device according to the main device number and from the device number, the main device number describes the driver for the control device , distinguishing the different devices from the same driver from the device number. That is, the master device number corresponds to the device driver, representing a type of device, which corresponds from the device number to the specific device and represents the same class of device number. If you use the IDE interface two hard disks, the master device number is the same, but the device number is different. Linux provides a mknod command to create a description file for the device driver.         Linux kernel This kind of master-slave device number classification method can be very good management equipment.

———— user process access to external devices is through device-independent software, device-independent software is the core of a variety of software abstraction layer such as VFS. When a user initiates a data request to an external device, the device-independent software invokes the device's appropriate driver, the driver accesses the external hardware device through the bus or register, initiates the request, and the driver registers an interrupt handler with the system's interrupt vector table at initialization time. When the external hardware has a request to return the interrupt signal, the kernel calls the response of the interrupt handler, the interrupt handler reads the returned data from the hardware register, and then transfers the device service program to the kernel, the device service program sends the data to the device-independent software, and finally arrives at the user process.

———— Linux device drivers involve other subsystems such as memory management, interrupt management, hardware register and bus access, and most of the drivers are designed to be modules for ease of use and are designed to be processed by kernel modules.

————-Driven authoring and debugging is a complex thing, and driving code consumes more than half of the Linux kernel code.

E:VFS (virtual file system)

———— in different format of the file partition, the program can read and write files correctly, and the result is the same. Sometimes when using a Linux system, you can copy files directly within different types of file partitions, for applications that do not know the type of file system, or even the type of file, which is what the virtual file system does behind the scenes. The virtual file system masks the differences between different file systems and provides a unified interface to the user.

The ———— virtual file system, or VFS virtual filesystem,is a software abstraction layer in the Linux kernel. It provides an interface mechanism to actual file systems such as Ext2,vfat through some data structures and their methods.       Any file in Linux can be manipulated by using the same set of file I/O system calls without regard to the specific file system format in which it resides, and further, file operations may take place between different file systems.

———— in a Linux system, everything can be considered a file. Not only ordinary text files, directories can be treated as files, and character devices, block devices, sockets, etc. can be treated as a file. Although these files are of different types, they use the same action method. This is also one of the basic philosophies of unix/linux design.

———— virtual file System (VFS) is the key to implementing "Everything is a file" feature, a software layer of the Linux kernel that provides a filesystem interface to user-space programs, and an abstraction in the kernel that allows different types of file systems to exist. VFS can be understood as an abstract interface standard, and all file systems in the system depend not only on VFS coexistence but also on VFS working together.

———— in order to support different file systems, VFS defines the most basic conceptual interfaces and data structures that are supported by all file systems, and when implementing a specific file system, VFS standard interfaces and data structures are provided to VFS, Different file systems may differ in the entity concept, but the VFS interface needs to be consistent with the concept of the VFS definition in order to achieve file system independence for the user. The VFS hides the details of the specific file system, so all the file systems are the same on the VFS layer and other parts of the kernel.

F:network Stack

———— Write a network application, using the socket through the TCP/IP protocol to communicate with other machines, and the previous introduction of the kernel subsystem similar to the socket-related functions are done through the kernel subsystem, the part of the task is the core network subsystem, sometimes this part of the code is called " Network Stack ".

———— Linux kernel provides excellent network processing power and function, which is inseparable from the design idea of network stack code, the network stack of Linux inherits the traditional hierarchy, and the network data from the user process to the actual network equipment needs four levels.

———— in fact, in each layer can also be divided into a lot of layers, the path of data transmission is based on the level, not across a certain level.

———— Linux Network subsystem adopts a similar object-oriented design idea to the network hierarchy, abstracts the hierarchy that needs to be processed into different entities, and defines the relationship between the entities and the data processing flow.

As ———— can see, the Linux kernel network subsystem defines 4 entities:

? Network protocol

The network protocol can be understood as a language, which is used for communication between different devices in the network, and is a specification of communication.

? sockets

Sockets are the interface between the kernel and the user program, a socket corresponds to a data connection, and the user is provided with file I/O, the user can send and receive data in the same way as the files on the data connection, the specific protocol processing by the network protocol part processing. Sockets are the interfaces that the user uses for the network.

? Device interface

The device interface is the interface of the software and hardware in the network subsystem, the user's data will be sent and received through the network hardware device, the network equipment is different, the device drive is not the same, and the device interface can shield the difference of the specific device drive.

? Network buffers

A network buffer, also known as a socket buffer (Sk_buff), is an important structure in the network subsystem. There are many uncertain factors in network transmission data, in addition to the limitations of physical equipment on transmission data (such as MMU), network interference, packet loss, retransmission, etc., will cause data instability, network buffer through the network data rearrangement, so that the business processing of the packet is complete. A network buffer is a buffer in memory, which is the interface between network system and memory management.

G:arch

———— the Linux kernel supports many architectures, the kernel puts device-independent code in the Arch directory, and the corresponding header file is placed in the include/asm-< system name > directory. This partitioning code is structurally clear and improves the code reuse rate. In the arch directory, each subdirectory corresponds to an architecture that stores the code for this architecture, and if the code is more likely to create a separate directory, such as the Arch/arm directory, there is a kernel directory, stored in the kernel directory in the ARM architecture specific functions or implementation method, the Arch/i386 directory holds the Intel X86 Architecture code, not only kernel directory, but also a number of directories, such as the MM directory contains the x86 system memory management implementation method , Math-emu contains the implementation of the x86 system floating point simulation. When reading kernel code, readers can start with an architectural code, and the main work of porting code to different architectures is the code inside the arch.

The composition of the Linux system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.