Skip to contentSkip to conversation

tcp: remove code from tcp_create_openreq_child()

PATCH In review Eric Dumazet 4 participants 15 messages Jan 17, 2019 – Jan 18, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover tcp: remove code from tcp_create_openreq_child()

tcp_create_openreq_child() is essentially cloning a listener, then must initialize some fields that can not be inherited.

Listeners are either fresh sockets, or sockets that came through tcp_disconnect() after a session that dirtied many fields.

By moving code to tcp_disconnect(), we can shorten time taken to create a clone, since tcp_disconnect() operation is very unlikely.

Eric Dumazet (11):
tcp: do not set snd_ssthresh in tcp_create_openreq_child()
tcp: move icsk_rto init to tcp_disconnect()
tcp: do not clear packets_out in tcp_create_openreq_child()
tcp: do not clear srtt_us in tcp_create_openreq_child
tcp: move mdev_us init to tcp_disconnect()
tcp: move snd_cwnd & snd_cwnd_cnt init to tcp_disconnect()
tcp: do not clear urg_data in tcp_create_openreq_child
tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init
to tcp_disconnect()
tcp: move app_limited init to tcp_disconnect()
tcp: move tp->rack init to tcp_disconnect()
tcp: move rx_opt & syn_data_acked init to tcp_disconnect()

 net/ipv4/tcp.c           | 21 ++++++++++++++++++++-
 net/ipv4/tcp_minisocks.c | 34 ----------------------------------
 2 files changed, 20 insertions(+), 35 deletions(-)
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#1 lore raw

PATCH 1/11 tcp: do not set snd_ssthresh in tcp_create_openreq_child()

New sockets get the field set to TCP_INFINITE_SSTHRESH in tcp_init_sock() In case a socket had this field changed and transitions to TCP_LISTEN state, tcp_disconnect() also makes sure snd_ssthresh is set to TCP_INFINITE_SSTHRESH.

So a listener has this field set to TCP_INFINITE_SSTHRESH already.

---
 net/ipv4/tcp_minisocks.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv4/tcp_minisocks.c +0 -1
index 12affb7864d981a6494059232c4965aaee756803..0cffa5937b1261984c3986b107220af495264437 100644
@@ -488,7 +488,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newtp->packets_out = 0;
 	newtp->retrans_out = 0;
 	newtp->sacked_out = 0;
-	newtp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
 	newtp->tlp_high_seq = 0;
 	newtp->lsndtime = tcp_jiffies32;
 	newsk->sk_txhash = treq->txhash;
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#2 lore raw

PATCH 2/11 tcp: move icsk_rto init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure a listener always has its icsk_rto field set to TCP_TIMEOUT_INIT, we do not need to rewrite this field after a new clone is created.

tcp_disconnect() is very seldom used in real applications.

---
 net/ipv4/tcp.c           | 1 +
 net/ipv4/tcp_minisocks.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -0
index 27e2f6837062374baaea267a8788b9fd91db25ff..9d8131f95a9732fb873c8a8b2c918657e1dade30 100644
@@ -2579,6 +2579,7 @@ int tcp_disconnect(struct sock *sk, int flags)
 	icsk->icsk_backoff = 0;
 	tp->snd_cwnd = 2;
 	icsk->icsk_probes_out = 0;
+	icsk->icsk_rto = TCP_TIMEOUT_INIT;
 	tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
 	tp->snd_cwnd_cnt = 0;
 	tp->window_clamp = 0;
net/ipv4/tcp_minisocks.c +0 -1
index 0cffa5937b1261984c3986b107220af495264437..9799f1d32e44f4c733b41c4d8fc7739970ccca28 100644
@@ -482,7 +482,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newtp->srtt_us = 0;
 	newtp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);
 	minmax_reset(&newtp->rtt_min, tcp_jiffies32, ~0U);
-	newicsk->icsk_rto = TCP_TIMEOUT_INIT;
 	newicsk->icsk_ack.lrcvtime = tcp_jiffies32;
 
 	newtp->packets_out = 0;
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#3 lore raw

PATCH 3/11 tcp: do not clear packets_out in tcp_create_openreq_child()

In reply to Eric Dumazet

New sockets have this field cleared, and tcp_disconnect() calls tcp_write_queue_purge() which among other things also clear tp->packets_out

