Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the maximum TCP Maximum Segment Size on Linux?

Tags:

linux

tcp

qos

In Linux, how do you set the maximum segment size that is allowed on a TCP connection? I need to set this for an application I did not write (so I cannot use setsockopt to do it). I need to set this ABOVE the mtu in the network stack.

I have two streams sharing the same network connection. One sends small packets periodically, which need absolute minimum latency. The other sends tons of data--I am using SCP to simulate that link.

I have setup traffic control (tc) to give the minimum latency traffic high priority. The problem I am running into, though, is that the TCP packets that are coming down from SCP end up with sizes up to 64K bytes. Yes, these are broken into smaller packets based on mtu, but this unfortunately occurs AFTER tc prioritizes the packets. Thus, my low latency packet gets stuck behind up to 64K bytes of SCP traffic.

This article indicates that on Windows you can set this value.

Is there something on Linux I can set? I've tried ip route and iptables, but these are applied too low in the network stack. I need to limit the TCP packet size before tc, so it can prioritize the high priority packets appropriately.

like image 663
Eric Avatar asked Oct 04 '10 18:10

Eric


People also ask

How do you set a maximum segment size?

Use the following command to set the TCP maximum segment size (MSS) for segments received by your local system: set advanced-tuning tcp-ip tcp-mss <512-1500> The default value is 1024.

How is the maximum size of a TCP segment decided?

The default TCP Maximum Segment Size is 536. Where a host wishes to set the maximum segment size to a value other than the default, the maximum segment size is specified as a TCP option, initially in the TCP SYN packet during the TCP handshake. The value cannot be changed after the connection is established.

How do you control TCP packet size?

The maximum size of a TCP packet is 64K (65535 bytes). Generally, the packet size gets restricted by the Maximum Transmission Unit (MTU) of network resources. MTU is the maximum size of the data transfer limit set by hardware in a network. The packet size should never exceed MTU.


2 Answers

Are you using tcp segmentation offload to the nic? (You can use "ethtool -k $your_network_device" to see the offload settings.) This is the only way as far as I know that you would see 64k tcp packets with a device MTU of 1500. Not that this answers the question, but it might help avoid misdiagnosis.

like image 65
CitizenB Avatar answered Sep 19 '22 15:09

CitizenB


ip route command with option advmss helps to set MSS value.

ip route add 192.168.1.0/24 dev eth0 advmss 1500
like image 24
rashok Avatar answered Sep 18 '22 15:09

rashok