TCP – Difference Between TCP Recv Buffer and TCP Receive Window Size

linuxtcp

The command shows the tcp receive buffer size in bytes.

$ cat /proc/sys/net/ipv4/tcp_rmem 
4096    87380   4001344

where the three values signifies the min, default and max values respectively.

Then I tried to find the tcp window size using tcpdump command.

 $ sudo tcpdump -n -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-ack) == tcp-syn and port 80 and host google.com' 
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
 16:15:41.465037 IP 172.16.31.141.51614 > 74.125.236.73.80: Flags [S], seq 3661804272,  win  14600, options [mss 1460,sackOK,TS val 4452053 ecr 0,nop,wscale 6], length 0

I got the window size to be 14600 which is 10 times the size of MSS.

Can anyone please tell me the relationship between the two.

Best Answer

The TCP window size is how much data can be "in flight" on the network. The TCP receive buffer is how much data can be buffered on the recipient's end.

Normally, a TCP stack will not allow data to be sent if it has no room for it in its receive buffer. Otherwise, if the data is received before the receiving application consumes some of the data in the buffer, the data would have to be throw away by the receiving TCP stack.

But the receive buffer can be much larger than the window.

With the settings you've shown (14,600 / 87,380), this end will allow the other end to send 14,600 bytes. As it receives data, it will update the window to allow to other end to send the lesser of 14,600 bytes or 87,380 bytes less the number of bytes waiting in its receive buffer.