MTU of computer network those things

Hello everyone, I am Xianyu

Today let's talk about MTU (Maximum Transmission Unit) in computer networks

What is MTU?

MTU (Maximum Transmission Unit) refers to the maximum transmission unit in the data link layer

In layman's terms, MTU refers to the size of the largest data frame that can be transmitted by the data link layer (in bytes).
insert image description here
Taking CentOS 7 as an example, you can ifconfigview the MTU value through the command
insert image description here

Why is MTU needed?

We know that data is usually transmitted in the form of data frames (Frame) in the data link layer

Because the transmitted Frame cannot be infinitely large (small ones can be transmitted), so the most suitable and efficient way to transmit a large Frame at a time becomes a problem that needs to be considered

So we need to set a value (that is, MTU), which is used to limit the size of the Frame

Wikipedia has this passage

Larger MTU is associated with reduced overhead. Smaller MTU values can reduce network delay.

From the above it can be concluded that:

  • The larger the MTU, the smaller the overhead

This sentence is easy to understand, a larger Frame means more valid data contained

I can transfer more data at a time, so the number of transfers is less, and the overhead on the network becomes smaller

  • Smaller MTU values ​​can reduce network latency

This sentence is easy to cause confusion. Why can a small MTU value reduce network delay?

If the MTU is set to a large value, it means that more data can be transmitted at one time, and the time to occupy the link will be longer, so the overall network delay will become larger

And if there is a bit error in a large section of data, this large section will be retransmitted entirely, and the cost of retransmission is very high

So what is the appropriate MTU setting?

Why is the MTU value 1500?

The RFC standard defines the default MTU value of Ethernet as 1500, why is it 1500?

This is a historical legacy

The early Ethernet used the working method of shared links. In order to ensure the CSMA/CD (carrier multiplexing/collision detection) mechanism, the minimum length of the Ethernet frame was 64 bytes and the maximum was 1518 bytes.

  • The minimum 64 bytes is to ensure that the most extreme collisions can be detected, and 64 bytes is the minimum value that can be detected
  • The maximum limit is 1518 bytes in order to prevent too long frame transmission time from occupying the shared link for too long and causing other services to be blocked

So the maximum length of a data frame is limited to 1518 bytes (including frame header, frame trailer and CRC check),
insert image description here
18 bytes are used for frame header and frame trailer, of which CRC check occupies 4 bytes, and the remaining 1500 words Section is the maximum data load (Payload)

Therefore, 1500 bytes is defined as the maximum length (MTU) of the data portion in an Ethernet frame

While technology has evolved, this rule has not changed

After decades of development, the speed of Ethernet has been increased from the initial 10M to hundreds of G, and the speed has increased by tens of thousands of times.

In such a high-speed transmission of data, if the maximum frame length of the classic Ethernet does not exceed the limit of 1518 bytes, the number of data packets transmitted per second will be very large

So some manufacturers proposed the concept of Jumbo Frame, which extended the maximum frame length of Ethernet to 9K

It has not yet been approved by the IEEE standards committee, but most equipment manufacturers have begun to support it

What should I do if the size of the sent data exceeds the MTU?

The default value of Ethernet's MTU is 1500, if the sending frame is smaller than MTU (for example, 1000 bytes), just transmit it directly

If it is larger than MTU (payload is 4000 bytes), fragmentation (Fragment) is required

That is, send 1500 bytes for the first time (IP header 20 bytes + Payload 1480 bytes)

Send 1500 bytes for the second time (IP header 20 bytes + Payload 1480 bytes)

The third time is 1060 bytes (IP header 20 bytes + Payload 1040 bytes))

insert image description here

Some friends may ask, what should I do if the size of the data I transmit is not enough for the minimum 64 bytes specified by the data frame?

The answer is: add padding data after the actual data content, so that the total length of the data packet reaches the minimum length requirement. Padding data can be any meaningless bytes, such as all 0 or all 1 data

How to ensure that the data sent does not exceed the MTU?

We know earlier that if the data sent is larger than the MTU, fragmentation will be performed

To make the size of the Frame data finally passed to the data link layer not exceed 1500 bytes, it is necessary to ensure that the data of each layer in the upper layer does not exceed this size

If the MTU is 1500, then the IP layer must ensure that the Packet data of the IP layer does not exceed 1480 bytes (1500 bytes – 20 bytes IP header),

For TCP, it must ensure that the data size of each segment does not exceed 1460 bytes (1460 bytes – 20 TCP header)

Taking the TCP layer (transport layer) as an example, how does the TCP layer know that the data sent will not exceed the MTU?

  1. IP layer (network layer) asks what is the maximum data transmission unit (MTU) of the data link layer
  2. The TCP layer will ask the IP layer what is the maximum data transmission size (Maximum packet size)

In this way, the TCP layer will know its maximum transmission data size, called MSS (Maximum segment size)

In the handshake phase of TCP, MSS (Maximum Segment Size) is used to specify the maximum length of the data part in the TCP segment

For TCP, knowing your own MSS is useless

For example, as a receiver, the size of the received packet depends on the sender, and the sender must know its own MSS.

Therefore, when establishing a TCP connection, both parties need to negotiate an appropriate MSS value for fragmentation and reassembly during data transmission.

What is TSO

Earlier we introduced what is MTU, MSS

If you go to grab the packets, you may encounter the following situation.
insert image description here
The MSS is clearly negotiated to be 1460 bytes, why the data is more than 10,000 bytes?

When establishing a TCP connection, both parties need to negotiate an appropriate MSS value for fragmentation during data transmission

However, this fragmentation process is often simple and repetitive and requires a relatively large amount of calculation, which requires more CPU resources.

So the network card will say to the kernel: Brother, I will do such trivial things, and I don’t need to trouble you.

Then the kernel will send the large packet to the network card, and the network card will be responsible for fragmentation

This is called TSO (TCP Segment Offload)

TSO (TCP Segmentation Offload) is a network transmission offloading technology, which is used to reduce the burden of network packet segmentation on the host and improve network transmission performance

When we capture the packet, we can see that the packet is still in the kernel, and the process of unpacking the network card later cannot be seen.

The network card can not only offload the sent packets, but also onload the received packets. Simply put, the network card will first accumulate some small packets, and then send them together to the kernel

# 查看网卡上面是否开启 TSO 功能
# on 表示开启
[root@root~]# ethtool -k <网卡名称>
tcp-segmentation-offload: on
        tx-tcp-segmentation: on
        tx-tcp-ecn-segmentation: on
        tx-tcp6-segmentation: on
        tx-tcp-mangleid-segmentation: off

Finally, to summarize:

insert image description here

  • MTU refers to the size (in bytes) of the largest data frame that the data link layer can transmit. Due to historical reasons, the minimum value of MTU is 64 bytes and the maximum is 1518 bytes (Payload is 46~1500 bytes)
  • If the sent data is larger than the MTU, the fragmentation operation will be performed; if it is smaller than the MTU, padding data will be added after the actual data content, so that the total length of the data packet reaches the minimum length requirement
  • MSS (Maximum Segment Size) is used to specify the maximum length of the data part in the TCP segment. When establishing a TCP connection, both parties need to negotiate an appropriate MSS value for fragmentation and reassembly during data transmission
  • TSO (TCP Segmentation Offload) is a network transmission offload technology. TSO technology moves the fragmentation process from the CPU to dedicated hardware on the network card, which is responsible for segmenting the application's large chunks of data into appropriately sized packets, adding TCP headers, and sending them directly to the network

Supongo que te gusta

Origin blog.csdn.net/s_alted/article/details/131423524
Recomendado
Clasificación