tcp: congestion control refactoring
Subsystems (3)
cover tcp: congestion control refactoring
This patch set refactors the sequence of congestion control, loss recovery, and transmission logic in TCP ack processing.
The design goal is to decouple and sequence them in the following order:
0. ACK accounting: free or tag sent packets [unchanged]
1. loss recovery: identify lost/ecn packets and update congestion state
2. congestion control: up/down cwnd and pacing rate based on (1)
3. transmission: send new or retransmit old based on (1) and (2)
This refactoring makes the cwnd changes more clear because it's done in one place. The packet accounting is also more robust especially for connections that do not support SACK. Patch 1-4 and 6 are refactoring and patch 5 improves TCP performance under reordering.
Yuchung Cheng (6):
tcp: retransmit after recovery processing and congestion control
tcp: move cwnd reduction after recovery state procesing
tcp: new delivery accounting
tcp: refactor pkts acked accounting
tcp: make congestioin control more robust against reordering
tcp: tcp_cong_control helper
include/linux/tcp.h | 1 + net/ipv4/tcp_input.c | 147 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 96 insertions(+), 52 deletions(-)
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 1/6 tcp: retransmit after recovery processing and congestion control
The retransmission and F-RTO transmission currently happen inside recovery state processing (tcp_fastretrans_alert) but before congestion control. This refactoring moves the logic after both s.t. we can determine how much to send (cwnd) before deciding what to send.
--- net/ipv4/tcp_input.c | 58 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 12 deletions(-)
net/ipv4/tcp_input.c +46 -12
@@ -126,6 +126,10 @@ int sysctl_tcp_invalid_ratelimit __read_mostly = HZ/2;#define TCP_REMNANT (TCP_FLAG_FIN|TCP_FLAG_URG|TCP_FLAG_SYN|TCP_FLAG_PSH)#define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH)) +#define REXMIT_NONE 0/* no loss recovery to do */ +#define REXMIT_LOST 1/* retransmit packets marked lost */ +#define REXMIT_NEW 2/* FRTO-style transmit of unsent/new packets */ +/* Adapt the MSS value used to make delayed ack decision to the * real world. */
@@ -2664,7 +2668,8 @@ static void tcp_enter_recovery(struct sock *sk, bool ece_ack)/* Process an ACK in CA_Loss state. Move to CA_Open if lost data are * recovered or spurious. Otherwise retransmits more on partial ACKs. */ -static void tcp_process_loss (struct sock *sk,int flag,bool is_dupack) +static void tcp_process_loss (struct sock *sk,int flag,bool is_dupack, +int *rexmit) {struct tcp_sock *tp =tcp_sk (sk);bool recovered = !before (tp->snd_una, tp->high_seq);
@@ -2686,10 +2691,15 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack) tp->frto =0 ;/* Step 3.a. loss was real */ }else if (flag &FLAG_SND_UNA_ADVANCED && !recovered) { tp->high_seq = tp->snd_nxt; -__tcp_push_pending_frames (sk,tcp_current_mss (sk), -TCP_NAGLE_OFF ); -if (after (tp->snd_nxt, tp->high_seq)) -return ;/* Step 2.b */ +/* Step 2.b. Try send new data (but deferred until cwnd +* is updated in tcp_ack()). Otherwise fall back to +* the conventional recovery. +*/ +if (tcp_send_head (sk) && +after (tcp_wnd_end (tp), tp->snd_nxt)) { + *rexmit =REXMIT_NEW ; +return ; + } tp->frto =0 ; } }
@@ -2708,7 +2718,7 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack)else if (flag &FLAG_SND_UNA_ADVANCED )tcp_reset_reno_sack (tp); } -tcp_xmit_retransmit_queue (sk); + *rexmit =REXMIT_LOST ; }/* Undo during fast recovery after partial ACK. */
@@ -2758,7 +2768,7 @@ static bool tcp_try_undo_partial(struct sock *sk, const int acked,*/ static void tcp_fastretrans_alert (struct sock *sk,const int acked,const int prior_unsacked, -bool is_dupack,int flag) +bool is_dupack,int flag,int *rexmit) {struct inet_connection_sock *icsk =inet_csk (sk);struct tcp_sock *tp =tcp_sk (sk);
@@ -2833,7 +2843,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked, }break ;case TCP_CA_Loss: -tcp_process_loss (sk, flag, is_dupack); +tcp_process_loss (sk, flag, is_dupack, rexmit);if (icsk->icsk_ca_state != TCP_CA_Open && !(flag &FLAG_LOST_RETRANS ))return ;
@@ -2873,7 +2883,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,if (do_lost)tcp_update_scoreboard (sk, fast_rexmit);tcp_cwnd_reduction (sk, prior_unsacked, fast_rexmit, flag); -tcp_xmit_retransmit_queue (sk); + *rexmit =REXMIT_LOST ; }/* Kathleen Nichols' algorithm for tracking the minimum value of
@@ -3508,6 +3518,27 @@ static inline void tcp_in_ack_event(struct sock *sk, u32 flags) icsk->icsk_ca_ops->in_ack_event (sk, flags); } +/* Congestion control has updated the cwnd already. So if we're in +* loss recovery then now we do any new sends (for FRTO) or +* retransmits (for CA_Loss or CA_recovery) that make sense. +*/ +static void tcp_xmit_recovery (struct sock *sk,int rexmit) +{ +struct tcp_sock *tp =tcp_sk (sk); + +if (rexmit ==REXMIT_NONE ) +return ; + +if (unlikely (rexmit ==2 )) { +__tcp_push_pending_frames (sk,tcp_current_mss (sk), +TCP_NAGLE_OFF ); +if (after (tp->snd_nxt, tp->high_seq)) +return ; + tp->frto =0 ; + } +tcp_xmit_retransmit_queue (sk); +} +/* This routine deals with incoming acks, but not outgoing ones. */ static int tcp_ack (struct sock *sk,const struct sk_buff *skb,int flag) {
@@ -3522,6 +3553,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)int prior_packets = tp->packets_out;const int prior_unsacked = tp->packets_out - tp->sacked_out;int acked =0 ;/* Number of packets newly acked */ +int rexmit =REXMIT_NONE ;/* Flag to (re)transmit to recover losses */ sack_state.first_sackt.v64 =0 ;
@@ -3618,7 +3650,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (tcp_ack_is_dubious (sk, flag)) { is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED |FLAG_NOT_DUP ));tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag); + is_dupack, flag, &rexmit); }if (tp->tlp_high_seq)tcp_process_tlp_ack (sk, ack, flag);
@@ -3636,13 +3668,14 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (icsk->icsk_pending ==ICSK_TIME_RETRANS )tcp_schedule_loss_probe (sk);tcp_update_pacing_rate (sk); +tcp_xmit_recovery (sk, rexmit);return 1 ; no_queue:/* If data was DSACKed, see if we can undo a cwnd reduction. */ if (flag &FLAG_DSACKING_ACK )tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag); + is_dupack, flag, &rexmit);/* If this ack opens up a zero window, clear backoff. It was * being used to time the probes, and is probably far higher than * it needs to be for normal retransmission.
@@ -3666,7 +3699,8 @@ old_ack: flag |=tcp_sacktag_write_queue (sk, skb, prior_snd_una, &sack_state);tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag); + is_dupack, flag, &rexmit); +tcp_xmit_recovery (sk, rexmit); }SOCK_DEBUG (sk,"Ack %u before %u:%u\n" , ack, tp->snd_una, tp->snd_nxt);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 2/6 tcp: move cwnd reduction after recovery state procesing
In reply to Yuchung ChengCurrently the cwnd is reduced and increased in various different places. The reduction happens in various places in the recovery state processing (tcp_fastretrans_alert) while the increase happens afterward.
A better sequence is to identify lost packets and update the congestion control state (icsk_ca_state) first. Then base on the new state, up/down the cwnd in one central place. It's more clear to reason cwnd changes.
--- net/ipv4/tcp_input.c | 60 ++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-)
net/ipv4/tcp_input.c +28 -32
@@ -2473,14 +2473,12 @@ static void tcp_init_cwnd_reduction(struct sock *sk)tcp_ecn_queue_cwr (tp); } -static void tcp_cwnd_reduction (struct sock *sk,const int prior_unsacked, -int fast_rexmit,int flag) +static void tcp_cwnd_reduction (struct sock *sk,int newly_acked_sacked, +int flag) {struct tcp_sock *tp =tcp_sk (sk);int sndcnt =0 ;int delta = tp->snd_ssthresh -tcp_packets_in_flight (tp); -int newly_acked_sacked = prior_unsacked - - (tp->packets_out - tp->sacked_out);if (newly_acked_sacked <=0 ||WARN_ON_ONCE (!tp->prior_cwnd))return ;
@@ -2498,7 +2496,8 @@ static void tcp_cwnd_reduction(struct sock *sk, const int prior_unsacked, }else { sndcnt =min (delta, newly_acked_sacked); } - sndcnt =max (sndcnt, (fast_rexmit ?1 :0 )); +/* Force a fast retransmit upon entering fast recovery */ + sndcnt =max (sndcnt, (tp->prr_out ?0 :1 )); tp->snd_cwnd =tcp_packets_in_flight (tp) + sndcnt; }
@@ -2543,7 +2542,7 @@ static void tcp_try_keep_open(struct sock *sk) } } -static void tcp_try_to_open (struct sock *sk,int flag,const int prior_unsacked) +static void tcp_try_to_open (struct sock *sk,int flag) {struct tcp_sock *tp =tcp_sk (sk);
@@ -2557,8 +2556,6 @@ static void tcp_try_to_open(struct sock *sk, int flag, const int prior_unsacked)if (inet_csk (sk)->icsk_ca_state !=TCP_CA_CWR ) {tcp_try_keep_open (sk); - }else { -tcp_cwnd_reduction (sk, prior_unsacked,0 , flag); } }
@@ -2722,8 +2719,7 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack, }/* Undo during fast recovery after partial ACK. */ -static bool tcp_try_undo_partial (struct sock *sk,const int acked, -const int prior_unsacked,int flag) +static bool tcp_try_undo_partial (struct sock *sk,const int acked) {struct tcp_sock *tp =tcp_sk (sk);
@@ -2738,10 +2734,8 @@ static bool tcp_try_undo_partial(struct sock *sk, const int acked,* can undo. Otherwise we clock out new packets but do not * mark more packets lost or retransmit more. */ -if (tp->retrans_out) { -tcp_cwnd_reduction (sk, prior_unsacked,0 , flag); +if (tp->retrans_out)return true; - }if (!tcp_any_retrans_done (sk)) tp->retrans_stamp =0 ;
@@ -2760,21 +2754,21 @@ static bool tcp_try_undo_partial(struct sock *sk, const int acked,* taking into account both packets sitting in receiver's buffer and * packets lost by network. * -* Besides that it does CWND reduction, when packet loss is detected -* and changes state of machine. +* Besides that it updates the congestion state when packet loss or ECN +* is detected. But it does not reduce the cwnd, it is done by the +* congestion control later. * * It does _not_ decide what to send, it is made in function * tcp_xmit_retransmit_queue(). */ static void tcp_fastretrans_alert (struct sock *sk,const int acked, -const int prior_unsacked, -bool is_dupack,int flag,int *rexmit) +bool is_dupack,int *ack_flag,int *rexmit) {struct inet_connection_sock *icsk =inet_csk (sk);struct tcp_sock *tp =tcp_sk (sk); +int fast_rexmit =0 , flag = *ack_flag;bool do_lost = is_dupack || ((flag &FLAG_DATA_SACKED ) && (tcp_fackets_out (tp) > tp->reordering)); -int fast_rexmit =0 ;if (WARN_ON (!tp->packets_out && tp->sacked_out)) tp->sacked_out =0 ;
@@ -2821,8 +2815,10 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,/* Use RACK to detect loss */ if (sysctl_tcp_recovery &TCP_RACK_LOST_RETRANS && -tcp_rack_mark_lost (sk)) +tcp_rack_mark_lost (sk)) { flag |=FLAG_LOST_RETRANS ; + *ack_flag |=FLAG_LOST_RETRANS ; + }/* E. Process state. */ switch (icsk->icsk_ca_state) {
@@ -2831,7 +2827,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,if (tcp_is_reno (tp) && is_dupack)tcp_add_reno_sack (sk); }else { -if (tcp_try_undo_partial (sk, acked, prior_unsacked, flag)) +if (tcp_try_undo_partial (sk, acked))return ;/* Partial ACK arrived. Force fast retransmit. */ do_lost = tcp_is_reno(tp) ||
@@ -2860,7 +2856,7 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,tcp_try_undo_dsack (sk);if (!tcp_time_to_recover (sk, flag)) { -tcp_try_to_open (sk, flag, prior_unsacked); +tcp_try_to_open (sk, flag);return ; }
@@ -2882,7 +2878,6 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,if (do_lost)tcp_update_scoreboard (sk, fast_rexmit); -tcp_cwnd_reduction (sk, prior_unsacked, fast_rexmit, flag); *rexmit =REXMIT_LOST ; }
@@ -3308,9 +3303,6 @@ static inline bool tcp_ack_is_dubious(const struct sock *sk, const int flag)/* Decide wheather to run the increase function of congestion control. */ static inline bool tcp_may_raise_cwnd (const struct sock *sk,const int flag) { -if (tcp_in_cwnd_reduction (sk)) -return false; -/* If reordering is high then always grow cwnd whenever data is * delivered regardless of its ordering. Otherwise stay conservative * and only grow cwnd on in-order delivery (RFC5681). A stretched ACK w/
@@ -3553,6 +3545,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)int prior_packets = tp->packets_out;const int prior_unsacked = tp->packets_out - tp->sacked_out;int acked =0 ;/* Number of packets newly acked */ +int acked_sacked;/* Number of packets newly acked or sacked */ int rexmit =REXMIT_NONE ;/* Flag to (re)transmit to recover losses */ sack_state.first_sackt.v64 =0 ;
@@ -3649,15 +3642,20 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (tcp_ack_is_dubious (sk, flag)) { is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED |FLAG_NOT_DUP )); -tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag, &rexmit); +tcp_fastretrans_alert (sk, acked, is_dupack, &flag, &rexmit); }if (tp->tlp_high_seq)tcp_process_tlp_ack (sk, ack, flag); + acked_sacked = prior_unsacked - (tp->packets_out - tp->sacked_out);/* Advance cwnd if state allows */ -if (tcp_may_raise_cwnd (sk, flag)) +if (tcp_in_cwnd_reduction (sk)) { +/* Reduce cwnd if state mandates */ +tcp_cwnd_reduction (sk, acked_sacked, flag); + }else if (tcp_may_raise_cwnd (sk, flag)) { +/* Advance cwnd if state allows */ tcp_cong_avoid (sk, ack, acked); + }if ((flag &FLAG_FORWARD_PROGRESS ) || !(flag &FLAG_NOT_DUP )) {struct dst_entry *dst =__sk_dst_get (sk);
@@ -3674,8 +3672,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) no_queue:/* If data was DSACKed, see if we can undo a cwnd reduction. */ if (flag &FLAG_DSACKING_ACK ) -tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag, &rexmit); +tcp_fastretrans_alert (sk, acked, is_dupack, &flag, &rexmit);/* If this ack opens up a zero window, clear backoff. It was * being used to time the probes, and is probably far higher than * it needs to be for normal retransmission.
@@ -3698,8 +3695,7 @@ old_ack:if (TCP_SKB_CB (skb)->sacked) { flag |=tcp_sacktag_write_queue (sk, skb, prior_snd_una, &sack_state); -tcp_fastretrans_alert (sk, acked, prior_unsacked, - is_dupack, flag, &rexmit); +tcp_fastretrans_alert (sk, acked, is_dupack, &flag, &rexmit);tcp_xmit_recovery (sk, rexmit); }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 3/6 tcp: new delivery accounting
In reply to Yuchung ChengThis patch changes the accounting of how many packets are newly acked or sacked when the sender receives an ACK.
The current approach basically computes
newly_acked_sacked = (prior_packets - prior_sacked) -
(tp->packets_out - tp->sacked_out)
where prior_packets and prior_sacked out are snapshot at the beginning of the ACK processing.
The new approach tracks the delivery information via a new TCP state variable "delivered" which monotically increases as new packets are delivered in order or out-of-order.
The reason for this change is that the current approach is brittle that produces negative or inaccurate estimate.
1) For non-SACK connections, an ACK that advances the SND.UNA could reset the DUPACK counters (tp->sacked_out) in tcp_process_loss() or tcp_fastretrans_alert(). This inflates the inflight suddenly and causes under-estimate or even negative estimate. Here is a real example:
before after (processing ACK)
packets_out 75 73 sacked_out 23 0 ca state Loss Open
The old approach computes (75-23) - (73 - 0) = -21 delivered while the new approach computes 1 delivered since it considers the 2nd-24th packets are delivered OOO.
2) MSS change would re-count packets_out and sacked_out so the estimate is in-accurate and can even become negative. E.g., the inflight is doubled when MSS is halved.
3) Spurious retransmission signaled by DSACK is not accounted
The new approach is simpler and more robust. For SACK connections, tp->delivered increments as packets are being acked or sacked in SACK and ACK processing.
For non-sack connections, it's done in tcp_remove_reno_sacks() and tcp_add_reno_sack(). When an ACK advances the SND.UNA, tp->delivered is incremented by the number of packets ACKed (less the current number of DUPACKs received plus one packet hole). Upon receiving a DUPACK, tp->delivered is incremented assuming one out-of-order packet is delivered.
Upon receiving a DSACK, tp->delivered is incremtened assuming one retransmission is delivered in tcp_sacktag_write_queue().
--- include/linux/tcp.h | 1 + net/ipv4/tcp_input.c | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-)
include/linux/tcp.h +1 -0
@@ -256,6 +256,7 @@ struct tcp_sock {u32 prr_delivered;/* Number of newly delivered packets to * receiver in Recovery. */ u32 prr_out;/* Total number of pkts sent during Recovery. */ +u32 delivered;/* Total data packets delivered incl. rexmits */ u32 rcv_wnd;/* Current receiver window */ u32 write_seq;/* Tail(+1) of data held in tcp send buffer */
net/ipv4/tcp_input.c +15 -6
@@ -1214,6 +1214,7 @@ static u8 tcp_sacktag_one(struct sock *sk, sacked |=TCPCB_SACKED_ACKED ; state->flag |=FLAG_DATA_SACKED ; tp->sacked_out += pcount; + tp->delivered += pcount;/* Out-of-order packets delivered */ fack_count += pcount;
@@ -1825,8 +1826,12 @@ static void tcp_check_reno_reordering(struct sock *sk, const int addend)static void tcp_add_reno_sack (struct sock *sk) {struct tcp_sock *tp =tcp_sk (sk); +u32 prior_sacked = tp->sacked_out; + tp->sacked_out++;tcp_check_reno_reordering (sk,0 ); +if (tp->sacked_out > prior_sacked) + tp->delivered++;/* Some out-of-order packet is delivered */ tcp_verify_left_out (tp); }
@@ -1838,6 +1843,7 @@ static void tcp_remove_reno_sacks(struct sock *sk, int acked)if (acked >0 ) {/* One ACK acked hole. The rest eat duplicate ACKs. */ + tp->delivered +=max_t (int, acked - tp->sacked_out,1 );if (acked -1 >= tp->sacked_out) tp->sacked_out =0 ;else
@@ -3158,10 +3164,13 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets, flag |=FLAG_ORIG_SACK_ACKED ; } -if (sacked &TCPCB_SACKED_ACKED ) +if (sacked &TCPCB_SACKED_ACKED ) { tp->sacked_out -= acked_pcount; -else if (tcp_is_sack (tp) && !tcp_skb_spurious_retrans (tp, skb)) -tcp_rack_advance (tp, &skb->skb_mstamp, sacked); + }else if (tcp_is_sack (tp)) { + tp->delivered += acked_pcount; +if (!tcp_skb_spurious_retrans (tp, skb)) +tcp_rack_advance (tp, &skb->skb_mstamp, sacked); + }if (sacked &TCPCB_LOST ) tp->lost_out -= acked_pcount;
@@ -3543,9 +3552,9 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)bool is_dupack = false;u32 prior_fackets;int prior_packets = tp->packets_out; -const int prior_unsacked = tp->packets_out - tp->sacked_out; +u32 prior_delivered = tp->delivered;int acked =0 ;/* Number of packets newly acked */ -int acked_sacked;/* Number of packets newly acked or sacked */ +u32 acked_sacked;/* Number of packets newly acked or sacked */ int rexmit =REXMIT_NONE ;/* Flag to (re)transmit to recover losses */ sack_state.first_sackt.v64 =0 ;
@@ -3647,7 +3656,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (tp->tlp_high_seq)tcp_process_tlp_ack (sk, ack, flag); - acked_sacked = prior_unsacked - (tp->packets_out - tp->sacked_out); + acked_sacked = tp->delivered - prior_delivered;/* Advance cwnd if state allows */ if (tcp_in_cwnd_reduction (sk)) {/* Reduce cwnd if state mandates */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 4/6 tcp: refactor pkts acked accounting
In reply to Yuchung ChengA small refactoring that gets number of packets cumulatively acked from tcp_clean_rtx_queue() directly.
--- net/ipv4/tcp_input.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/ipv4/tcp_input.c +3 -4
@@ -3106,7 +3106,7 @@ static void tcp_ack_tstamp(struct sock *sk, struct sk_buff *skb,* arrived at the other end. */ static int tcp_clean_rtx_queue (struct sock *sk,int prior_fackets, -u32 prior_snd_una, +u32 prior_snd_una,int *acked,struct tcp_sacktag_state *sack) {const struct inet_connection_sock *icsk =inet_csk (sk);
@@ -3279,6 +3279,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets, } }#endif + *acked = pkts_acked;return flag; }
@@ -3644,10 +3645,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag) goto no_queue;/* See if we can take anything off of the retransmit queue. */ - acked = tp->packets_out; - flag |=tcp_clean_rtx_queue (sk, prior_fackets, prior_snd_una, + flag |=tcp_clean_rtx_queue (sk, prior_fackets, prior_snd_una, &acked, &sack_state); - acked -= tp->packets_out;if (tcp_ack_is_dubious (sk, flag)) { is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED |FLAG_NOT_DUP ));
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 5/6 tcp: make congestioin control more robust against reordering
In reply to Yuchung ChengThis change enables congestion control to update cwnd based on not only packet cumulatively acked but also packets delivered out-of-order. This makes congestion control robust against packet reordering because it may raise cwnd as long as packets are being delivered once reordering has been detected (i.e., it only cares the amount of packets delivered, not the ordering among them).
--- net/ipv4/tcp_input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_input.c +1 -1
@@ -3662,7 +3662,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)tcp_cwnd_reduction (sk, acked_sacked, flag); }else if (tcp_may_raise_cwnd (sk, flag)) {/* Advance cwnd if state allows */ -tcp_cong_avoid (sk, ack, acked); +tcp_cong_avoid (sk, ack, acked_sacked); }if ((flag &FLAG_FORWARD_PROGRESS ) || !(flag &FLAG_NOT_DUP )) {
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 6/6 tcp: tcp_cong_control helper
In reply to Yuchung ChengRefactor and consolidate cwnd and rate updates into a new function tcp_cong_control().
--- net/ipv4/tcp_input.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
net/ipv4/tcp_input.c +19 -12
@@ -3325,6 +3325,24 @@ static inline bool tcp_may_raise_cwnd(const struct sock *sk, const int flag)return flag &FLAG_DATA_ACKED ; } +/* The "ultimate" congestion control function that aims to replace the rigid +* cwnd increase and decrease control (tcp_cong_avoid,tcp_*cwnd_reduction). +* It's called toward the end of processing an ACK with precise rate +* information. All transmission or retransmission are delayed afterwards. +*/ +static void tcp_cong_control (struct sock *sk,u32 ack,u32 acked_sacked, +int flag) +{ +if (tcp_in_cwnd_reduction (sk)) { +/* Reduce cwnd if state mandates */ +tcp_cwnd_reduction (sk, acked_sacked, flag); + }else if (tcp_may_raise_cwnd (sk, flag)) { +/* Advance cwnd if state allows */ +tcp_cong_avoid (sk, ack, acked_sacked); + } +tcp_update_pacing_rate (sk); +} +/* Check that window update is acceptable. * The function assumes that snd_una<=ack<=snd_next. */
@@ -3555,7 +3573,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)int prior_packets = tp->packets_out;u32 prior_delivered = tp->delivered;int acked =0 ;/* Number of packets newly acked */ -u32 acked_sacked;/* Number of packets newly acked or sacked */ int rexmit =REXMIT_NONE ;/* Flag to (re)transmit to recover losses */ sack_state.first_sackt.v64 =0 ;
@@ -3655,16 +3672,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (tp->tlp_high_seq)tcp_process_tlp_ack (sk, ack, flag); - acked_sacked = tp->delivered - prior_delivered; -/* Advance cwnd if state allows */ -if (tcp_in_cwnd_reduction (sk)) { -/* Reduce cwnd if state mandates */ -tcp_cwnd_reduction (sk, acked_sacked, flag); - }else if (tcp_may_raise_cwnd (sk, flag)) { -/* Advance cwnd if state allows */ -tcp_cong_avoid (sk, ack, acked_sacked); - } -if ((flag &FLAG_FORWARD_PROGRESS ) || !(flag &FLAG_NOT_DUP )) {struct dst_entry *dst =__sk_dst_get (sk);if (dst)
@@ -3673,7 +3680,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)if (icsk->icsk_pending ==ICSK_TIME_RETRANS )tcp_schedule_loss_probe (sk); -tcp_update_pacing_rate (sk); +tcp_cong_control (sk, ack, tp->delivered - prior_delivered, flag);tcp_xmit_recovery (sk, rexmit);return 1 ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
I am really sorry I missed the net-next close announcement. Will re-submit once it's re-opened
David Miller
maintainerFrom: Yuchung Cheng <[email protected]>
Date: Thu, 14 Jan 2016 15:43:28 -0800
Quoted 9 lines
This patch set refactors the sequence of congestion control, loss recovery, and transmission logic in TCP ack processing.
The design goal is to decouple and sequence them in the following order:
0. ACK accounting: free or tag sent packets [unchanged]
1. loss recovery: identify lost/ecn packets and update congestion state
Quoted 8 lines
2. congestion control: up/down cwnd and pacing rate based on (1)
3. transmission: send new or retransmit old based on (1) and (2)
This refactoring makes the cwnd changes more clear because it's done in one place. The packet accounting is also more robust especially for connections that do not support SACK. Patch 1-4 and 6 are refactoring and patch 5 improves TCP performance under reordering.
As the net-next tree is closed right now, please resubmit this series when it opens back up.
Thank you.