--- linux system Linux system composed of seven major subsystems

         <Linux system seven sub>

a:SCI(system call interface)

---- user program by the software interrupts , system calls the function provided by the kernel, this interface between the service user and kernel space provided is called a system call. System call is Linux kernel, user space can not directly use the system call. Call must boundaries across applications and kernel in the user process using the system.

 

---- Linux kernel provides a unified system call interface to the user, but the system calls the method varies on different processors. Linux kernel provides a number of system calls, a method to explore the Linux system calls now from the basic principles of system calls. When loading the index and parameters of the system C library calls, it calls 0x80 software interrupt, it will execute system_call function, which in accordance with the contents of the EAX register marked handles all system calls. After testing several units, uses the contents of the EAX register to search the index table to obtain system_call_table inlet system calls, then the system call is executed. After the return from the system call, eventually calling the kernel function system_exit, and calls resume_userspace function returns the user space.

 

b:pm(process management)

---- linux kernel through process management subsystem to achieve the relevant operational processes, on linux system, all calculations are expressed through a process, the process can be short term (execute a command), it can be a long-term (a network service). linux system is a dynamic system, through process management can adapt to changing computing needs. 

 

---- in user space, the process is the process identifier (PID) represented. From the user's perspective, a PID is a numeric value, which uniquely identifies a process, a PID value does not change throughout the life cycle of the process, but PID can be re-used after the destruction process. Create a process can be used in several ways, you can create a new process, you can create a child process of the current process.

 

---- Linux kernel space, each process has an independent data structure used to store the process ID, the priority information, the address space, this structure is also called a process control block (Process Control Block) . The so-called process management is the management of the process control block

PM(process management)

 

---- linux process through fork () system call function generated. Calls fork () process is called the parent process, the resulting process is called the child process. When the child process is created, in addition to the process ID, and other data structures consistent parent process. Debugging fork () system after a call to create a memory, the child was immediately added to the kernel process queue, and then use the exec () system call, the program's code is added to the child process's address space, after the child began to execute their own code .

     

---- you can have multiple processes on a single system, but under normal circumstances there is only one CPU, at the same time, only one process at work, even if there are multiple CPU, the same number of impossible and processes. If you let a number of processes can work on the CPU, this is the work process management subsystem. linux kernel process queue designed storage structure, there will be a plurality of queues in the system, they are stored in the different states of the process. A process can have several states, particularly defined by the operating system, but the operating mode comprises at least the ready state and wait three states, the core design process storage queue corresponding to a state corresponding to the control block.

 

---- When a user process is loaded, it will enter the ready state, the ready state is added to the queue, the CPU time is rotated to queue the ready state, transitions to process code, a process is performed, when the time slice to process after being swapped out. If the I / O operation will be occurred in the process is swapped out in advance, and stored in the queue, when the I / O request is returned, the process has been placed in the ready queue. linux process queue management system for the design of a number of different ways, the main purpose is to improve the stability of the process of debugging.

 

c:MM(memery management)

---- Computer memory is an important resource, but also an important part of the kernel. The computer uses virtual memory technology, memory management hardware memory management in accordance with pagination. Pagination is the physical memory of a computer system in accordance with the same size aliquot, each memory slice called memory page, the memory page size is typically 4KB. Linux kernel memory management subsystem manages the mapping between virtual memory and physical memory, and the system's available memory space.     

 

---- Memory Management to manage not only 4KB buffer. Linux provides an abstraction of 4KB buffers, such as slab allocator. This mode uses 4KB buffer memory management as the base, and then from the distribution structure, and track usage of memory pages, such as which pages are full of memory, which is not fully use the page, which page is blank. This allows the model needs to be adjusted dynamically according to system memory usage.     

 

---- support multiple users on the system, due to the increased memory footprint, easy situation to be depleted of physical memory appears. In order to solve the problem of physical memory is exhausted, the memory management subsystem specified page can be removed and placed in memory disk, a process called exchange. Memory management source code can be found in the ./linux/mm 

 

d:DD(device driver)

---- With the increasing modern computer external equipment, up more and more devices are developed, the development of computer bus is also very fast, operating system functions is also rising, more and more complex software system for external devices access can not directly access the hardware device that's like DOS, and almost all the devices require device drivers. Modern operating systems almost always provides a device driver interface specific hardware-independent, so that the benefits are shielded operational details of the specific device, the interface provided by the user through the operating system can access the device, and the operating details of the specific equipment to complete by the device driver, driver developers only need to provide the appropriate interfaces to the operating system.     

 

---- the device with other operating systems different complex classification, linux kernel the apparatus into three categories: block, character and network devices. This is an abstract classification, characteristics of the device from three different abstract data reading and writing.    

❶ block device     

Is a conceptual block device I / O operations can operate a plurality of bytes of data, data read and write buffer, when the buffer is full only after the reading and writing of data transfer, such as a hard disk sector data can be read once, at the same time, block device support random read and write operations, can read and write data from the specified location;    

❷ character device     

Character device access mode is linear, and can access on byte manner, such as serial devices, can read and write data in accordance with the character, but only in accordance with the order of operations, specify an address can not access;    

❸ network equipment     

Network device compared with the previous two methods, special, dedicated to such core division driving out of a separate network device may read and write data through the socket. 

 

