Skip to content

Commit

Permalink
Merge branch 'support-tcp_rto_min_us-and-tcp_delack_max_us-for-set-ge…
Browse files Browse the repository at this point in the history
…tsockopt'

Jason Xing says:

====================
support TCP_RTO_MIN_US and TCP_DELACK_MAX_US for set/getsockopt

Add set/getsockopt supports for TCP_RTO_MIN_US and TCP_DELACK_MAX_US.
====================

Link: https://patch.msgid.link/20250317120314.41404-1-kerneljasonxing@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Mar 25, 2025
2 parents 98b2c04 + 9552f90 commit 0d14c39
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Documentation/networking/ip-sysctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,8 @@ tcp_pingpong_thresh - INTEGER
tcp_rto_min_us - INTEGER
Minimal TCP retransmission timeout (in microseconds). Note that the
rto_min route option has the highest precedence for configuring this
setting, followed by the TCP_BPF_RTO_MIN socket option, followed by
this tcp_rto_min_us sysctl.
setting, followed by the TCP_BPF_RTO_MIN and TCP_RTO_MIN_US socket
options, followed by this tcp_rto_min_us sysctl.

The recommended practice is to use a value less or equal to 200000
microseconds.
Expand Down
2 changes: 1 addition & 1 deletion include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ u32 tcp_delack_max(const struct sock *sk);
static inline u32 tcp_rto_min(const struct sock *sk)
{
const struct dst_entry *dst = __sk_dst_get(sk);
u32 rto_min = inet_csk(sk)->icsk_rto_min;
u32 rto_min = READ_ONCE(inet_csk(sk)->icsk_rto_min);

if (dst && dst_metric_locked(dst, RTAX_RTO_MIN))
rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN);
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/linux/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ enum {

#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */
#define TCP_RTO_MAX_MS 44 /* max rto time in ms */
#define TCP_RTO_MIN_US 45 /* min rto time in us */
#define TCP_DELACK_MAX_US 46 /* max delayed ack time in us */

#define TCP_REPAIR_ON 1
#define TCP_REPAIR_OFF 0
Expand Down
26 changes: 24 additions & 2 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3352,8 +3352,8 @@ int tcp_disconnect(struct sock *sk, int flags)
icsk->icsk_probes_out = 0;
icsk->icsk_probes_tstamp = 0;
icsk->icsk_rto = TCP_TIMEOUT_INIT;
icsk->icsk_rto_min = TCP_RTO_MIN;
icsk->icsk_delack_max = TCP_DELACK_MAX;
WRITE_ONCE(icsk->icsk_rto_min, TCP_RTO_MIN);
WRITE_ONCE(icsk->icsk_delack_max, TCP_DELACK_MAX);
tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
tcp_snd_cwnd_set(tp, TCP_INIT_CWND);
tp->snd_cwnd_cnt = 0;
Expand Down Expand Up @@ -3833,6 +3833,22 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
return -EINVAL;
WRITE_ONCE(inet_csk(sk)->icsk_rto_max, msecs_to_jiffies(val));
return 0;
case TCP_RTO_MIN_US: {
int rto_min = usecs_to_jiffies(val);

if (rto_min > TCP_RTO_MIN || rto_min < TCP_TIMEOUT_MIN)
return -EINVAL;
WRITE_ONCE(inet_csk(sk)->icsk_rto_min, rto_min);
return 0;
}
case TCP_DELACK_MAX_US: {
int delack_max = usecs_to_jiffies(val);

if (delack_max > TCP_DELACK_MAX || delack_max < TCP_TIMEOUT_MIN)
return -EINVAL;
WRITE_ONCE(inet_csk(sk)->icsk_delack_max, delack_max);
return 0;
}
}

sockopt_lock_sock(sk);
Expand Down Expand Up @@ -4672,6 +4688,12 @@ int do_tcp_getsockopt(struct sock *sk, int level,
case TCP_RTO_MAX_MS:
val = jiffies_to_msecs(tcp_rto_max(sk));
break;
case TCP_RTO_MIN_US:
val = jiffies_to_usecs(READ_ONCE(inet_csk(sk)->icsk_rto_min));
break;
case TCP_DELACK_MAX_US:
val = jiffies_to_usecs(READ_ONCE(inet_csk(sk)->icsk_delack_max));
break;
default:
return -ENOPROTOOPT;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -4179,7 +4179,7 @@ u32 tcp_delack_max(const struct sock *sk)
{
u32 delack_from_rto_min = max(tcp_rto_min(sk), 2) - 1;

return min(inet_csk(sk)->icsk_delack_max, delack_from_rto_min);
return min(READ_ONCE(inet_csk(sk)->icsk_delack_max), delack_from_rto_min);
}

/* Send out a delayed ack, the caller does the policy checking
Expand Down

0 comments on commit 0d14c39

Please sign in to comment.