Skip to content

Commit df92c83

Browse files
nealcardwelldavem330
authored andcommitted
tcp: fix xmit timer to only be reset if data ACKed/SACKed
Fix a TCP loss recovery performance bug raised recently on the netdev list, in two threads: (i) July 26, 2017: netdev thread "TCP fast retransmit issues" (ii) July 26, 2017: netdev thread: "[PATCH V2 net-next] TLP: Don't reschedule PTO when there's one outstanding TLP retransmission" The basic problem is that incoming TCP packets that did not indicate forward progress could cause the xmit timer (TLP or RTO) to be rearmed and pushed back in time. In certain corner cases this could result in the following problems noted in these threads: - Repeated ACKs coming in with bogus SACKs corrupted by middleboxes could cause TCP to repeatedly schedule TLPs forever. We kept sending TLPs after every ~200ms, which elicited bogus SACKs, which caused more TLPs, ad infinitum; we never fired an RTO to fill in the holes. - Incoming data segments could, in some cases, cause us to reschedule our RTO or TLP timer further out in time, for no good reason. This could cause repeated inbound data to result in stalls in outbound data, in the presence of packet loss. This commit fixes these bugs by changing the TLP and RTO ACK processing to: (a) Only reschedule the xmit timer once per ACK. (b) Only reschedule the xmit timer if tcp_clean_rtx_queue() deems the ACK indicates sufficient forward progress (a packet was cumulatively ACKed, or we got a SACK for a packet that was sent before the most recent retransmit of the write queue head). This brings us back into closer compliance with the RFCs, since, as the comment for tcp_rearm_rto() notes, we should only restart the RTO timer after forward progress on the connection. Previously we were restarting the xmit timer even in these cases where there was no forward progress. As a side benefit, this commit simplifies and speeds up the TCP timer arming logic. We had been calling inet_csk_reset_xmit_timer() three times on normal ACKs that cumulatively acknowledged some data: 1) Once near the top of tcp_ack() to switch from TLP timer to RTO: if (icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) tcp_rearm_rto(sk); 2) Once in tcp_clean_rtx_queue(), to update the RTO: if (flag & FLAG_ACKED) { tcp_rearm_rto(sk); 3) Once in tcp_ack() after tcp_fastretrans_alert() to switch from RTO to TLP: if (icsk->icsk_pending == ICSK_TIME_RETRANS) tcp_schedule_loss_probe(sk); This commit, by only rescheduling the xmit timer once per ACK, simplifies the code and reduces CPU overhead. This commit was tested in an A/B test with Google web server traffic. SNMP stats and request latency metrics were within noise levels, substantiating that for normal web traffic patterns this is a rare issue. This commit was also tested with packetdrill tests to verify that it fixes the timer behavior in the corner cases discussed in the netdev threads mentioned above. This patch is a bug fix patch intended to be queued for -stable relases. Fixes: 6ba8a3b ("tcp: Tail loss probe (TLP)") Reported-by: Klavs Klavsen <kl@vsen.dk> Reported-by: Mao Wenan <maowenan@huawei.com> Signed-off-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: Nandita Dukkipati <nanditad@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a281581 commit df92c83

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

‎net/ipv4/tcp_input.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ int sysctl_tcp_invalid_ratelimit __read_mostly = HZ/2;
107107
#define FLAG_ORIG_SACK_ACKED 0x200 /* Never retransmitted data are (s)acked */
108108
#define FLAG_SND_UNA_ADVANCED 0x400 /* Snd_una was changed (!= FLAG_DATA_ACKED) */
109109
#define FLAG_DSACKING_ACK 0x800 /* SACK blocks contained D-SACK info */
110+
#define FLAG_SET_XMIT_TIMER 0x1000 /* Set TLP or RTO timer */
110111
#define FLAG_SACK_RENEGING 0x2000 /* snd_una advanced to a sacked seq */
111112
#define FLAG_UPDATE_TS_RECENT 0x4000 /* tcp_replace_ts_recent() */
112113
#define FLAG_NO_CHALLENGE_ACK 0x8000 /* do not call tcp_send_challenge_ack() */
@@ -3016,6 +3017,13 @@ void tcp_rearm_rto(struct sock *sk)
30163017
}
30173018
}
30183019