---- apparatus according to the Linux kernel number and access from the master device number of methods, major number of the driver control device is described, to distinguish the same from device number of different device driver program. That is, the major number and the corresponding device driver, representative of a type of device, device number and corresponding to the particular equipment, on behalf of the same type of device number. As used IDE hard disk interface, two major number are the same, but different from the device number. Linux provides mknod command to create a device driver description file. This Linux kernel from the primary classification device number can be well managed device.         

 

---- user process accessing an external device is performed by device-independent software, device-independent software is the kernel of a variety of software abstraction layer such as VFS. When the user data request to initiate an external device, via the device-independent software will be a corresponding driver calls the device driver to access external hardware devices via bus or register to initiate the request, the driver to the system interrupt during initialization vector table Register an interrupt handler, when the request to return the external hardware interrupt handler will issue an interrupt signal in response to the kernel will invoke the interrupt handler reads the data returned from the hardware registers, and then transferred to the device in kernel service by equipment service program data to the device-independent software, and finally to the user process.    

 

---- Linux device driver process relates to other subsystems, such as memory management, interrupt management, hardware registers, and bus access, etc. In addition, most of the drivers is designed for ease of use as a module, but also to the design of the kernel module .    

 

---- driven to write and debug a complex matter, driven code takes up more than half the amount of linux kernel code.

 

e:VFS(virtual file system)

---- partition on a file in different formats, the program can correctly read and write files, and the result is the same. Sometimes when using linux system found, you can copy files directly in different types of files partition for the application, does not know the type of file system, you do not even know the type of file, which is done behind the virtual file system work. The virtual file system shields the differences between different file systems, provides a unified interface to the user. 

 

---- virtual file system that VFSVirtual File System) is a Linux kernel software abstraction layer. It provides an interface to the actual file system mechanisms such as ext2, vfat data structures and the like methods. By using the same calling a file I / O system can be on any file in the Linux operating without regard to respond to the specific file system format; Still further, operations may be performed between files of different file systems.       

 

---- In linux system, everything can be seen as a file. Not only plain text files, directories can be treated as a file, and character devices, block devices, and so can be used as a socket file for processing. Although these file types, but use the same method of operation. This is the UNIX / Linux one of the basic design philosophy.    

 

---- virtual file system (VFS) is the key to achieve "everything is a file" feature, is a software layer of the Linux kernel, file system interface to provide a user-space program; at the same time provides an abstraction function kernel , exist that allow different types of file systems. VFS can be understood as an abstract interface standard, the system all file systems not only rely on VFS coexistence, but also rely on VFS work together.     

 

---- In order to be able to support different file systems, VFS defines all file systems are supported, interfaces and data structures on a basic concept, in achieving a specific file system when the need to provide to meet the VFS VFS standard interfaces and data structures, different file systems may have on the physical concept of difference, but use the concept of need and VFS defined when the VFS interface remains the same, the only way to achieve the user's file system independence. VFS hides the details of the specific operating system file, so in other parts of this layer and kernel VFS view, all file systems are the same. 

 

f:Network Stack

---- writing network applications that use socket via TCP / IP communication protocol similar to the other machine, and kernel subsystems described earlier, socket-related function is completed by the kernel subsystem, which served as part of the task is the kernel the network subsystem, and sometimes this part of the code called "network stack."     

 

---- Linux kernel provides excellent network performance and functionality, this network stack design codes are inseparable, Linux network stack part followed the traditional hierarchical structure, the actual network data arrives from the user process network equipment needed four levels.       

 

---- Indeed, in which each path can also be divided into a lot of levels, the data is transmitted by hierarchy, and can not exceed a certain level.     

 

---- Linux network subsystem of the network using hierarchical object oriented design similar idea, the level of abstraction to deal with different entities, and defines the relationship between the entities and the data processing flow. 

 

---- As can be seen, linux kernel network subsystem defines four entities:    

❶ network protocol     

Network protocol can be understood as a language for communication between different network devices, it is a specification of a communication.    

❷ socket     

Is an interface socket kernel and user program, a data corresponding to a socket connector, and provides the user with file I / O, the user may operate like file send and receive data over the data connection, the protocol processing by the network specific protocols part of the process. Sockets are user-network interface.    

❸ Device Interface     

Is a network device interface subsystem of software and hardware interfaces, user data ultimately required by sending and receiving network hardware, network device vary, the device driver are not the same, the device interface shielded by the device driver specific differences.    

❹ network buffer     

Buffer also known as network socket buffer (sk_buff), it is an important structure of the network subsystem. The presence of many uncertainties network traffic, in addition to the physical limitations of the data transmission device (e.g. the MMU), network interference, packet loss, retransmission, can cause instability in the data network by rearranging buffer network data, the business process of the packet is complete. Network buffer is a buffer memory, and the memory system is a network management interface.

 

g:Arch

---- Linux kernel supports many architectures, the kernel and device-independent code in arch directory, the corresponding header file in the include / asm- <system name> directory. Such clear division code structure, while increasing the rate of code reuse. Directory in the arch, an architecture corresponding to each subdirectory, this configuration storage system corresponding to the code, if the code creates a more separate directory, for example arch / arm directory, there is a kernel directory, it is stored in kernel directory unique to the arm in function or implementation architecture; in arch / i386 directory code stored Intel x86 architecture, not only the kernel directory, but also a plurality of directories, for example, on the x86 mm directory contains memory management system implementation, math-emu realization contains the x86 floating point simulation system. Readers can start from one architecture code reading kernel code when the main work of the different structure of the code transplant system is the arch inside the code. 

Guess you like

Origin blog.csdn.net/u012308586/article/details/95318422