So a listener is guaranteed to have this field cleared.

---
 net/ipv4/tcp_minisocks.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv4/tcp_minisocks.c +0 -1
index 9799f1d32e44f4c733b41c4d8fc7739970ccca28..830e4eb558f8861fb3813c35b215425a53cacf62 100644
@@ -484,7 +484,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	minmax_reset(&newtp->rtt_min, tcp_jiffies32, ~0U);
 	newicsk->icsk_ack.lrcvtime = tcp_jiffies32;
 
-	newtp->packets_out = 0;
 	newtp->retrans_out = 0;
 	newtp->sacked_out = 0;
 	newtp->tlp_high_seq = 0;
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#4 lore raw

PATCH 4/11 tcp: do not clear srtt_us in tcp_create_openreq_child

In reply to Eric Dumazet

All listeners have this field cleared already, since tcp_disconnect() clears it and newly created sockets have also a zero value here.

So a clone will inherit a zero value here.

---
 net/ipv4/tcp_minisocks.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv4/tcp_minisocks.c +0 -1
index 830e4eb558f8861fb3813c35b215425a53cacf62..977ad1c0cccad564fa111556ad0a0f3af4534381 100644
@@ -479,7 +479,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 
 	tcp_init_wl(newtp, treq->rcv_isn);
 
-	newtp->srtt_us = 0;
 	newtp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);
 	minmax_reset(&newtp->rtt_min, tcp_jiffies32, ~0U);
 	newicsk->icsk_ack.lrcvtime = tcp_jiffies32;
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#5 lore raw

PATCH 5/11 tcp: move mdev_us init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure a listener always has its mdev_us field set to TCP_TIMEOUT_INIT, we do not need to rewrite this field after a new clone is created.

tcp_disconnect() is very seldom used in real applications.

---
 net/ipv4/tcp.c           | 1 +
 net/ipv4/tcp_minisocks.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -0
index 9d8131f95a9732fb873c8a8b2c918657e1dade30..731b1c6e88a992e51b9e303803444dc255d888fa 100644
@@ -2572,6 +2572,7 @@ int tcp_disconnect(struct sock *sk, int flags)
 	sk->sk_shutdown = 0;
 	sock_reset_flag(sk, SOCK_DONE);
 	tp->srtt_us = 0;
+	tp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);
 	tp->rcv_rtt_last_tsecr = 0;
 	tp->write_seq += tp->max_window + 2;
 	if (tp->write_seq == 0)
net/ipv4/tcp_minisocks.c +0 -1
index 977ad1c0cccad564fa111556ad0a0f3af4534381..35906b44e2cfa767f760773d0321a992114fee5b 100644
@@ -479,7 +479,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 
 	tcp_init_wl(newtp, treq->rcv_isn);
 
-	newtp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);
 	minmax_reset(&newtp->rtt_min, tcp_jiffies32, ~0U);
 	newicsk->icsk_ack.lrcvtime = tcp_jiffies32;
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#6 lore raw

PATCH 6/11 tcp: move snd_cwnd & snd_cwnd_cnt init to tcp_disconnect()

In reply to Eric Dumazet

Passive connections can inherit proper value by cloning, if we make sure all listeners have the proper values there.

tcp_disconnect() was setting snd_cwnd to 2, which seems quite obsolete since IW10 adoption.

Also remove an obsolete comment.

---
 net/ipv4/tcp.c           | 2 +-
 net/ipv4/tcp_minisocks.c | 8 --------
 2 files changed, 1 insertion(+), 9 deletions(-)
net/ipv4/tcp.c +1 -1
index 731b1c6e88a992e51b9e303803444dc255d888fa..3f99ad92eaedb2364e339842365f553fca8922e1 100644
@@ -2578,10 +2578,10 @@ int tcp_disconnect(struct sock *sk, int flags)
 	if (tp->write_seq == 0)
 		tp->write_seq = 1;
 	icsk->icsk_backoff = 0;
-	tp->snd_cwnd = 2;
 	icsk->icsk_probes_out = 0;
 	icsk->icsk_rto = TCP_TIMEOUT_INIT;
 	tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
