Skip to contentSkip to conversation

tcp: Change txhash on every SYN and RTO retransmit

PATCH Superseded Lawrence Brakmo 2 participants 3 messages Sep 27, 2016

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: Change txhash on every SYN and RTO retransmit

The current code changes txhash (flowlables) on every retransmitted SYN/ACK, but only after the 2nd retransmitted SYN and only after tcp_retries1 RTO retransmits.

With this patch:
1) txhash is changed with every SYN retransmist
2) adds the option for the txhash to be changed before tcp_retries1 RTO retransmits. A new sysctl tcp_rto_txhash_prob represents the probability that txhash will be changed. The default value is 0 which maintains previous behavior and a value of 100 will always change it.

Tested with packetdrill tests

---
 include/net/tcp.h          |  1 +
 net/ipv4/sysctl_net_ipv4.c | 10 ++++++++++
 net/ipv4/tcp_input.c       |  2 ++
 net/ipv4/tcp_timer.c       |  7 +++++++
 4 files changed, 20 insertions(+)
include/net/tcp.h +1 -0
index f83b7f2..406d474 100644
@@ -271,6 +271,7 @@ extern int sysctl_tcp_autocorking;
 extern int sysctl_tcp_invalid_ratelimit;
 extern int sysctl_tcp_pacing_ss_ratio;
 extern int sysctl_tcp_pacing_ca_ratio;
+extern int sysctl_tcp_rto_txhash_prob;
 
 extern atomic_long_t tcp_memory_allocated;
 extern struct percpu_counter tcp_sockets_allocated;
net/ipv4/sysctl_net_ipv4.c +10 -0
index 1cb67de..0b185a1 100644
@@ -28,6 +28,7 @@
 static int zero;
 static int one = 1;
 static int four = 4;
+static int hundred = 100;
 static int thousand = 1000;
 static int gso_max_segs = GSO_MAX_SEGS;
 static int tcp_retr1_max = 255;
@@ -624,6 +625,15 @@ static struct ctl_table ipv4_table[] = {
 		.proc_handler	= proc_dointvec_ms_jiffies,
 	},
 	{
+		.procname	= "tcp_rto_txhash_prob",
+		.data		= &sysctl_tcp_rto_txhash_prob,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &zero,
+		.extra2		= &hundred,
+	},
+	{
 		.procname	= "icmp_msgs_per_sec",
 		.data		= &sysctl_icmp_msgs_per_sec,
 		.maxlen		= sizeof(int),
net/ipv4/tcp_input.c +2 -0
index 8c6ad2d..2fea29d 100644
@@ -101,6 +101,8 @@ int sysctl_tcp_moderate_rcvbuf __read_mostly = 1;
 int sysctl_tcp_early_retrans __read_mostly = 3;
 int sysctl_tcp_invalid_ratelimit __read_mostly = HZ/2;
 
+int sysctl_tcp_rto_txhash_prob __read_mostly = 100;
+
 #define FLAG_DATA		0x01 /* Incoming frame contained data.		*/
 #define FLAG_WIN_UPDATE		0x02 /* Incoming ACK was a window update.	*/
 #define FLAG_DATA_ACKED		0x04 /* This ACK acknowledged new data.		*/
net/ipv4/tcp_timer.c +7 -0
index f712b41..0df8c5f 100644
@@ -192,6 +192,8 @@ static int tcp_write_timeout(struct sock *sk)
 			if (tp->syn_data && icsk->icsk_retransmits == 1)
 				NET_INC_STATS(sock_net(sk),
 					      LINUX_MIB_TCPFASTOPENACTIVEFAIL);
+		} else if (!tp->syn_data && !tp->syn_fastopen) {
+			sk_rethink_txhash(sk);
 		}
 		retry_until = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_syn_retries;
 		syn_set = true;
@@ -213,6 +215,11 @@ static int tcp_write_timeout(struct sock *sk)
 			tcp_mtu_probing(icsk, sk);
 
 			dst_negative_advice(sk);
