Home > System Tutorial > LINUX > body text

Subvert your understanding of operating systems - an overview of Linux distributions

王林
Release: 2024-02-13 21:15:02
forward
529 people have browsed it

Whether you are a senior programmer or a beginner, whether you are a Windows or macOS user, if you have a certain understanding of computer operating systems, then the name Linux will definitely be familiar to you. However, you may only scratch the surface of the Linux operating system. In fact, there are many Linux distributions, each with unique features and application scenarios. Below, we will introduce you to several common Linux distributions and help you subvert the traditional understanding of operating systems.

In order to enable multiple devices to communicate with each other through the network, and to solve the compatibility issues of various devices in network interconnection, the International Standardization Organization has formulated the open system interconnection reference model (open System Interconnection Reference Model) , which is the OSI network model. This model mainly has 7 layers, namely application layer, presentation layer, session layer, transport layer, network layer, data link layer and physical layer.

Subvert your understanding of operating systems - an overview of Linux distributions
Each layer is responsible for different functions, as follows:

•Application layer is responsible for providing a unified interface to applications;

•The presentation layer is responsible for converting data into a format that is compatible with another system;

•Session layer, responsible for establishing, managing and terminating communication sessions between presentation layer entities;

•Transport layer, responsible for end-to-end data transmission;

•Network layer, responsible for data routing, forwarding, and fragmentation;

•Data link layer, responsible for data framing and error detection, as well as MAC addressing;

•Physical layer, responsible for transmitting data frames in the physical network;

Because the OSI model is too complex, what is proposed is only a conceptual and theoretical layering, and no specific implementation plan is provided. In fact, the four-layer model, which is more common and practical, is the TCP/IP network model. The Linux system implements the network protocol stack according to this network model.

The TCP/IP network model has 4 layers, namely application layer, transport layer, network layer and network interface layer. The functions of each layer are as follows:

•Application layer, responsible for providing users with a set of applications, such as HTTP, DNS, FTP, etc.;

•Transport layer, responsible for end-to-end communication, such as TCP, UDP, etc.;

•Network layer, responsible for encapsulation, fragmentation, routing, and forwarding of network packets, such as IP, ICMP, etc.;

•Network interface layer, responsible for the transmission of network packets in the physical network, such as network packet framing, MAC addressing, error detection, and transmission of network frames through the network card, etc.;

Compared with the OSI network model, the TCP/IP network model is much simpler and easier to remember. The relationship between them is as follows:

Subvert your understanding of operating systems - an overview of Linux distributions
However, the seven-layer and four-layer load balancing we often talk about are described by the OSI network model. Layer seven corresponds to the application layer, and layer four corresponds to the transport layer.

Linux Network Protocol Stack

We can compare our body to the data in the application layer, the base clothes to the TCP header in the transport layer, the coat to the IP header in the network layer, and the hat and shoes to the frame headers in the network interface layer. and the end of the frame.

In the winter season, when we want to go out to play from home, we naturally have to put on base clothes first, then put on a warm jacket, and finally put on a hat and shoes before going out. This process is like when we put on the TCP protocol When the communication network packet is sent out, the application layer data will be encapsulated and processed layer by layer according to the network protocol stack.

You can see from the picture below the encapsulation format of application layer data at each layer.

Subvert your understanding of operating systems - an overview of Linux distributions
in:

•Transport layer adds a TCP header in front of the application data;

•Network layer, adds IP header in front of TCP packet;

•The network interface layer adds a frame header and a frame trailer before and after the IP packet;

These new additions, headers and tails all have their own functions, and are filled in according to a specific protocol format. Each layer adds its own protocol header, which naturally increases the size of the network packet. , but the physical link cannot transmit data packets of any size, so in Ethernet, the maximum transmission unit (MTU) is stipulated to be 1500 bytes, which also specifies the maximum IP packet size for a single transmission.

When the network packet exceeds the MTU size, it will be fragmented at the network layer to ensure that the fragmented IP packet will not exceed the MTU size. If the MTU is smaller, more packets are needed, so the network throughput capacity On the contrary, if the MTU is larger, the smaller the packets required, the better the network throughput will be.

After knowing the TCP/IP network model and the encapsulation principle of network packets, you must have guessed what the Linux network protocol stack looks like. It is actually similar to the four-layer structure of TCP/IP:

Subvert your understanding of operating systems - an overview of Linux distributions
From the network protocol stack in the picture above, you can see:

•The application needs to interact with the Socket layer through system calls;

•Below the Socket layer are the transport layer, network layer and network interface layer;

•The bottom layer is the network card driver and hardware network card device;

Linux process of receiving network packets

The network card is a piece of hardware in the computer that is responsible for receiving and sending network packets. When the network card receives a network packet, it will put the network packet into the Ring Buffer through DMA technology. This is a ring buffer. The buffer is in the network card driver in kernel memory.

After receiving the network packet, how should we tell the operating system that the network packet has arrived?

