Skip to contentSkip to conversation

tcp: add net.ipv4.tcp_comp_sack_rtt_percent

PATCH Superseded Eric Dumazet 3 participants 5 messages Nov 5, 2025 – Nov 6, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: add net.ipv4.tcp_comp_sack_rtt_percent

TCP SACK compression has been added in 2018 in commit 5d9f4262b7ea ("tcp: add SACK compression").

It is working great for WAN flows (with large RTT).
Wifi in particular gets a significant boost _when_ ACK are suppressed.

Add a new sysctl so that we can tune the very conservative 5 % value that has been used so far in this formula, so that small RTT flows can benefit from this feature.

delay = min ( 5 % of RTT, 1 ms)

This patch adds new tcp_comp_sack_rtt_percent sysctl to ease experiments and tuning.

Given that we cap the delay to 1ms (tcp_comp_sack_delay_ns sysctl), set the default value to 100.

---
 Documentation/networking/ip-sysctl.rst | 13 +++++++++++--
 include/net/netns/ipv4.h               |  1 +
 net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
 net/ipv4/tcp_input.c                   | 26 ++++++++++++++++++--------
 net/ipv4/tcp_ipv4.c                    |  1 +
 5 files changed, 40 insertions(+), 10 deletions(-)
Documentation/networking/ip-sysctl.rst +11 -2
index 7cd35bfd39e68c5b2650eb9d0fbb76e34aed3f2b..ebc11f593305bf87e7d4ad4d50ef085b22aef7da 100644
@@ -854,9 +854,18 @@ tcp_sack - BOOLEAN
 
 	Default: 1 (enabled)
 
+tcp_comp_sack_rtt_percent - INTEGER
+	Percentage of SRTT used for the compressed SACK feature.
+	See tcp_comp_sack_nr, tcp_comp_sack_delay_ns, tcp_comp_sack_slack_ns.
+
+	Possible values : 1 - 1000
+
+	Default : 100 %
+
 tcp_comp_sack_delay_ns - LONG INTEGER
-	TCP tries to reduce number of SACK sent, using a timer
-	based on 5% of SRTT, capped by this sysctl, in nano seconds.
+	TCP tries to reduce number of SACK sent, using a timer based
+	on tcp_comp_sack_rtt_percent of SRTT, capped by this sysctl
+	in nano seconds.
 	The default is 1ms, based on TSO autosizing period.
 
 	Default : 1,000,000 ns (1 ms)
include/net/netns/ipv4.h +1 -0
index 0e96c90e56c6d987a16598ef885c403d5c3eae52..de9d36acc8e22d3203120d8015b3d172e85de121 100644
@@ -221,6 +221,7 @@ struct netns_ipv4 {
 	int sysctl_tcp_pacing_ss_ratio;
 	int sysctl_tcp_pacing_ca_ratio;
 	unsigned int sysctl_tcp_child_ehash_entries;
+	int sysctl_tcp_comp_sack_rtt_percent;
 	unsigned long sysctl_tcp_comp_sack_delay_ns;
 	unsigned long sysctl_tcp_comp_sack_slack_ns;
 	int sysctl_max_syn_backlog;
net/ipv4/sysctl_net_ipv4.c +9 -0
index 0c7c8f9041cbf4aa4e51dcebd607aa5d8ac80dcd..35367f8e2da32f2c7de5a06164f5e47c8929c8f1 100644
@@ -1451,6 +1451,15 @@ static struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_doulongvec_minmax,
 	},
