net.ipv4.tcp_app_win 有什么作用?

jav*_*g87 5 linux tcp tcp-ip

我不明白为什么这些变量在 Linux 中共存。来自 man tcp 的信息说(Ubuntu 12.04):

对于 tcp_adv_win_scale:

tcp_adv_win_scale(整数;默认值:2;自 Linux 2.4 起)

          Count   buffering   overhead  as  bytes/2^tcp_adv_win_scale,  if
          tcp_adv_win_scale    is    greater    than    0;    or    bytes-
          bytes/2^(-tcp_adv_win_scale),  if tcp_adv_win_scale is less than
          or equal to zero.

          The socket receive buffer space is shared between  the  applica?
          tion  and  kernel.   TCP maintains part of the buffer as the TCP
          window, this is the size of the receive window advertised to the
          other  end.   The rest of the space is used as the "application"
          buffer, used to isolate the network from scheduling and applica?
          tion  latencies.   The  tcp_adv_win_scale  default  value  of  2
          implies that the space used for the application  buffer  is  one
          fourth that of the total.
Run Code Online (Sandbox Code Playgroud)

对于 tcp_app_win:

tcp_app_win (integer; default: 31; since Linux 2.4)
              This  variable  defines  how  many  bytes  of the TCP window are
              reserved for buffering overhead.

              A maximum of (window/2^tcp_app_win, mss) bytes in the window are
              reserved  for the application buffer.  A value of 0 implies that
              no amount is reserved.
Run Code Online (Sandbox Code Playgroud)

所以我不确定 tcp_app_win 究竟发生了什么变化。在我看来,这两个变量都可以用来调整 TCP 应用程序缓冲区,因此不需要一起更改它们。我是对的?

slm*_*slm 3

我找到了这个信息,其中谈到了tcp_adv_win_scale。该页面的标题是:TCP 性能调整 - 如何调整 linux

摘抄

TCP 性能受到延迟和窗口大小(以及开销,这会减少有效窗口大小)的限制,具体取决于 window_size/RTT(这是在任何给定时刻可以通过链路“传输”的数据量)。

要获得可能的实际传输速度,您必须将结果窗口除以延迟(以秒为单位):

开销为:window/2^tcp_adv_win_scale(tcp_adv_win_scale默认为2)

因此,对于 Linux 接收窗口(tcp_rmem)的默认参数:87380 - (87380 / 2^2) = 65536。

给定跨大西洋链路(150 ms RTT),最大性能最终为:65536/0.150 = 436906 字节/秒或约 400 kbyte/秒,这在今天确实很慢。

随着默认大小的增加:(873800 - 873800/2^2)/0.150 = 4369000 字节/秒,或大约 4Mbytes/秒,这对于现代网络来说是合理的。请注意,这是默认设置,如果发送方配置了更大的窗口大小,它会很高兴地扩展到 10 倍(8738000*0.75/0.150 = ~40Mbytes/s),这对于现代网络来说非常好。

2.6.17 及更高版本具有相当好的默认值,并且如果对方支持的话,实际上可以将窗口大小调整到允许的最大值。因此,从那时起,本指南的大部分内容就不再需要了。不过,为了获得良好的长途吞吐量,可能需要增加最大值。

我能够理解这一点,但不太理解这两个变量之间的关系(如果有的话)。

我只是勉强理解这试图解释什么。从本质上讲,这个参数听起来像是用于缩放缓冲空间量的参数,用于 TCP 和应用程序。

经过更多搜索,我发现这些解释更有意义。该页面的标题是:Ipsysctl 教程 1.0.4 - 第 3 章。 IPv4 变量引用

摘抄

3.3.2. tcp_adv_win_scale

该变量用于告诉内核应将多少套接字缓冲区空间用于 TCP 窗口大小,以及为应用程序缓冲区保存多少空间。如果 tcp_adv_win_scale 为负数,则使用以下公式计算窗口缩放的缓冲区开销:

其中 bytes 是窗口中的字节数。如果 tcp_adv_win_scale 值为正,则使用以下公式计算缓冲区开销:

tcp_adv_win_scale 变量采用整数值,默认设置为 2。这又意味着应用程序缓冲区是 tcp_rmem 变量中指定的总缓冲区空间的 1/4。

3.3.3. tcp_app_win

该变量告诉内核在传输特定 TCP 窗口的 TCP 套接字内存缓冲区中为特定 TCP 窗口保留多少字节。该值用于指定要保留多少缓冲区空间的计算中,如下所示:下列:

公式的 SS

从上面的计算中您可能会了解到,该值越大,特定窗口的缓冲区空间就越小。此计算的唯一例外是 0,它告诉内核不为该特定连接保留空间。该变量的默认值为 31,通常应该是一个不错的值。除非您知道自己在做什么,否则请勿更改此值。

根据这些解释,听起来第一个参数tcp_adv_win_scale是控制套接字缓冲区空间的分割,即如何划分 TCP 窗口使用与应用程序缓冲区。

而第二个参数tcp_app_win指定为描述中提到的应用程序缓冲区保留的字节数tcp_adv_win_scale