+	tp->snd_cwnd = TCP_INIT_CWND;
 	tp->snd_cwnd_cnt = 0;
 	tp->window_clamp = 0;
 	tp->delivered_ce = 0;
net/ipv4/tcp_minisocks.c +0 -8
index 35906b44e2cfa767f760773d0321a992114fee5b..ca96e7da99b6e450a5e881e280ad84137a57409d 100644
@@ -490,14 +490,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newtp->last_oow_ack_time = 0;
 	newtp->total_retrans = req->num_retrans;
 
-	/* So many TCP implementations out there (incorrectly) count the
-	 * initial SYN frame in their delayed-ACK and congestion control
-	 * algorithms that we must have the following bandaid to talk
-	 * efficiently to them.  -DaveM
-	 */
-	newtp->snd_cwnd = TCP_INIT_CWND;
-	newtp->snd_cwnd_cnt = 0;
-
 	/* There's a bubble in the pipe until at least the first ACK. */
 	newtp->app_limited = ~0U;
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#7 lore raw

PATCH 7/11 tcp: do not clear urg_data in tcp_create_openreq_child

In reply to Eric Dumazet

All listeners have this field cleared already, since tcp_disconnect() clears it and newly created sockets have also a zero value here.

So a clone will inherit a zero value here.

---
 net/ipv4/tcp_minisocks.c | 2 --
 1 file changed, 2 deletions(-)
net/ipv4/tcp_minisocks.c +0 -2
index ca96e7da99b6e450a5e881e280ad84137a57409d..2747aa72b8e2b5c190c2c3e68a7dea04ee97dcac 100644
@@ -501,8 +501,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newtp->rx_opt.dsack = 0;
 	newtp->rx_opt.num_sacks = 0;
 
-	newtp->urg_data = 0;
-
 	if (sock_flag(newsk, SOCK_KEEPOPEN))
 		inet_csk_reset_keepalive_timer(newsk,
 					       keepalive_time_when(newtp));
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#8 lore raw

PATCH 8/11 tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure all listeners have these fields cleared, then a clone will also inherit zero values.

---
 net/ipv4/tcp.c           | 4 ++++
 net/ipv4/tcp_minisocks.c | 4 ----
 2 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/tcp.c +4 -0
index 3f99ad92eaedb2364e339842365f553fca8922e1..551ad8604bea0cb459805165bb216a99fd3bd8e2 100644
@@ -2605,6 +2605,10 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tp->duplicate_sack[0].end_seq = 0;
 	tp->dsack_dups = 0;
 	tp->reord_seen = 0;
+	tp->retrans_out = 0;
+	tp->sacked_out = 0;
+	tp->tlp_high_seq = 0;
+	tp->last_oow_ack_time = 0;
 
 	/* Clean up fastopen related fields */
 	tcp_free_fastopen_req(tp);
net/ipv4/tcp_minisocks.c +0 -4
index 2747aa72b8e2b5c190c2c3e68a7dea04ee97dcac..29fba13849a79695b3f62a989b27157b57caedfb 100644
@@ -482,12 +482,8 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	minmax_reset(&newtp->rtt_min, tcp_jiffies32, ~0U);
 	newicsk->icsk_ack.lrcvtime = tcp_jiffies32;
 
-	newtp->retrans_out = 0;
-	newtp->sacked_out = 0;
-	newtp->tlp_high_seq = 0;
 	newtp->lsndtime = tcp_jiffies32;
 	newsk->sk_txhash = treq->txhash;
-	newtp->last_oow_ack_time = 0;
 	newtp->total_retrans = req->num_retrans;
 
 	/* There's a bubble in the pipe until at least the first ACK. */
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#9 lore raw

PATCH 9/11 tcp: move app_limited init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure all listeners have app_limited set to ~0U, then a clone will also inherit proper initial value.

---
 net/ipv4/tcp.c           | 3 +++
 net/ipv4/tcp_minisocks.c | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
net/ipv4/tcp.c +3 -0
index 551ad8604bea0cb459805165bb216a99fd3bd8e2..5f15fcc9612ae6b6964ca15660dbb7eb8cd71d83 100644
@@ -2609,6 +2609,9 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tp->sacked_out = 0;
 	tp->tlp_high_seq = 0;
 	tp->last_oow_ack_time = 0;