+	{
+		.procname	= "tcp_comp_sack_rtt_percent",
+		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_rtt_percent,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_ONE_THOUSAND,
+	},
 	{
 		.procname	= "tcp_comp_sack_slack_ns",
 		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
net/ipv4/tcp_input.c +18 -8
index 6db1d4c36a88bfa64b48388ee95e4e9218d9a9fd..d4ee74da018ee97209bed3402688f5e18759866b 100644
@@ -5893,7 +5893,9 @@ static inline void tcp_data_snd_check(struct sock *sk)
 static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
-	unsigned long rtt, delay;
+	struct net *net = sock_net(sk);
+	unsigned long rtt;
+	u64 delay;
 
 	    /* More than one full frame received... */
 	if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss &&
@@ -5912,7 +5914,7 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
 		 * Defer the ack until tcp_release_cb().
 		 */
 		if (sock_owned_by_user_nocheck(sk) &&
-		    READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_backlog_ack_defer)) {
+		    READ_ONCE(net->ipv4.sysctl_tcp_backlog_ack_defer)) {
 			set_bit(TCP_ACK_DEFERRED, &sk->sk_tsq_flags);
 			return;
 		}
@@ -5927,7 +5929,7 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
 	}
 
 	if (!tcp_is_sack(tp) ||
-	    tp->compressed_ack >= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_nr))
+	    tp->compressed_ack >= READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_nr))
 		goto send_now;
 
 	if (tp->compressed_ack_rcv_nxt != tp->rcv_nxt) {
@@ -5942,18 +5944,26 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
 	if (hrtimer_is_queued(&tp->compressed_ack_timer))
 		return;
 
-	/* compress ack timer : 5 % of rtt, but no more than tcp_comp_sack_delay_ns */
+	/* compress ack timer : comp_sack_rtt_percent of rtt,
+	 * but no more than tcp_comp_sack_delay_ns.
+	 */
 
 	rtt = tp->rcv_rtt_est.rtt_us;
 	if (tp->srtt_us && tp->srtt_us < rtt)
 		rtt = tp->srtt_us;
 
-	delay = min_t(unsigned long,
-		      READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_delay_ns),
-		      rtt * (NSEC_PER_USEC >> 3)/20);
+	/* delay = (rtt >> 3) * NSEC_PER_USEC * comp_sack_rtt_percent / 100
+	 * ->
+	 * delay = rtt * 1.25 * comp_sack_rtt_percent
+	 */
+	delay = (u64)(rtt + (rtt >> 2)) *
+		READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_rtt_percent);
+
+	delay = min(delay, READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_delay_ns));
+
 	sock_hold(sk);
 	hrtimer_start_range_ns(&tp->compressed_ack_timer, ns_to_ktime(delay),
-			       READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_slack_ns),
+			       READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_slack_ns),
 			       HRTIMER_MODE_REL_PINNED_SOFT);
 }
 
net/ipv4/tcp_ipv4.c +1 -0
index b7526a7888cbe296c0f4ba6350772741cfe1765b..a4411cd0229cb7fc5903d206e549d0889d177937 100644
@@ -3596,6 +3596,7 @@ static int __net_init tcp_sk_init(struct net *net)
 	net->ipv4.sysctl_tcp_comp_sack_delay_ns = NSEC_PER_MSEC;
 	net->ipv4.sysctl_tcp_comp_sack_slack_ns = 100 * NSEC_PER_USEC;
 	net->ipv4.sysctl_tcp_comp_sack_nr = 44;
+	net->ipv4.sysctl_tcp_comp_sack_rtt_percent = 100;
 	net->ipv4.sysctl_tcp_backlog_ack_defer = 1;
 	net->ipv4.sysctl_tcp_fastopen = TFO_CLIENT_ENABLE;
 	net->ipv4.sysctl_tcp_fastopen_blackhole_timeout = 0;
Signature · 1 line
2.51.2.1026.g39e6a42477-goog
maintainer
#1 lore raw
Quoted 33 lines · Eric Dumazet

TCP SACK compression has been added in 2018 in commit 5d9f4262b7ea ("tcp: add SACK compression").

It is working great for WAN flows (with large RTT).
Wifi in particular gets a significant boost _when_ ACK are suppressed.

Add a new sysctl so that we can tune the very conservative 5 % value that has been used so far in this formula, so that small RTT flows can benefit from this feature.

delay = min ( 5 % of RTT, 1 ms)

