tcp: remove code from tcp_create_openreq_child()
Subsystems (3)
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
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
@@ -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
PATCH 2/11 tcp: move icsk_rto init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
PATCH 3/11 tcp: do not clear packets_out in tcp_create_openreq_child()
In reply to Eric DumazetNew 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
@@ -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
PATCH 4/11 tcp: do not clear srtt_us in tcp_create_openreq_child
In reply to Eric DumazetAll 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
@@ -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
PATCH 5/11 tcp: move mdev_us init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
PATCH 6/11 tcp: move snd_cwnd & snd_cwnd_cnt init to tcp_disconnect()
In reply to Eric DumazetPassive 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
@@ -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
@@ -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
PATCH 7/11 tcp: do not clear urg_data in tcp_create_openreq_child
In reply to Eric DumazetAll 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
@@ -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
PATCH 8/11 tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
PATCH 9/11 tcp: move app_limited init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
PATCH 10/11 tcp: move tp->rack init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
PATCH 11/11 tcp: move rx_opt & syn_data_acked init to tcp_disconnect()
In reply to Eric DumazetIf 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
@@ -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
@@ -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
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, sincetcp_disconnect()operation is very unlikely.Eric Dumazet (11):
tcp: do not setsnd_ssthreshintcp_create_openreq_child()
tcp: moveicsk_rtoinit totcp_disconnect()
tcp: do not clearpackets_outintcp_create_openreq_child()
tcp: do not clearsrtt_usintcp_create_openreq_child
tcp: movemdev_usinit totcp_disconnect()
tcp: movesnd_cwnd&snd_cwnd_cntinit totcp_disconnect()
tcp: do not clearurg_dataintcp_create_openreq_child
tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init
totcp_disconnect()
tcp: moveapp_limitedinit totcp_disconnect()
tcp: movetp->rackinit totcp_disconnect()
tcp: moverx_opt&syn_data_ackedinit totcp_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
Soheil Hassas Yeganeh
Acked-byQuoted 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, sincetcp_disconnect()operation is very unlikely.Eric Dumazet (11):
tcp: do not setsnd_ssthreshintcp_create_openreq_child()
tcp: moveicsk_rtoinit totcp_disconnect()
tcp: do not clearpackets_outintcp_create_openreq_child()
tcp: do not clearsrtt_usintcp_create_openreq_child
tcp: movemdev_usinit totcp_disconnect()
tcp: movesnd_cwnd&snd_cwnd_cntinit totcp_disconnect()
tcp: do not clearurg_dataintcp_create_openreq_child
tcp: move retrans_out,sacked_out,tlp_high_seq,last_oow_ack_time init
totcp_disconnect()
tcp: moveapp_limitedinit totcp_disconnect()
tcp: movetp->rackinit totcp_disconnect()
tcp: moverx_opt&syn_data_ackedinit totcp_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!
Acked-by Yuchung Cheng <[email protected]>
Thank you very much, Eric, for the nice code removal!
Quoted 2 lines
Quoted 2 lines
2.20.1.321.g9e740568ce-goog
David Miller
maintainerFrom: 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, sincetcp_disconnect()operation is very unlikely.
Series applied, thanks Eric.