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
指定的三个值是min default max"缓冲区大小.所以从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屋!