This patch adds new tcp_comp_sack_rtt_percent sysctl to ease experiments and tuning.

Given that we cap the delay to 1ms (tcp_comp_sack_delay_ns sysctl), set the default value to 100.

---
 Documentation/networking/ip-sysctl.rst | 13 +++++++++++--
 include/net/netns/ipv4.h               |  1 +
 net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
 net/ipv4/tcp_input.c                   | 26 ++++++++++++++++++--------
 net/ipv4/tcp_ipv4.c                    |  1 +
 5 files changed, 40 insertions(+), 10 deletions(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 7cd35bfd39e68c5b2650eb9d0fbb76e34aed3f2b..ebc11f593305bf87e7d4ad4d50ef085b22aef7da 100644

Documentation/networking/ip-sysctl.rst tcp_sack - BOOLEAN · line 863

Quoted 10 lines
Documentation/networking/ip-sysctl.rst +7 -0
@@ -854,9 +854,18 @@ tcp_sack - BOOLEAN
 
        Default: 1 (enabled)
 
+tcp_comp_sack_rtt_percent - INTEGER
+       Percentage of SRTT used for the compressed SACK feature.
+       See tcp_comp_sack_nr, tcp_comp_sack_delay_ns, tcp_comp_sack_slack_ns.
+
+       Possible values : 1 - 1000
+
+       Default : 100 %

Overall the patch looks great to me, but for the default value I would suggest 33% rather than 100%.

AFAICT, basically, in data center environments with RTT < 1ms, if tcp_comp_sack_rtt_percent is 100% and we allow the data receiver to wait a whole SRTT before it sends an ACK, then the data sender is likely to have fully used up its cwnd at the point that the receiver finally sends the ACK at the end of the SRTT. That means that for the entire time that the ACK is traveling from the data receiver to the data sender, the data sender has no permission (from congestion control) to send. So the "pipe" (data sender -> data receiver network path) will have an idle bubble for a long time while the data sender is waiting for the ACK. In these cases, the system would lose pipelining and would end up in a "stop and wait" mode.

The rationale for 33% is basically to try to facilitate pipelining, where there are always at least 3 ACKs and 3 GSO/TSO skbs per SRTT, so that the path can maintain a budget for 3 full-sized GSO/TSO skbs "in flight" at all times:

+ 1 skb in the qdisc waiting to be sent by the NIC next
+ 1 skb being sent by the NIC (being serialized by the NIC out onto the wire)
+ 1 skb being received and aggregated by the receiver machine's aggregation mechanism (some combination of LRO, GRO, and sack compression)

Note that this is basically the same magic number (3) and the same rationales as:

(a) tcp_tso_should_defer() ensuring that we defer sending data for no longer than cwnd/tcp_tso_win_divisor (where tcp_tso_win_divisor = 3), and
(b) bbr_quantization_budget() ensuring that cwnd is at least 3 GSO/TSO skbs to maintain pipelining and full throughput at low RTTs

It is also similar in spirit to your 2014 patch that limits GSO skbs to half the cwnd, again to help maintain pipelining:

tcp: limit GSO packets to half cwnd
d649a7a81f3b5bacb1d60abd7529894d8234a666
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d649a7a81f3b5bacb1d60abd7529894d8234a666

WDYT?

neal

#2 lore raw
Quoted 81 lines · Neal Cardwell
Quoted 33 lines · Eric Dumazet

TCP SACK compression has been added in 2018 in commit 5d9f4262b7ea ("tcp: add SACK compression").

It is working great for WAN flows (with large RTT).
Wifi in particular gets a significant boost _when_ ACK are suppressed.

Add a new sysctl so that we can tune the very conservative 5 % value that has been used so far in this formula, so that small RTT flows can benefit from this feature.

delay = min ( 5 % of RTT, 1 ms)

This patch adds new tcp_comp_sack_rtt_percent sysctl to ease experiments and tuning.

Given that we cap the delay to 1ms (tcp_comp_sack_delay_ns sysctl), set the default value to 100.

---
 Documentation/networking/ip-sysctl.rst | 13 +++++++++++--
 include/net/netns/ipv4.h               |  1 +
 net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
 net/ipv4/tcp_input.c                   | 26 ++++++++++++++++++--------
 net/ipv4/tcp_ipv4.c                    |  1 +
 5 files changed, 40 insertions(+), 10 deletions(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 7cd35bfd39e68c5b2650eb9d0fbb76e34aed3f2b..ebc11f593305bf87e7d4ad4d50ef085b22aef7da 100644

Documentation/networking/ip-sysctl.rst tcp_sack - BOOLEAN · line 863

Quoted 10 lines
Documentation/networking/ip-sysctl.rst +7 -0
@@ -854,9 +854,18 @@ tcp_sack - BOOLEAN
 
        Default: 1 (enabled)
 
+tcp_comp_sack_rtt_percent - INTEGER
+       Percentage of SRTT used for the compressed SACK feature.
+       See tcp_comp_sack_nr, tcp_comp_sack_delay_ns, tcp_comp_sack_slack_ns.
+
+       Possible values : 1 - 1000
+
+       Default : 100 %

Overall the patch looks great to me, but for the default value I would suggest 33% rather than 100%.

AFAICT, basically, in data center environments with RTT < 1ms, if tcp_comp_sack_rtt_percent is 100% and we allow the data receiver to wait a whole SRTT before it sends an ACK, then the data sender is likely to have fully used up its cwnd at the point that the receiver finally sends the ACK at the end of the SRTT. That means that for the entire time that the ACK is traveling from the data receiver to the data sender, the data sender has no permission (from congestion control) to send. So the "pipe" (data sender -> data receiver network path) will have an idle bubble for a long time while the data sender is waiting for the ACK. In these cases, the system would lose pipelining and would end up in a "stop and wait" mode.

The rationale for 33% is basically to try to facilitate pipelining, where there are always at least 3 ACKs and 3 GSO/TSO skbs per SRTT, so that the path can maintain a budget for 3 full-sized GSO/TSO skbs "in flight" at all times:

+ 1 skb in the qdisc waiting to be sent by the NIC next
+ 1 skb being sent by the NIC (being serialized by the NIC out onto the wire)
+ 1 skb being received and aggregated by the receiver machine's aggregation mechanism (some combination of LRO, GRO, and sack compression)

Note that this is basically the same magic number (3) and the same rationales as:

(a) tcp_tso_should_defer() ensuring that we defer sending data for no longer than cwnd/tcp_tso_win_divisor (where tcp_tso_win_divisor = 3), and
(b) bbr_quantization_budget() ensuring that cwnd is at least 3 GSO/TSO skbs to maintain pipelining and full throughput at low RTTs

Quoted 8 lines

It is also similar in spirit to your 2014 patch that limits GSO skbs to half the cwnd, again to help maintain pipelining:

tcp: limit GSO packets to half cwnd
d649a7a81f3b5bacb1d60abd7529894d8234a666
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d649a7a81f3b5bacb1d60abd7529894d8234a666

WDYT?

This all makes sense Neal, thank you !

I was mainly focused on reordering issues more than actual drops :)

#3 lore raw
In reply to Eric Dumazet
Quoted 32 lines · Eric Dumazet

TCP SACK compression has been added in 2018 in commit 5d9f4262b7ea ("tcp: add SACK compression").

It is working great for WAN flows (with large RTT).
Wifi in particular gets a significant boost _when_ ACK are suppressed.

Add a new sysctl so that we can tune the very conservative 5 % value that has been used so far in this formula, so that small RTT flows can benefit from this feature.

delay = min ( 5 % of RTT, 1 ms)

This patch adds new tcp_comp_sack_rtt_percent sysctl to ease experiments and tuning.

Given that we cap the delay to 1ms (tcp_comp_sack_delay_ns sysctl), set the default value to 100.

---
  Documentation/networking/ip-sysctl.rst | 13 +++++++++++--
  include/net/netns/ipv4.h               |  1 +
  net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
  net/ipv4/tcp_input.c                   | 26 ++++++++++++++++++--------
  net/ipv4/tcp_ipv4.c                    |  1 +
  5 files changed, 40 insertions(+), 10 deletions(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 7cd35bfd39e68c5b2650eb9d0fbb76e34aed3f2b..ebc11f593305bf87e7d4ad4d50ef085b22aef7da 100644

Documentation/networking/ip-sysctl.rst tcp_sack - BOOLEAN · line 861

Quoted 8 lines
Documentation/networking/ip-sysctl.rst +5 -0
@@ -854,9 +854,18 @@ tcp_sack - BOOLEAN
 
  	Default: 1 (enabled)
 
+tcp_comp_sack_rtt_percent - INTEGER
+	Percentage of SRTT used for the compressed SACK feature.
+	See tcp_comp_sack_nr, tcp_comp_sack_delay_ns, tcp_comp_sack_slack_ns.
+
+	Possible values : 1 - 1000

If this is a percentage, why does it allow 1000 as max?

Quoted 86 lines
Documentation/networking/ip-sysctl.rst +5 -2
+	Default : 100 %
+
  tcp_comp_sack_delay_ns - LONG INTEGER
-	TCP tries to reduce number of SACK sent, using a timer
-	based on 5% of SRTT, capped by this sysctl, in nano seconds.
+	TCP tries to reduce number of SACK sent, using a timer based
+	on tcp_comp_sack_rtt_percent of SRTT, capped by this sysctl
+	in nano seconds.
  	The default is 1ms, based on TSO autosizing period.
 
  	Default : 1,000,000 ns (1 ms)
include/net/netns/ipv4.h +1 -0
index 0e96c90e56c6d987a16598ef885c403d5c3eae52..de9d36acc8e22d3203120d8015b3d172e85de121 100644
@@ -221,6 +221,7 @@ struct netns_ipv4 {
  	int sysctl_tcp_pacing_ss_ratio;
  	int sysctl_tcp_pacing_ca_ratio;
  	unsigned int sysctl_tcp_child_ehash_entries;
+	int sysctl_tcp_comp_sack_rtt_percent;
  	unsigned long sysctl_tcp_comp_sack_delay_ns;
  	unsigned long sysctl_tcp_comp_sack_slack_ns;
  	int sysctl_max_syn_backlog;
net/ipv4/sysctl_net_ipv4.c +9 -0
index 0c7c8f9041cbf4aa4e51dcebd607aa5d8ac80dcd..35367f8e2da32f2c7de5a06164f5e47c8929c8f1 100644
@@ -1451,6 +1451,15 @@ static struct ctl_table ipv4_net_table[] = {
  		.mode		= 0644,
  		.proc_handler	= proc_doulongvec_minmax,
  	},
+	{
+		.procname	= "tcp_comp_sack_rtt_percent",
+		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_rtt_percent,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_ONE_THOUSAND,
+	},
  	{
  		.procname	= "tcp_comp_sack_slack_ns",
  		.data		= &init_net.ipv4.sysctl_tcp_comp_sack_slack_ns,
net/ipv4/tcp_input.c +8 -4
index 6db1d4c36a88bfa64b48388ee95e4e9218d9a9fd..d4ee74da018ee97209bed3402688f5e18759866b 100644
@@ -5893,7 +5893,9 @@ static inline void tcp_data_snd_check(struct sock *sk)
  static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
  {
  	struct tcp_sock *tp = tcp_sk(sk);
-	unsigned long rtt, delay;
+	struct net *net = sock_net(sk);
+	unsigned long rtt;
+	u64 delay;
 
  	    /* More than one full frame received... */
  	if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss &&
@@ -5912,7 +5914,7 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
  		 * Defer the ack until tcp_release_cb().
  		 */
  		if (sock_owned_by_user_nocheck(sk) &&
-		    READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_backlog_ack_defer)) {
+		    READ_ONCE(net->ipv4.sysctl_tcp_backlog_ack_defer)) {
  			set_bit(TCP_ACK_DEFERRED, &sk->sk_tsq_flags);
  			return;
  		}
@@ -5927,7 +5929,7 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
  	}
 
  	if (!tcp_is_sack(tp) ||
-	    tp->compressed_ack >= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_nr))
+	    tp->compressed_ack >= READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_nr))
  		goto send_now;
 
  	if (tp->compressed_ack_rcv_nxt != tp->rcv_nxt) {
@@ -5942,18 +5944,26 @@ static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible)
  	if (hrtimer_is_queued(&tp->compressed_ack_timer))
  		return;
 
