Skip to content

Commit 28576ae

Browse files
committed
tcp: add tcp_rto_max_ms sysctl
JIRA: https://issues.redhat.com/browse/RHEL-115393 Upstream Status: linux.git Conflicts:\ - Context differences due to missing upstream commit 54b771e ("doc: net: Fix .rst rendering of net_cachelines pages") in c10s. 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 5fac748 commit 28576ae

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ tcp_retries2 - INTEGER
705705
seconds and is a lower bound for the effective timeout.
706706
TCP will effectively time out at the first RTO which exceeds the
707707
hypothetical timeout.
708+
If tcp_rto_max_ms is decreased, it is recommended to also
709+
change tcp_retries2.
708710

709711
RFC 1122 recommends at least 100 seconds for the timeout,
710712
which corresponds to a value of at least 8.
@@ -1223,6 +1225,17 @@ tcp_rto_min_us - INTEGER
12231225

12241226
Default: 200000
12251227

1228+
tcp_rto_max_ms - INTEGER
1229+
Maximal TCP retransmission timeout (in ms).
1230+
Note that TCP_RTO_MAX_MS socket option has higher precedence.
1231+
1232+
When changing tcp_rto_max_ms, it is important to understand
1233+
that tcp_retries2 might need a change.
1234+
1235+
Possible Values: 1000 - 120,000
1236+
1237+
Default: 120,000
1238+
12261239
UDP variables
12271240
=============
12281241

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
@@ -181,6 +181,7 @@ struct netns_ipv4 {
181181
u8 sysctl_tcp_window_scaling;
182182
u8 sysctl_tcp_timestamps;
183183
int sysctl_tcp_rto_min_us;
184+
int sysctl_tcp_rto_max_ms;
184185
u8 sysctl_tcp_recovery;
185186
u8 sysctl_tcp_thin_linear_timeouts;
186187
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
@@ -28,6 +28,7 @@ static int tcp_adv_win_scale_max = 31;
2828
static int tcp_app_win_max = 31;
2929
static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
3030
static int tcp_min_snd_mss_max = 65535;
31+
static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
3132
static int ip_privileged_port_min;
3233
static int ip_privileged_port_max = 65535;
3334
static int ip_ttl_min = 1;
@@ -1573,6 +1574,15 @@ static struct ctl_table ipv4_net_table[] = {
15731574
.proc_handler = proc_dointvec_minmax,
15741575
.extra1 = SYSCTL_ONE,
15751576
},
1577+
{
1578+
.procname = "tcp_rto_max_ms",
1579+
.data = &init_net.ipv4.sysctl_tcp_rto_max_ms,
1580+
.maxlen = sizeof(int),
1581+
.mode = 0644,
1582+
.proc_handler = proc_dointvec_minmax,
1583+
.extra1 = SYSCTL_ONE_THOUSAND,
1584+
.extra2 = &tcp_rto_max_max,
1585+
},
15761586
};
15771587

15781588
static __net_init int ipv4_sysctl_init_net(struct net *net)

net/ipv4/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void tcp_init_sock(struct sock *sk)
423423
{
424424
struct inet_connection_sock *icsk = inet_csk(sk);
425425
struct tcp_sock *tp = tcp_sk(sk);
426-
int rto_min_us;
426+
int rto_min_us, rto_max_ms;
427427

428428
tp->out_of_order_queue = RB_ROOT;
429429
sk->tcp_rtx_queue = RB_ROOT;
@@ -433,8 +433,8 @@ void tcp_init_sock(struct sock *sk)
433433

434434
icsk->icsk_rto = TCP_TIMEOUT_INIT;
435435

436-
/* Use a sysctl ? */
437-
icsk->icsk_rto_max = TCP_RTO_MAX;
436+
rto_max_ms = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rto_max_ms);
437+
icsk->icsk_rto_max = msecs_to_jiffies(rto_max_ms);
438438

439439
rto_min_us = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rto_min_us);
440440
icsk->icsk_rto_min = usecs_to_jiffies(rto_min_us);

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,6 +3528,7 @@ static int __net_init tcp_sk_init(struct net *net)
35283528

35293529
net->ipv4.sysctl_tcp_pingpong_thresh = 1;
35303530
net->ipv4.sysctl_tcp_rto_min_us = jiffies_to_usecs(TCP_RTO_MIN);
3531+
net->ipv4.sysctl_tcp_rto_max_ms = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
35313532

35323533
return 0;
35333534
}

0 commit comments

Comments
 (0)