Linux内核每个TCP/IP网络连接消耗多少内存? [英] How much memory is consumed by the Linux kernel per TCP/IP network connection?
问题描述
Linux内核平均每个TCP/IP网络连接消耗多少内存(在内核地址空间中)?
How much memory on average is consumed by the Linux kernel (in kernel address space) per TCP/IP network connection?
推荐答案
对于TCP连接,消耗的内存取决于
For a TCP connection memory consumed depends on
-
sk_buff的大小(Linux内核使用的内部网络结构)
size of sk_buff (internal networking structure used by linux kernel)
用于连接的读写缓冲区
可以根据需要调整缓冲区的大小
the size of buffers can be tweaked as required
root@x:~# sysctl -A | grep net | grep mem
检查这些变量
这些参数指定内核中所有网络连接的最大默认内存缓冲区使用量
these specify the maximum default memory buffer usage for all network connections in kernel
net.core.wmem_max = 131071
net.core.rmem_max = 131071
net.core.wmem_default = 126976
net.core.rmem_default = 126976
这些指定特定于tcp连接的缓冲存储器使用情况
these specify buffer memory usage specific to tcp connections
net.ipv4.tcp_mem = 378528 504704 757056
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_rmem = 4096 87380 4194304
指定的三个值是最小默认最大"缓冲区大小. 因此从linux开始,将对每个连接使用默认值的读写缓冲区. 随着连接数量的增加,这些缓冲区将减少[最多直到指定的最小值] 最大缓冲区值也是如此.
the three values specified are " min default max" buffer sizes. So to start with linux will use the default values of read and write buffer for each connection. As the number of connection increases , these buffers will be reduced [at most till the specified min value] Same is the case for max buffer value.
可以使用此sysctl -w KEY=KEY VALUE
例如下面的命令确保每个连接的读写缓冲区分别为4096.
eg. The below command ensures the read and write buffers for each connection are 4096 each.
sysctl -w net.ipv4.tcp_rmem='4096 4096 4096'
sysctl -w net.ipv4.tcp_wmem='4096 4096 4096'
这篇关于Linux内核每个TCP/IP网络连接消耗多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!