-	/* compress ack timer : 5 % of rtt, but no more than tcp_comp_sack_delay_ns */
+	/* compress ack timer : comp_sack_rtt_percent of rtt,
+	 * but no more than tcp_comp_sack_delay_ns.
+	 */
 
  	rtt = tp->rcv_rtt_est.rtt_us;

net/ipv4/tcp_input.c static void __tcp_ack_snd_check(struct sock *sk, int ofo_possible) · line 5958

Quoted 10 lines
net/ipv4/tcp_input.c +4 -3
  	if (tp->srtt_us && tp->srtt_us < rtt)
  		rtt = tp->srtt_us;
 
-	delay = min_t(unsigned long,
-		      READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_delay_ns),
-		      rtt * (NSEC_PER_USEC >> 3)/20);
+	/* delay = (rtt >> 3) * NSEC_PER_USEC * comp_sack_rtt_percent / 100
+	 * ->
+	 * delay = rtt * 1.25 * comp_sack_rtt_percent
+	 */

Why explain this with shifts. I have to use extra time to remember that shift ">> 3" is the same as div "/" 8. And that ">>" 2 is the same as div "/4". For the code, I think the compiler will convert /4 to >>2 anyway. I don't feel strongly about this, so I'll let it be up to you if you want to adjust this or not.