+	/* There's a bubble in the pipe until at least the first ACK. */
+	tp->app_limited = ~0U;
+
 
 	/* Clean up fastopen related fields */
 	tcp_free_fastopen_req(tp);
net/ipv4/tcp_minisocks.c +0 -3
index 29fba13849a79695b3f62a989b27157b57caedfb..13f3c6444efa63b63fe38bf4606c91fa962ec584 100644
@@ -486,9 +486,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newsk->sk_txhash = treq->txhash;
 	newtp->total_retrans = req->num_retrans;
 
-	/* There's a bubble in the pipe until at least the first ACK. */
-	newtp->app_limited = ~0U;
-
 	tcp_init_xmit_timers(newsk);
 	newtp->write_seq = newtp->pushed_seq = treq->snt_isn + 1;
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#10 lore raw

PATCH 10/11 tcp: move tp->rack init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure all listeners have proper tp->rack value, then a clone will also inherit proper initial value.

Note that fresh sockets init tp->rack from tcp_init_sock()

---
 net/ipv4/tcp.c           | 6 ++++++
 net/ipv4/tcp_minisocks.c | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/tcp.c +6 -0
index 5f15fcc9612ae6b6964ca15660dbb7eb8cd71d83..2348199e6cee9b644177b1d5158680359fa2b57d 100644
@@ -2611,6 +2611,12 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tp->last_oow_ack_time = 0;
 	/* There's a bubble in the pipe until at least the first ACK. */
 	tp->app_limited = ~0U;
+	tp->rack.mstamp = 0;
+	tp->rack.advanced = 0;
+	tp->rack.reo_wnd_steps = 1;
+	tp->rack.last_delivered = 0;
+	tp->rack.reo_wnd_persist = 0;
+	tp->rack.dsack_seen = 0;
 
 
 	/* Clean up fastopen related fields */
net/ipv4/tcp_minisocks.c +0 -6
index 13f3c6444efa63b63fe38bf4606c91fa962ec584..27e11eb4164ca18da0e939eb928b5b2442f300dd 100644
@@ -535,12 +535,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	newtp->fastopen_req = NULL;
 	newtp->fastopen_rsk = NULL;
 	newtp->syn_data_acked = 0;
-	newtp->rack.mstamp = 0;
-	newtp->rack.advanced = 0;
-	newtp->rack.reo_wnd_steps = 1;
-	newtp->rack.last_delivered = 0;
-	newtp->rack.reo_wnd_persist = 0;
-	newtp->rack.dsack_seen = 0;
 
 	__TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS);
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
#11 lore raw

PATCH 11/11 tcp: move rx_opt & syn_data_acked init to tcp_disconnect()

In reply to Eric Dumazet

If we make sure all listeners have these fields cleared, then a clone will also inherit zero values.

---
 net/ipv4/tcp.c           | 4 ++++
 net/ipv4/tcp_minisocks.c | 6 ------
 2 files changed, 4 insertions(+), 6 deletions(-)
net/ipv4/tcp.c +4 -0
index 2348199e6cee9b644177b1d5158680359fa2b57d..541bdb9f81d791ca84c7f03d9caf15d84066c32e 100644
@@ -2617,6 +2617,10 @@ int tcp_disconnect(struct sock *sk, int flags)
 	tp->rack.last_delivered = 0;
 	tp->rack.reo_wnd_persist = 0;
 	tp->rack.dsack_seen = 0;
+	tp->syn_data_acked = 0;
+	tp->rx_opt.saw_tstamp = 0;
+	tp->rx_opt.dsack = 0;
+	tp->rx_opt.num_sacks = 0;
 
 
 	/* Clean up fastopen related fields */
net/ipv4/tcp_minisocks.c +0 -6
index 27e11eb4164ca18da0e939eb928b5b2442f300dd..182595e2d40ff5b48cd6d095d4bd97b4cb26d3c0 100644
@@ -489,11 +489,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	tcp_init_xmit_timers(newsk);
 	newtp->write_seq = newtp->pushed_seq = treq->snt_isn + 1;
 
-	newtp->rx_opt.saw_tstamp = 0;
-
-	newtp->rx_opt.dsack = 0;
-	newtp->rx_opt.num_sacks = 0;
-
 	if (sock_flag(newsk, SOCK_KEEPOPEN))
 		inet_csk_reset_keepalive_timer(newsk,
 					       keepalive_time_when(newtp));