+		} else if (sk->sk_txhash && sysctl_tcp_rto_txhash_prob > 0) {
+			u32 v = prandom_u32() % 100;
+
+			if (v < sysctl_tcp_rto_txhash_prob)
+				sk_set_txhash(sk);
 		}
 
 		retry_until = net->ipv4.sysctl_tcp_retries2;
Signature · 1 line
2.9.3
#1 lore raw
Quoted 11 lines · Lawrence Brakmo

The current code changes txhash (flowlables) on every retransmitted SYN/ACK, but only after the 2nd retransmitted SYN and only after tcp_retries1 RTO retransmits.

With this patch:
1) txhash is changed with every SYN retransmist
2) adds the option for the txhash to be changed before tcp_retries1 RTO retransmits. A new sysctl tcp_rto_txhash_prob represents the probability that txhash will be changed. The default value is 0 which maintains previous behavior and a value of 100 will always change it.

...

net/ipv4/tcp_timer.c static int tcp_write_timeout(struct sock *sk) · line 223

Quoted 10 lines
net/ipv4/tcp_timer.c +5 -0
@@ -213,6 +215,11 @@ static int tcp_write_timeout(struct sock *sk)
 			tcp_mtu_probing(icsk, sk);
 
 			dst_negative_advice(sk);
+		} else if (sk->sk_txhash && sysctl_tcp_rto_txhash_prob > 0) {
+			u32 v = prandom_u32() % 100;
+
+			if (v < sysctl_tcp_rto_txhash_prob)
+				sk_set_txhash(sk);
 

Write timeouts are rare events and sk_txhash should already be set.

Also prandom_u32_max() is a bit faster (no divide, and even no multiply for 100 which is 5*5*4, compiler can emit 2 lea instructions )

I would suggest not using all these tests and instead be very simple :

 	} else if (prandom_u32_max(100) < sysctl_tcp_rto_txhash_prob) {
		sk_set_txhash(sk);
	}

Finally, adding a new sysctl requires a Documentation update ( Documentation/networking/ip-sysctl.txt )

Thanks.

#2 lore raw

Eric, thank you for comments. V2 should be out shortly.

Thanks!

Quoted 44 lines · On 9/27/16, 9:29 AM, "[email protected] on behalf of Eric Dumazet"…
Quoted 11 lines · Lawrence Brakmo

The current code changes txhash (flowlables) on every retransmitted SYN/ACK, but only after the 2nd retransmitted SYN and only after tcp_retries1 RTO retransmits.

With this patch:
1) txhash is changed with every SYN retransmist
2) adds the option for the txhash to be changed before tcp_retries1 RTO retransmits. A new sysctl tcp_rto_txhash_prob represents the probability that txhash will be changed. The default value is 0 which maintains previous behavior and a value of 100 will always change it.

...

net/ipv4/tcp_timer.c static int tcp_write_timeout(struct sock *sk) · line 223

Quoted 10 lines
net/ipv4/tcp_timer.c +5 -0
@@ -213,6 +215,11 @@ static int tcp_write_timeout(struct sock *sk)
 			tcp_mtu_probing(icsk, sk);
 
 			dst_negative_advice(sk);
+		} else if (sk->sk_txhash && sysctl_tcp_rto_txhash_prob > 0) {
+			u32 v = prandom_u32() % 100;
+
+			if (v < sysctl_tcp_rto_txhash_prob)
+				sk_set_txhash(sk);
 

Write timeouts are rare events and sk_txhash should already be set.

Also prandom_u32_max() is a bit faster (no divide, and even no multiply for 100 which is 5*5*4, compiler can emit 2 lea instructions )

I would suggest not using all these tests and instead be very simple :

	} else if (prandom_u32_max(100) < sysctl_tcp_rto_txhash_prob) {
		sk_set_txhash(sk);
	}

Finally, adding a new sysctl requires a Documentation update ( Documentation/networking/ip-sysctl.txt )

Thanks.