Quoted 24 lines
net/ipv4/tcp_input.c +6 -1
+	delay = (u64)(rtt + (rtt >> 2)) *
+		READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_rtt_percent);
+
+	delay = min(delay, READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_delay_ns));
+
  	sock_hold(sk);
  	hrtimer_start_range_ns(&tp->compressed_ack_timer, ns_to_ktime(delay),
-			       READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_slack_ns),
+			       READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_slack_ns),
  			       HRTIMER_MODE_REL_PINNED_SOFT);
  }
 
net/ipv4/tcp_ipv4.c +1 -0
index b7526a7888cbe296c0f4ba6350772741cfe1765b..a4411cd0229cb7fc5903d206e549d0889d177937 100644
@@ -3596,6 +3596,7 @@ static int __net_init tcp_sk_init(struct net *net)
  	net->ipv4.sysctl_tcp_comp_sack_delay_ns = NSEC_PER_MSEC;
  	net->ipv4.sysctl_tcp_comp_sack_slack_ns = 100 * NSEC_PER_USEC;
  	net->ipv4.sysctl_tcp_comp_sack_nr = 44;
+	net->ipv4.sysctl_tcp_comp_sack_rtt_percent = 100;
  	net->ipv4.sysctl_tcp_backlog_ack_defer = 1;
  	net->ipv4.sysctl_tcp_fastopen = TFO_CLIENT_ENABLE;
  	net->ipv4.sysctl_tcp_fastopen_blackhole_timeout = 0;
