In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the architecture and network layering of Linux system". In the daily operation, I believe many people have doubts about the architecture and network layering of Linux system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "Linux system architecture and network layering". Next, please follow the editor to study!
Linux kernel architecture diagram
The above picture is the architecture diagram of the Linux kernel, from the hardware layer-- > operating system kernel-> application layer, the design of this system architecture is applied to all kinds of software and hardware systems, such as Internet of things system, single-chip microcomputer system, robot and other fields.
Process scheduling
A process is called process or task in Linux systems. The data structure of processes in the operating system contains many elements, such as address space, process priority, process status, semaphores, occupied files, etc., which are often linked by linked lists.
When each system Tick interrupt occurs, CPU checks the processes in the ready queue (traversing the process structure in the linked list). If there is a new process that meets the scheduling algorithm, it needs to switch, save the information of the currently running process (including stack, address, etc.), suspend the current process, and then run the new process, this is process scheduling.
CPU scheduling is based on the priority of the process. The ultimate goal of scheduling is to enable high-priority processes to get CPU resources in time, and low-priority tasks can be fairly allocated to CPU resources. However, because the information of the current process is saved, the switching of the process itself has a cost, and the scheduling algorithm also needs to consider efficiency.
In the early Linux kernel, the polling algorithm was adopted. The kernel chose the high priority processes in the ready process queue to execute for equal time each time. The algorithm is simple and intuitive, but it will still cause some low priority processes to be unable to execute for a long time. In order to improve the fairness of scheduling, the CFS scheduler algorithm was introduced into the Linux kernel.
CFS introduces the concept of virtual run time, which is represented by task_struct- > se.vruntime, which is used to record and measure the CPU run time that the process should get. In an ideal scheduling situation, all processes should have the same task_struct- > se.vruntime value at any time. Because each process is executed concurrently, no process will exceed the CPU time it would ideally take. CFS's logic for selecting processes to run is based on the task_struct- > se.vruntie value, and it always chooses the process with the lowest task_struct- > se.vruntie value to run (for fairness).
CFS uses a red-black tree based on time sorting to provide an execution timeline for future processes. All processes are sorted by the task_struct- > se.vruntime keyword. CFS selects the leftmost task from the tree to execute. As the system runs, the executed processes are placed on the right side of the tree, gradually giving each task the opportunity to become the leftmost process, thus allowing each process to get CPU resources.
Generally speaking, the CFS algorithm first selects a process, and when the process switches, the CPU time used by the process will be added to the process task_struct- > se.vruntime. When the value of task_struct- > se.vruntime gradually increases to the leftmost process of the red-black tree, the leftmost process is selected for execution and the current process is preempted.
Memory management
Memory, a hardware device that is addressed by the operating system, finds the corresponding memory unit, and then operates on it. The byte length of CPU determines the maximum addressable space. The maximum addressable space for 32-bit machines is 4G Bytes,64-bit machines. The maximum addressing space for machines is 2 ^ 64 Bytes.
The maximum address space is independent of physical memory size and is called virtual address space. The Linux kernel divides the virtual address space into kernel space and user space. The virtual address space range for each user process is 0~TASK_SIZE. The area from TASK_SIZE~ 2 ^ 32 or 2 ^ 64 is reserved for the kernel and cannot be accessed by user processes.
Mapping between virtual address space and physical memory
In most cases, the virtual address space is larger than the actual physical memory, and the operating system needs to consider how to map the actual available physical memory to the virtual address space.
The Linux kernel uses page tables (page table) to map virtual addresses to physical addresses. The virtual address is related to the kernel address of the user used by the process, and the physical address is used to address the memory actually used.
Sample diagram
As shown in the figure above, the virtual address space of the An and B processes is divided into equal parts of equal size, called page. Physical memory is also split into pages of equal size (page frame).
The first memory page of process A maps to page 4 of physical memory (RAM), and the first memory page of process B maps to page 5 of physical memory. The fifth memory page of process An and the first memory page of process B are mapped to page 5 of physical memory (the kernel can determine which memory space is shared by different processes). The page table maps virtual address space to physical address space.
File system
The core idea of Linux: everything is file. There are many file systems in Linux system, such as EXT2,EXT3,EXT4,rootfs,proc and so on. Each file system is independent and has its own organization and operation methods.
To support different file systems, the kernel includes a layer of virtual file system (Virtual File System) between the user mode and the file system. Most functions provided by the kernel can be accessed through interfaces defined by VFS. For example, kernel subsystems: character devices, block devices, pipes, socket, etc. In addition, the files used to manipulate character and block devices are real files in the / dev directory, which are created by the corresponding driver when read and write operations are performed.
VFS structure diagram
Four virtual file system objects of Linux:
1. Super block (Super Block)
2. Inode (node)
3. Dentry (directory)
4. Block (specific data blocks)
Super block
Represents a specific mounted file system, including the type, size, status, and so on.
Inode
Represents a specific file, in Linux file management, a file in addition to its own data, there is a subsidiary information, that is, the file metadata (metadata), this metadata is used to record a lot of information about the file, such as file size, creator, creation time, etc., this metadata is included in the inode.
Inode is the key to documents from abstract-> concrete. Inode stores pointers to blocks of data on the storage device in which the contents of the file are stored. When Linux wants to open a file, all it needs to do is to find the inode corresponding to the file, and then save all the data blocks along the pointer to form the data of a file in memory.
Inode structure
Inode is not the only way to organize files, the simplest way to organize files is to put files into storage devices sequentially, but if there is a delete operation, the free space caused by deletion is interspersed between normal files, so it is difficult to use and manage them. Complex methods can be used to do linked lists, each data block has a pointer to the next data block belonging to the same file, the advantage is that you can take advantage of scattered free space, the disadvantage is that the operation on the file must be carried out in a linear manner, if randomly read, you must traverse the linked list to the target location. Because this traversal is not carried out in memory, it is very slow.
Inode can make full use of the space, and the memory space is not related to the storage device, which solves the above problem. But inode has its own problems. The total number of block pointers that each inode can store is fixed. If a file needs more data blocks than this total, inode needs extra space to store the extra pointers.
Dentry
Represents a directory item that is part of a path, such as a path / home/jackycao/hello.txt, then the directory entry has home, jackycao, hello.txt.
Block
Represents specific data, a file consists of scattered multiple block, organized by the inode to point to.
Device driver
To put it bluntly, the interaction with peripherals is the operation of input (input), operation (operate) and output (ouput).
The kernel needs to accomplish three things:
1. Implement different methods to address hardware for different device types.
two。 User space must be provided with ways to operate different hardware devices, and a unified mechanism is needed to ensure that programming is as limited as possible.
3. Let user space know which devices are in the kernel.
Equipment communication diagram
There are two main ways for the kernel to access peripherals: the Imax O port and the Imax O memory mapping. Let's not introduce it in detail.
The kernel dynamically receives requests (data) from peripherals in two ways: polling and interrupts.
Polling: periodic access to query whether the device has data, and if so, get the data. This method is a waste of CPU resources.
Interrupt: the core idea is to actively notify CPU when there is an external request, the interrupt has the highest priority, and will interrupt the current process of CPU, each CPU provides an interrupt line, each interrupt is identified by a unique interrupt number, and the kernel provides an interrupt handling method for the interrupt of each application. When data is ready for use by the kernel or indirectly by an application, the peripheral initiates an interrupt. The use of interrupts ensures that the system notifies CPU only when the peripheral needs processor intervention, which improves efficiency.
PS: the concept of blocks and sectors: a block is a sequence of bytes of a specified size that is used to hold data transferred between the kernel and devices. The size of the block can be set. The default is 4096 bytes. The sector is the minimum unit for storage device operation. The default is 512 Bytes, and the block is a continuous sector.
The network
The model of Linux's network subsystem is based on ISO's OSI model, and the corresponding levels are simplified in the Linux kernel. The following figure shows the TCP/IP reference model used by Linux.
Network model
Host-to-Host layer: the physical layer and data link layer of the OSI model, responsible for transferring data from one computer to another. From the point of view of the Linux kernel, this layer is implemented through the device driver of the network card.
Internet layer: the network layer equivalent to the OSI model, which is responsible for allowing computers in the network to exchange data (these computers are not necessarily directly connected). At the same time, the packets responsible for transmission in this layer are divided into specified sizes, because the maximum network packets supported by each computer are different in the transmission path, and the data is divided into different packets during transmission and reassembled at the receiving end. This layer assigns unique network addresses to computers in the network.
Transport layer: the transport layer equivalent to the OSI model, responsible for the transfer of data between applications running on two connected computers. For example, the client and server programs on two computers identify the communicating application by the port number.
App layer: equivalent to the session layer, presentation layer, and application layer of the OSI model. After two applications of different computers in the network establish a connection, this layer is responsible for the transmission of the actual content.
The implementation of Linux kernel subsystem is realized by C code, and each layer can only communicate with its upper and lower layers.
Linux network layering diagram
At this point, the study on "Linux system architecture and network layering" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.