@@ -534,7 +529,6 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,
 	tcp_ecn_openreq_child(newtp, req);
 	newtp->fastopen_req = NULL;
 	newtp->fastopen_rsk = NULL;
-	newtp->syn_data_acked = 0;
 
 	__TCP_INC_STATS(sock_net(sk), TCP_MIB_PASSIVEOPENS);
 
Signature · 1 line
2.20.1.321.g9e740568ce-goog
Acked-by on the v1 series
#12 lore raw
In reply to Eric Dumazet
Quoted 25 lines · Eric Dumazet

tcp_create_openreq_child() is essentially cloning a listener, then must initialize some fields that can not be inherited.

Listeners are either fresh sockets, or sockets that came through tcp_disconnect() after a session that dirtied many fields.

By moving code to tcp_disconnect(), we can shorten time taken to create a clone, since tcp_disconnect() operation is very unlikely.

Eric Dumazet (11):
tcp: do not set snd_ssthresh in tcp_create_openreq_child()
tcp: move icsk_rto init to tcp_disconnect()
tcp: do not clear packets_out in tcp_create_openreq_child()
tcp: do not clear srtt_us in tcp_create_openreq_child
tcp: move mdev_us init to tcp_disconnect()
tcp: move snd_cwnd & snd_cwnd_cnt init to tcp_disconnect()
tcp: do not clear urg_data in tcp_create_openreq_child
tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init
to tcp_disconnect()
tcp: move app_limited init to tcp_disconnect()
tcp: move tp->rack init to tcp_disconnect()
tcp: move rx_opt & syn_data_acked init to tcp_disconnect()

Quoted 5 lines
 net/ipv4/tcp.c           | 21 ++++++++++++++++++++-
 net/ipv4/tcp_minisocks.c | 34 ----------------------------------
 2 files changed, 20 insertions(+), 35 deletions(-)

--

Entire patch set looks great to me!

Quoted 2 lines

2.20.1.321.g9e740568ce-goog

#13 lore raw
Quoted 27 lines · Yuchung Cheng
Quoted 25 lines · Eric Dumazet

tcp_create_openreq_child() is essentially cloning a listener, then must initialize some fields that can not be inherited.

Listeners are either fresh sockets, or sockets that came through tcp_disconnect() after a session that dirtied many fields.

By moving code to tcp_disconnect(), we can shorten time taken to create a clone, since tcp_disconnect() operation is very unlikely.

Eric Dumazet (11):
tcp: do not set snd_ssthresh in tcp_create_openreq_child()
tcp: move icsk_rto init to tcp_disconnect()
tcp: do not clear packets_out in tcp_create_openreq_child()
tcp: do not clear srtt_us in tcp_create_openreq_child
tcp: move mdev_us init to tcp_disconnect()
tcp: move snd_cwnd & snd_cwnd_cnt init to tcp_disconnect()
tcp: do not clear urg_data in tcp_create_openreq_child
tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init
to tcp_disconnect()
tcp: move app_limited init to tcp_disconnect()
tcp: move tp->rack init to tcp_disconnect()
tcp: move rx_opt & syn_data_acked init to tcp_disconnect()

Quoted 8 lines
Quoted 5 lines
 net/ipv4/tcp.c           | 21 ++++++++++++++++++++-
 net/ipv4/tcp_minisocks.c | 34 ----------------------------------
 2 files changed, 20 insertions(+), 35 deletions(-)

--

Entire patch set looks great to me!

Thank you very much, Eric, for the nice code removal!

Quoted 2 lines
Quoted 2 lines

2.20.1.321.g9e740568ce-goog

maintainer
#14 lore raw
In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Thu, 17 Jan 2019 11:23:31 -0800

Quoted 9 lines

tcp_create_openreq_child() is essentially cloning a listener, then must initialize some fields that can not be inherited.

Listeners are either fresh sockets, or sockets that came through tcp_disconnect() after a session that dirtied many fields.

By moving code to tcp_disconnect(), we can shorten time taken to create a clone, since tcp_disconnect() operation is very unlikely.

Series applied, thanks Eric.