#4 lore raw
Quoted 37 lines · Jesper Dangaard Brouer
Quoted 35 lines · Eric Dumazet

TCP SACK compression has been added in 2018 in commit 5d9f4262b7ea ("tcp: add SACK compression").

It is working great for WAN flows (with large RTT).
Wifi in particular gets a significant boost _when_ ACK are suppressed.

Add a new sysctl so that we can tune the very conservative 5 % value that has been used so far in this formula, so that small RTT flows can benefit from this feature.

delay = min ( 5 % of RTT, 1 ms)

This patch adds new tcp_comp_sack_rtt_percent sysctl to ease experiments and tuning.

Given that we cap the delay to 1ms (tcp_comp_sack_delay_ns sysctl), set the default value to 100.

---
  Documentation/networking/ip-sysctl.rst | 13 +++++++++++--
  include/net/netns/ipv4.h               |  1 +
  net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
  net/ipv4/tcp_input.c                   | 26 ++++++++++++++++++--------
  net/ipv4/tcp_ipv4.c                    |  1 +
  5 files changed, 40 insertions(+), 10 deletions(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 7cd35bfd39e68c5b2650eb9d0fbb76e34aed3f2b..ebc11f593305bf87e7d4ad4d50ef085b22aef7da 100644
@@ -854,9 +854,18 @@ tcp_sack - BOOLEAN
 
      Default: 1 (enabled)
 
Quoted 7 lines

Documentation/networking/ip-sysctl.rst tcp_sack - BOOLEAN · line 861

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +5 -0
+tcp_comp_sack_rtt_percent - INTEGER
+     Percentage of SRTT used for the compressed SACK feature.
+     See tcp_comp_sack_nr, tcp_comp_sack_delay_ns, tcp_comp_sack_slack_ns.
+
+     Possible values : 1 - 1000

If this is a percentage, why does it allow 1000 as max?

To allow a 10x max. If someone needs more in the future, we might change it.

Quoted 10 lines

Documentation/networking/ip-sysctl.rst tcp_sack - BOOLEAN · line 865

Quoted 4 lines
Documentation/networking/ip-sysctl.rst +4 -0
+     /* delay = (rtt >> 3) * NSEC_PER_USEC * comp_sack_rtt_percent / 100
+      * ->
+      * delay = rtt * 1.25 * comp_sack_rtt_percent
+      */

Why explain this with shifts. I have to use extra time to remember that shift ">> 3" is the same as div "/" 8. And that ">>" 2 is the same as div "/4". For the code, I think the compiler will convert /4 to >>2 anyway. I don't feel strongly about this, so I'll let it be up to you if you want to adjust this or not.

Look elsewhere in TCP, we always convert rtt with (rtt >> 3), because it is kept scaled by 3.

I personally prefer this to rtt/8, but I understand if you are from another team :)

