Skip to content

Commit 01ccd4f

Browse files
committed
tcp: add tcp_rto_max_ms sysctl
JIRA: https://issues.redhat.com/browse/RHEL-115191 Upstream Status: linux.git Conflicts:\ - Minor chunk difference due to missing upstream commit f086ede ("tcp: add sysctl_tcp_rto_min_us") in c9s. - Context differences due to missing upstream commits 54b771e ("doc: net: Fix .rst rendering of net_cachelines pages"), f086ede ("tcp: add sysctl_tcp_rto_min_us"), 1c106eb ("net: ipv{6,4}: Remove the now superfluous sentinel elements from ctl_table array") and 562b1fd ("tcp: Set pingpong threshold via sysctl") in c9s. commit 1280c26 Author: Eric Dumazet <edumazet@google.com> Date: Fri Feb 7 15:28:30 2025 +0000 tcp: add tcp_rto_max_ms sysctl Previous patch added a TCP_RTO_MAX_MS socket option to tune a TCP socket max RTO value. Many setups prefer to change a per netns sysctl. This patch adds /proc/sys/net/ipv4/tcp_rto_max_ms Its initial value is 120000 (120 seconds). Keep in mind that a decrease of tcp_rto_max_ms means shorter overall timeouts, unless tcp_retries2 sysctl is increased. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com> Reviewed-by: Neal Cardwell <ncardwell@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent d8cf7ce commit 01ccd4f

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,8 @@ tcp_retries2 - INTEGER
697697
seconds and is a lower bound for the effective timeout.
698698
TCP will effectively time out at the first RTO which exceeds the
699699
hypothetical timeout.
700+
If tcp_rto_max_ms is decreased, it is recommended to also
701+
change tcp_retries2.
700702

701703
RFC 1122 recommends at least 100 seconds for the timeout,
702704
which corresponds to a value of at least 8.
@@ -1041,6 +1043,17 @@ tcp_challenge_ack_limit - INTEGER
10411043
in RFC 5961 (Improving TCP's Robustness to Blind In-Window Attacks)
10421044
Default: 1000
10431045

1046+
tcp_rto_max_ms - INTEGER
1047+
Maximal TCP retransmission timeout (in ms).
1048+
Note that TCP_RTO_MAX_MS socket option has higher precedence.
1049+
1050+
When changing tcp_rto_max_ms, it is important to understand
1051+
that tcp_retries2 might need a change.
1052+
1053+
Possible Values: 1000 - 120,000
1054+
1055+
Default: 120,000
1056+
10441057
UDP variables
10451058
=============
10461059

Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ u8 sysctl_tcp_sack -
8484
u8 sysctl_tcp_window_scaling - - tcp_syn_options,tcp_parse_options
8585
u8 sysctl_tcp_timestamps
8686
u8 sysctl_tcp_early_retrans read_mostly - tcp_schedule_loss_probe(tcp_write_xmit)
87+
u32 sysctl_tcp_rto_max_ms - -
8788
u8 sysctl_tcp_recovery - - tcp_fastretrans_alert
8889
u8 sysctl_tcp_thin_linear_timeouts - - tcp_retrans_timer(on_thin_streams)
8990
u8 sysctl_tcp_slow_start_after_idle - - unlikely(tcp_cwnd_validate-network-not-starved)

include/net/netns/ipv4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct netns_ipv4 {
171171
u8 sysctl_tcp_sack;
172172
u8 sysctl_tcp_window_scaling;
173173
u8 sysctl_tcp_timestamps;
174+
int sysctl_tcp_rto_max_ms;
174175
u8 sysctl_tcp_recovery;
175176
u8 sysctl_tcp_thin_linear_timeouts;
176177
u8 sysctl_tcp_slow_start_after_idle;

net/ipv4/sysctl_net_ipv4.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static int tcp_adv_win_scale_max = 31;
4141
static int tcp_app_win_max = 31;
4242
static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
4343
static int tcp_min_snd_mss_max = 65535;
44+
static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
4445
static int ip_privileged_port_min;
4546
static int ip_privileged_port_max = 65535;
4647
static int ip_ttl_min = 1;
@@ -1425,6 +1426,15 @@ static struct ctl_table ipv4_net_table[] = {
14251426
.extra1 = SYSCTL_ZERO,
14261427
.extra2 = SYSCTL_ONE,
14271428
},
1429+
{
1430+
.procname = "tcp_rto_max_ms",
1431+
.data = &init_net.ipv4.sysctl_tcp_rto_max_ms,
1432+
.maxlen = sizeof(int),
1433+
.mode = 0644,
1434+
.proc_handler = proc_dointvec_minmax,
1435+
.extra1 = SYSCTL_ONE_THOUSAND,
1436+
.extra2 = &tcp_rto_max_max,
1437+
},
14281438
{ }
14291439
};
14301440

net/ipv4/tcp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ void tcp_init_sock(struct sock *sk)
417417
{
418418
struct inet_connection_sock *icsk = inet_csk(sk);
419419
struct tcp_sock *tp = tcp_sk(sk);
420+
int rto_max_ms;
420421

421422
tp->out_of_order_queue = RB_ROOT;
422423
sk->tcp_rtx_queue = RB_ROOT;
@@ -426,8 +427,8 @@ void tcp_init_sock(struct sock *sk)
426427

427428
icsk->icsk_rto = TCP_TIMEOUT_INIT;
428429

429-
/* Use a sysctl ? */
430-
icsk->icsk_rto_max = TCP_RTO_MAX;
430+
rto_max_ms = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rto_max_ms);
431+
icsk->icsk_rto_max = msecs_to_jiffies(rto_max_ms);
431432

432433
icsk->icsk_rto_min = TCP_RTO_MIN;
433434

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,6 +3222,8 @@ static int __net_init tcp_sk_init(struct net *net)
32223222

32233223
net->ipv4.sysctl_tcp_shrink_window = 0;
32243224

3225+
net->ipv4.sysctl_tcp_rto_max_ms = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
3226+
32253227
return 0;
32263228
fail:
32273229
tcp_sk_exit(net);

0 commit comments

Comments
 (0)