The simplest way is to trigger an interrupt, that is, every time the network card receives a network packet, it triggers an interrupt to tell the operating system.

However, there is a problem. In a high-performance network scenario, the number of network packets will be very large, and a large number of interrupts will be triggered. You must know that when the CPU receives an interrupt, it will stop what it is doing. To process these network packets, only after the processing is completed, will they go back to continue other things. Triggering interrupts so frequently will cause the CPU to have endless processing interrupts, and other tasks may not be able to move forward, thus affecting the system. Overall efficiency.

So in order to solve the performance overhead caused by frequent interrupts, the Linux kernel introduced the NAPI mechanism in version 2.6, which mixes "interrupts and polling" to receive network packets. Its core concept is not to use interrupts. method to read data, but first use the interrupt to wake up the service program for data reception, and then use the poll method to poll the data.

For example, when a network packet arrives, the network card initiates a hardware interrupt, and then the network card hardware interrupt processing function is executed. After the interrupt processing function is processed, it is necessary to "temporarily mask the interrupt", and then wake up the "soft interrupt" to poll and process the data. The interruption is not resumed until there is no new data. In this way, one interruption processes multiple network packets, thus reducing the performance overhead caused by the network card interruption.

How does soft interrupt handle network packets? It will copy the data from the Ring Buffer to the kernel struct sk_buff buffer, so that it can be handed over to the network protocol stack as a network packet for layer-by-layer processing.

First, it will enter the network interface layer. At this layer, the legality of the packet will be checked. If it is illegal, it will be discarded. If it is legal, the type of the upper layer protocol of the network packet will be found, such as IPv4 or IPv6. , then remove the frame header and frame trailer, and then hand it over to the network layer.

At the network layer, take out the IP packet and determine the next direction of the network packet, such as whether to hand it over to the upper layer for processing or forward it. When it is confirmed that the network packet is to be sent to the local machine, it will look at the IP header to see whether the type of the upper layer protocol is TCP or UDP, then remove the IP header, and then hand it to the transport layer.

The transport layer takes out the TCP header or UDP header, uses the four-tuple "source IP, source port, destination IP, destination port" as an identifier to find the corresponding Socket, and copies the data to the Socket's receive buffer.

Finally, the application layer program calls the Socket interface to read the newly arrived data from the kernel's Socket receiving buffer to the application layer.

At this point, the receiving process of a network packet has ended. You can also see the process of receiving network packets from the left part of the figure below. The right part is just the opposite, which is the process of sending network packets.

Subvert your understanding of operating systems - an overview of Linux distributions

Linux process of sending network packets

As shown in half of the picture above, the process of sending network packets is exactly opposite to the receiving process.

First, the application will call the interface of Socket to send data packets. Since this is a system call, it will fall from the user mode to the Socket layer in the kernel mode. The Socket layer will copy the application layer data to the Socket sending buffer. .

Next, the network protocol stack takes out the data packet from the Socket send buffer and processes it layer by layer from top to bottom according to the TCP/IP protocol stack.

If the TCP transmission protocol is used to send data, the TCP header will be added to the transport layer and then handed over to the network layer. The network layer will add an IP packet to the data packet, and then confirm the next hop IP by querying the routing table. And fragmented according to MTU size.

The fragmented network packet will be sent to the network interface layer, where the MAC address of the next hop will be obtained through the ARP protocol, and then the frame header and frame trailer will be added and placed in the packet sending queue.

After these are prepared, a soft interrupt will be triggered to tell the network card driver that there are new network packets that need to be sent. Finally, the driver reads the network packets from the packet sending queue through DMA and puts them into the hardware network card. queue, and then the physical network card sends it out.

Summarize

Computers are usually connected together by network devices such as communication network cards, switches, routers, etc. Due to the heterogeneity of network devices, the International Organization for Standardization has defined a seven-layer OSI network model. However, this model has It is relatively complicated and is not used in actual applications. Instead, a more simplified TCP/IP model is used. The Linux network protocol stack is implemented according to this model.

The TCP/IP model is mainly divided into four layers: application layer, transport layer, network layer, and network interface layer. Each layer has different responsibilities. This is also the main component of the Linux network protocol stack.

When the application sends a data packet through the Socket interface, the data packet will be processed layer by layer from top to bottom by the network protocol stack before being sent to the network card queue, and then the network card will send the network packet out.

When receiving a network packet, it must also be processed layer by layer from bottom to top of the network protocol stack before it is finally sent to the application program.

In short, Linux, as a free and open source operating system, has emerged in the field of technology and has been widely used. Whether you are an experienced programmer or an ordinary user, choosing a Linux distribution that suits you can really bring many unexpected benefits. I believe this article can help you better understand the Linux distribution, and I hope you can experience the charm of Linux on your own computer.

The above is the detailed content of Subvert your understanding of operating systems - an overview of Linux distributions. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!