Quoted 27 lines
Quoted 26 lines
Documentation/networking/ip-sysctl.rst +6 -1
+     delay = (u64)(rtt + (rtt >> 2)) *
+             READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_rtt_percent);
+
+     delay = min(delay, READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_delay_ns));
+
      sock_hold(sk);
      hrtimer_start_range_ns(&tp->compressed_ack_timer, ns_to_ktime(delay),
-                            READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_slack_ns),
+                            READ_ONCE(net->ipv4.sysctl_tcp_comp_sack_slack_ns),
                             HRTIMER_MODE_REL_PINNED_SOFT);
  }
net/ipv4/tcp_ipv4.c +1 -0
index b7526a7888cbe296c0f4ba6350772741cfe1765b..a4411cd0229cb7fc5903d206e549d0889d177937 100644
@@ -3596,6 +3596,7 @@ static int __net_init tcp_sk_init(struct net *net)
      net->ipv4.sysctl_tcp_comp_sack_delay_ns = NSEC_PER_MSEC;
      net->ipv4.sysctl_tcp_comp_sack_slack_ns = 100 * NSEC_PER_USEC;
      net->ipv4.sysctl_tcp_comp_sack_nr = 44;
+     net->ipv4.sysctl_tcp_comp_sack_rtt_percent = 100;
      net->ipv4.sysctl_tcp_backlog_ack_defer = 1;
      net->ipv4.sysctl_tcp_fastopen = TFO_CLIENT_ENABLE;
      net->ipv4.sysctl_tcp_fastopen_blackhole_timeout = 0;