如何确定和分配分配给要发送的数据包skb的空间量? [英] How exactly is the amount of space allocated to a to-be-transmitted packet skb determined and allocated?

查看:155
本文介绍了如何确定和分配分配给要发送的数据包skb的空间量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,当内核堆栈(在Tx路径上)分配套接字缓冲区(skb)时,"head"和"tail"指针指向开始&保留的内存空间的末尾.

From what I understand, when a socket buffer (skb) is allocated by the kernel stack (on Tx path), the 'head' and 'tail' pointers point to the start & end of reserved memory space.

我的qs是:到底是什么确定了这个数量:(尾-头)八位位组? 它是最大MTU吗?似乎一点也不喜欢,因为一点实验表明字节数(尾部头)可能很小(320字节,等等).那么在这里发挥作用的是套接字应用程序吗?

My qs is: what exactly determines this amount: (tail - head) octets? Is it max MTU? Doesn't seem like it as a little experimentation shows that the # of bytes (tail-head) can be quite small (320 bytes, etc). So is it the socket app that plays a role here?

此外,AFIAK的想法是保留足够的内存,以便在协议栈的下方不再需要更多的分配,即,保留的空间可以大于有效负载.如果是这样,那么进一步封装(例如VoIP,SSL等)的情况又如何呢?

Also, AFAIK, the idea is to reserve enough memory such that no further allocs are required further down the protocol stack, i.e., reserved space can be more than the payload. If so, what about cases where further encapsulation is done (like VoIP, SSL, etc?)?

更新: 这有助于回答问题吗?

Update: Does this help answer the qs?

  1. 在net/ipv4/tcp_output.c中找到:

  1. Found in net/ipv4/tcp_output.c:

... tcp_make_synack() {... skb = sock_wmalloc(sk,MAX_TCP_HEADER + 15 + s_data_desired,1,GFP_ATOMIC); ... }

... tcp_make_synack() { ... skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15 + s_data_desired, 1, GFP_ATOMIC); ... }

这似乎是TCP状态m/c的SYN-ACK部分. 因此,由此看来,尺寸"似乎可以达到320.

This seems to be the SYN-ACK part of the TCP state m/c. So, by this, 'size' seems to work out to around 320.

  1. TCP分段数据包.. 默认的'mss'是512吗? <-基于tcp_base_mss吗?
  1. TCP segments data packets.. default 'mss' is 512 ? <-- based on tcp_base_mss ?

TIA!

推荐答案

首先进行小校正-缓冲区位于headend之间,而不是tail(与data配对)之间.

Small correction first - the buffer is between head and end, not tail (which is paired with data).

您的基本想法是正确的. TCP根据其所需的数据进行分配,再加上用于较低层报头的空间.由于这些标头并不是真正预先知道的,因此TCP根据最大可能的数量进行分配(这很可能远远超过实际需要的数量).

Your basic idea is correct. TCP allocates according to the data it needs, plus room for lower layer headers. Since these headers are not really known in advance, TCP allocates according to the maximum possible (which is very likely to be much more than actually needed).

如果结束时不够,可以重新分配数据包(可以使用pskb_expand_head).
在大多数情况下,向数据包添加数据的代码会首先检查是否有足够的顶部空间(希望是这种情况),如果没有,则重新分配.

If this ends up not enough, the packet can be reallocated (pskb_expand_head can be used).
In most cases, code that adds data to the packet first checks if there's enough headspace (which will hopefully be the case), and reallocates if not.

默认" MSS不是很重要-仅在找不到更好的值时才使用.通常,MSS为MTU-40,通常为1460.

The "default" MSS isn't very important - it's only used when no better value can be found. Normally, the MSS will be MTU-40, which is usually 1460.

这篇关于如何确定和分配分配给要发送的数据包skb的空间量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