3020+
/* Try to schedule a loss probe; if that doesn't work, then schedule an RTO. */
3021+
static void tcp_set_xmit_timer(struct sock *sk)
3022+
{
3023+
if (!tcp_schedule_loss_probe(sk))
3024+
tcp_rearm_rto(sk);
3025+
}
3026+
30193027
/* If we get here, the whole TSO packet has not been acked. */
30203028
static u32 tcp_tso_acked(struct sock *sk, struct sk_buff *skb)
30213029
{
@@ -3177,7 +3185,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
31773185
ca_rtt_us, sack->rate);
31783186

31793187
if (flag & FLAG_ACKED) {
3180-
tcp_rearm_rto(sk);
3188+
flag |= FLAG_SET_XMIT_TIMER; /* set TLP or RTO timer */
31813189
if (unlikely(icsk->icsk_mtup.probe_size &&
31823190
!after(tp->mtu_probe.probe_seq_end, tp->snd_una))) {
31833191
tcp_mtup_probe_success(sk);
@@ -3205,7 +3213,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
32053213
* after when the head was last (re)transmitted. Otherwise the
32063214
* timeout may continue to extend in loss recovery.
32073215
*/
3208-
tcp_rearm_rto(sk);
3216+
flag |= FLAG_SET_XMIT_TIMER; /* set TLP or RTO timer */
32093217
}
32103218

32113219
if (icsk->icsk_ca_ops->pkts_acked) {
@@ -3577,9 +3585,6 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
35773585
if (after(ack, tp->snd_nxt))
35783586
goto invalid_ack;
35793587

3580-
if (icsk->icsk_pending == ICSK_TIME_LOSS_PROBE)
3581-
tcp_rearm_rto(sk);
3582-
35833588
if (after(ack, prior_snd_una)) {
35843589
flag |= FLAG_SND_UNA_ADVANCED;
35853590
icsk->icsk_retransmits = 0;
@@ -3644,18 +3649,20 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
36443649
flag |= tcp_clean_rtx_queue(sk, prior_fackets, prior_snd_una, &acked,
36453650
&sack_state);
36463651

3652+
if (tp->tlp_high_seq)
3653+
tcp_process_tlp_ack(sk, ack, flag);
3654+
/* If needed, reset TLP/RTO timer; RACK may later override this. */
3655+
if (flag & FLAG_SET_XMIT_TIMER)
3656+
tcp_set_xmit_timer(sk);
3657+
36473658
if (tcp_ack_is_dubious(sk, flag)) {
36483659
is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED | FLAG_NOT_DUP));
36493660
tcp_fastretrans_alert(sk, acked, is_dupack, &flag, &rexmit);
36503661
}
3651-
if (tp->tlp_high_seq)
3652-
tcp_process_tlp_ack(sk, ack, flag);
36533662

36543663
if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP))
36553664
sk_dst_confirm(sk);
36563665

3657-
if (icsk->icsk_pending == ICSK_TIME_RETRANS)
3658-
tcp_schedule_loss_probe(sk);
36593666
delivered = tp->delivered - delivered; /* freshly ACKed or SACKed */
36603667
lost = tp->lost - lost; /* freshly marked lost */
36613668
tcp_rate_gen(sk, delivered, lost, sack_state.rate);

‎net/ipv4/tcp_output.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,21 +2380,12 @@ bool tcp_schedule_loss_probe(struct sock *sk)
23802380
u32 rtt = usecs_to_jiffies(tp->srtt_us >> 3);
23812381
u32 timeout, rto_delta_us;
23822382

2383-
/* No consecutive loss probes. */
2384-
if (WARN_ON(icsk->icsk_pending == ICSK_TIME_LOSS_PROBE)) {
2385-
tcp_rearm_rto(sk);
2386-
return false;
2387-
}
23882383
/* Don't do any loss probe on a Fast Open connection before 3WHS
23892384
* finishes.
23902385
*/
23912386
if (tp->fastopen_rsk)
23922387
return false;
23932388

2394-
/* TLP is only scheduled when next timer event is RTO. */
2395-
if (icsk->icsk_pending != ICSK_TIME_RETRANS)
2396-
return false;
2397-
23982389
/* Schedule a loss probe in 2*RTT for SACK capable connections
23992390
* in Open state, that are either limited by cwnd or application.
24002391
*/

0 commit comments

Comments
 (0)