aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_input.c
diff options
context:
space:
mode:
authorYuchung Cheng <ycheng@google.com>2017-11-08 16:01:27 -0500
committerDavid S. Miller <davem@davemloft.net>2017-11-11 04:53:16 -0500
commit737ff314563ca27f044f9a3a041e9d42491ef7ce (patch)
treea95677bca04ad68e0c1a60fa343d59d24934e669 /net/ipv4/tcp_input.c
parent713bafea92920103cd3d361657406cf04d0e22dd (diff)
tcp: use sequence distance to detect reordering
Replace the reordering distance measurement in packet unit with sequence based approach. Previously it trackes the number of "packets" toward the forward ACK (i.e. highest sacked sequence)in a state variable "fackets_out". Precisely measuring reordering degree on packet distance has not much benefit, as the degree constantly changes by factors like path, load, and congestion window. It is also complicated and prone to arcane bugs. This patch replaces with sequence-based approach that's much simpler. Signed-off-by: Yuchung Cheng <ycheng@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Neal Cardwell <ncardwell@google.com> Reviewed-by: Soheil Hassas Yeganeh <soheil@google.com> Reviewed-by: Priyaranjan Jha <priyarjha@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_input.c')
-rw-r--r--net/ipv4/tcp_input.c155
1 files changed, 68 insertions, 87 deletions
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 487e181cff86..94d729be42a9 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -849,39 +849,39 @@ static void tcp_dsack_seen(struct tcp_sock *tp)
849 tp->rack.dsack_seen = 1; 849 tp->rack.dsack_seen = 1;
850} 850}
851 851
852static void tcp_update_reordering(struct sock *sk, const int metric, 852/* It's reordering when higher sequence was delivered (i.e. sacked) before
853 const int ts) 853 * some lower never-retransmitted sequence ("low_seq"). The maximum reordering
854 * distance is approximated in full-mss packet distance ("reordering").
855 */
856static void tcp_check_sack_reordering(struct sock *sk, const u32 low_seq,
857 const int ts)
854{ 858{
855 struct tcp_sock *tp = tcp_sk(sk); 859 struct tcp_sock *tp = tcp_sk(sk);
856 int mib_idx; 860 const u32 mss = tp->mss_cache;
861 u32 fack, metric;
857 862
858 if (WARN_ON_ONCE(metric < 0)) 863 fack = tcp_highest_sack_seq(tp);
864 if (!before(low_seq, fack))
859 return; 865 return;
860 866
861 if (metric > tp->reordering) { 867 metric = fack - low_seq;
862 tp->reordering = min(sock_net(sk)->ipv4.sysctl_tcp_max_reordering, metric); 868 if ((metric > tp->reordering * mss) && mss) {
863
864#if FASTRETRANS_DEBUG > 1 869#if FASTRETRANS_DEBUG > 1
865 pr_debug("Disorder%d %d %u f%u s%u rr%d\n", 870 pr_debug("Disorder%d %d %u f%u s%u rr%d\n",
866 tp->rx_opt.sack_ok, inet_csk(sk)->icsk_ca_state, 871 tp->rx_opt.sack_ok, inet_csk(sk)->icsk_ca_state,
867 tp->reordering, 872 tp->reordering,
868 tp->fackets_out, 873 0,
869 tp->sacked_out, 874 tp->sacked_out,
870 tp->undo_marker ? tp->undo_retrans : 0); 875 tp->undo_marker ? tp->undo_retrans : 0);
871#endif 876#endif
877 tp->reordering = min_t(u32, (metric + mss - 1) / mss,
878 sock_net(sk)->ipv4.sysctl_tcp_max_reordering);
872 } 879 }
873 880
874 tp->rack.reord = 1; 881 tp->rack.reord = 1;
875
876 /* This exciting event is worth to be remembered. 8) */ 882 /* This exciting event is worth to be remembered. 8) */
877 if (ts) 883 NET_INC_STATS(sock_net(sk),
878 mib_idx = LINUX_MIB_TCPTSREORDER; 884 ts ? LINUX_MIB_TCPTSREORDER : LINUX_MIB_TCPSACKREORDER);
879 else if (tcp_is_reno(tp))
880 mib_idx = LINUX_MIB_TCPRENOREORDER;
881 else
882 mib_idx = LINUX_MIB_TCPSACKREORDER;
883
884 NET_INC_STATS(sock_net(sk), mib_idx);
885} 885}
886 886
887/* This must be called before lost_out is incremented */ 887/* This must be called before lost_out is incremented */
@@ -1097,8 +1097,7 @@ static bool tcp_check_dsack(struct sock *sk, const struct sk_buff *ack_skb,
1097} 1097}
1098 1098
1099struct tcp_sacktag_state { 1099struct tcp_sacktag_state {
1100 int reord; 1100 u32 reord;
1101 int fack_count;
1102 /* Timestamps for earliest and latest never-retransmitted segment 1101 /* Timestamps for earliest and latest never-retransmitted segment
1103 * that was SACKed. RTO needs the earliest RTT to stay conservative, 1102 * that was SACKed. RTO needs the earliest RTT to stay conservative,
1104 * but congestion control should still get an accurate delay signal. 1103 * but congestion control should still get an accurate delay signal.
@@ -1174,15 +1173,15 @@ static u8 tcp_sacktag_one(struct sock *sk,
1174 u64 xmit_time) 1173 u64 xmit_time)
1175{ 1174{
1176 struct tcp_sock *tp = tcp_sk(sk); 1175 struct tcp_sock *tp = tcp_sk(sk);
1177 int fack_count = state->fack_count;
1178 1176
1179 /* Account D-SACK for retransmitted packet. */ 1177 /* Account D-SACK for retransmitted packet. */
1180 if (dup_sack && (sacked & TCPCB_RETRANS)) { 1178 if (dup_sack && (sacked & TCPCB_RETRANS)) {
1181 if (tp->undo_marker && tp->undo_retrans > 0 && 1179 if (tp->undo_marker && tp->undo_retrans > 0 &&
1182 after(end_seq, tp->undo_marker)) 1180 after(end_seq, tp->undo_marker))
1183 tp->undo_retrans--; 1181 tp->undo_retrans--;
1184 if (sacked & TCPCB_SACKED_ACKED) 1182 if ((sacked & TCPCB_SACKED_ACKED) &&
1185 state->reord = min(fack_count, state->reord); 1183 before(start_seq, state->reord))
1184 state->reord = start_seq;
1186 } 1185 }
1187 1186
1188 /* Nothing to do; acked frame is about to be dropped (was ACKed). */ 1187 /* Nothing to do; acked frame is about to be dropped (was ACKed). */
@@ -1208,9 +1207,10 @@ static u8 tcp_sacktag_one(struct sock *sk,
1208 * which was in hole. It is reordering. 1207 * which was in hole. It is reordering.
1209 */ 1208 */
1210 if (before(start_seq, 1209 if (before(start_seq,
1211 tcp_highest_sack_seq(tp))) 1210 tcp_highest_sack_seq(tp)) &&
1212 state->reord = min(fack_count, 1211 before(start_seq, state->reord))
1213 state->reord); 1212 state->reord = start_seq;
1213
1214 if (!after(end_seq, tp->high_seq)) 1214 if (!after(end_seq, tp->high_seq))
1215 state->flag |= FLAG_ORIG_SACK_ACKED; 1215 state->flag |= FLAG_ORIG_SACK_ACKED;
1216 if (state->first_sackt == 0) 1216 if (state->first_sackt == 0)
@@ -1229,15 +1229,10 @@ static u8 tcp_sacktag_one(struct sock *sk,
1229 tp->sacked_out += pcount; 1229 tp->sacked_out += pcount;
1230 tp->delivered += pcount; /* Out-of-order packets delivered */ 1230 tp->delivered += pcount; /* Out-of-order packets delivered */
1231 1231
1232 fack_count += pcount;
1233
1234 /* Lost marker hint past SACKed? Tweak RFC3517 cnt */ 1232 /* Lost marker hint past SACKed? Tweak RFC3517 cnt */
1235 if (tp->lost_skb_hint && 1233 if (tp->lost_skb_hint &&
1236 before(start_seq, TCP_SKB_CB(tp->lost_skb_hint)->seq)) 1234 before(start_seq, TCP_SKB_CB(tp->lost_skb_hint)->seq))
1237 tp->lost_cnt_hint += pcount; 1235 tp->lost_cnt_hint += pcount;
1238
1239 if (fack_count > tp->fackets_out)
1240 tp->fackets_out = fack_count;
1241 } 1236 }
1242 1237
1243 /* D-SACK. We can detect redundant retransmission in S|R and plain R 1238 /* D-SACK. We can detect redundant retransmission in S|R and plain R
@@ -1484,7 +1479,6 @@ static struct sk_buff *tcp_shift_skb_data(struct sock *sk, struct sk_buff *skb,
1484 } 1479 }
1485 1480
1486out: 1481out:
1487 state->fack_count += pcount;
1488 return prev; 1482 return prev;
1489 1483
1490noop: 1484noop:
@@ -1563,8 +1557,6 @@ static struct sk_buff *tcp_sacktag_walk(struct sk_buff *skb, struct sock *sk,
1563 tcp_highest_sack_seq(tp))) 1557 tcp_highest_sack_seq(tp)))
1564 tcp_advance_highest_sack(sk, skb); 1558 tcp_advance_highest_sack(sk, skb);
1565 } 1559 }
1566
1567 state->fack_count += tcp_skb_pcount(skb);
1568 } 1560 }
1569 return skb; 1561 return skb;
1570} 1562}
@@ -1575,7 +1567,6 @@ static struct sk_buff *tcp_sacktag_bsearch(struct sock *sk,
1575{ 1567{
1576 struct rb_node *parent, **p = &sk->tcp_rtx_queue.rb_node; 1568 struct rb_node *parent, **p = &sk->tcp_rtx_queue.rb_node;
1577 struct sk_buff *skb; 1569 struct sk_buff *skb;
1578 int unack_bytes;
1579 1570
1580 while (*p) { 1571 while (*p) {
1581 parent = *p; 1572 parent = *p;
@@ -1588,12 +1579,6 @@ static struct sk_buff *tcp_sacktag_bsearch(struct sock *sk,
1588 p = &parent->rb_right; 1579 p = &parent->rb_right;
1589 continue; 1580 continue;
1590 } 1581 }
1591
1592 state->fack_count = 0;
1593 unack_bytes = TCP_SKB_CB(skb)->seq - tcp_sk(sk)->snd_una;
1594 if (state->mss_now && unack_bytes > 0)
1595 state->fack_count = unack_bytes / state->mss_now;
1596
1597 return skb; 1582 return skb;
1598 } 1583 }
1599 return NULL; 1584 return NULL;
@@ -1651,13 +1636,10 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb,
1651 int first_sack_index; 1636 int first_sack_index;
1652 1637
1653 state->flag = 0; 1638 state->flag = 0;
1654 state->reord = tp->packets_out; 1639 state->reord = tp->snd_nxt;
1655 1640
1656 if (!tp->sacked_out) { 1641 if (!tp->sacked_out)
1657 if (WARN_ON(tp->fackets_out))
1658 tp->fackets_out = 0;
1659 tcp_highest_sack_reset(sk); 1642 tcp_highest_sack_reset(sk);
1660 }
1661 1643
1662 found_dup_sack = tcp_check_dsack(sk, ack_skb, sp_wire, 1644 found_dup_sack = tcp_check_dsack(sk, ack_skb, sp_wire,
1663 num_sacks, prior_snd_una); 1645 num_sacks, prior_snd_una);
@@ -1729,7 +1711,6 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb,
1729 } 1711 }
1730 1712
1731 state->mss_now = tcp_current_mss(sk); 1713 state->mss_now = tcp_current_mss(sk);
1732 state->fack_count = 0;
1733 skb = NULL; 1714 skb = NULL;
1734 i = 0; 1715 i = 0;
1735 1716
@@ -1787,7 +1768,6 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb,
1787 skb = tcp_highest_sack(sk); 1768 skb = tcp_highest_sack(sk);
1788 if (!skb) 1769 if (!skb)
1789 break; 1770 break;
1790 state->fack_count = tp->fackets_out;
1791 cache++; 1771 cache++;
1792 goto walk; 1772 goto walk;
1793 } 1773 }
@@ -1802,7 +1782,6 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb,
1802 skb = tcp_highest_sack(sk); 1782 skb = tcp_highest_sack(sk);
1803 if (!skb) 1783 if (!skb)
1804 break; 1784 break;
1805 state->fack_count = tp->fackets_out;
1806 } 1785 }
1807 skb = tcp_sacktag_skip(skb, sk, state, start_seq); 1786 skb = tcp_sacktag_skip(skb, sk, state, start_seq);
1808 1787
@@ -1822,9 +1801,8 @@ advance_sp:
1822 for (j = 0; j < used_sacks; j++) 1801 for (j = 0; j < used_sacks; j++)
1823 tp->recv_sack_cache[i++] = sp[j]; 1802 tp->recv_sack_cache[i++] = sp[j];
1824 1803
1825 if ((state->reord < tp->fackets_out) && 1804 if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss || tp->undo_marker)
1826 ((inet_csk(sk)->icsk_ca_state != TCP_CA_Loss) || tp->undo_marker)) 1805 tcp_check_sack_reordering(sk, state->reord, 0);
1827 tcp_update_reordering(sk, tp->fackets_out - state->reord, 0);
1828 1806
1829 tcp_verify_left_out(tp); 1807 tcp_verify_left_out(tp);
1830out: 1808out:
@@ -1862,8 +1840,13 @@ static bool tcp_limit_reno_sacked(struct tcp_sock *tp)
1862static void tcp_check_reno_reordering(struct sock *sk, const int addend) 1840static void tcp_check_reno_reordering(struct sock *sk, const int addend)
1863{ 1841{
1864 struct tcp_sock *tp = tcp_sk(sk); 1842 struct tcp_sock *tp = tcp_sk(sk);
1865 if (tcp_limit_reno_sacked(tp)) 1843
1866 tcp_update_reordering(sk, tp->packets_out + addend, 0); 1844 if (!tcp_limit_reno_sacked(tp))
1845 return;
1846
1847 tp->reordering = min_t(u32, tp->packets_out + addend,
1848 sock_net(sk)->ipv4.sysctl_tcp_max_reordering);
1849 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRENOREORDER);
1867} 1850}
1868 1851
1869/* Emulate SACKs for SACKless connection: account for a new dupack. */ 1852/* Emulate SACKs for SACKless connection: account for a new dupack. */
@@ -1909,7 +1892,6 @@ void tcp_clear_retrans(struct tcp_sock *tp)
1909 tp->lost_out = 0; 1892 tp->lost_out = 0;
1910 tp->undo_marker = 0; 1893 tp->undo_marker = 0;
1911 tp->undo_retrans = -1; 1894 tp->undo_retrans = -1;
1912 tp->fackets_out = 0;
1913 tp->sacked_out = 0; 1895 tp->sacked_out = 0;
1914} 1896}
1915 1897
@@ -1959,7 +1941,6 @@ void tcp_enter_loss(struct sock *sk)
1959 if (is_reneg) { 1941 if (is_reneg) {
1960 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSACKRENEGING); 1942 NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPSACKRENEGING);
1961 tp->sacked_out = 0; 1943 tp->sacked_out = 0;
1962 tp->fackets_out = 0;
1963 } 1944 }
1964 tcp_clear_all_retrans_hints(tp); 1945 tcp_clear_all_retrans_hints(tp);
1965 1946
@@ -2026,11 +2007,6 @@ static bool tcp_check_sack_reneging(struct sock *sk, int flag)
2026 return false; 2007 return false;
2027} 2008}
2028 2009
2029static inline int tcp_fackets_out(const struct tcp_sock *tp)
2030{
2031 return tcp_is_reno(tp) ? tp->sacked_out + 1 : tp->fackets_out;
2032}
2033
2034/* Heurestics to calculate number of duplicate ACKs. There's no dupACKs 2010/* Heurestics to calculate number of duplicate ACKs. There's no dupACKs
2035 * counter when SACK is enabled (without SACK, sacked_out is used for 2011 * counter when SACK is enabled (without SACK, sacked_out is used for
2036 * that purpose). 2012 * that purpose).
@@ -2701,15 +2677,15 @@ static void tcp_process_loss(struct sock *sk, int flag, bool is_dupack,
2701} 2677}
2702 2678
2703/* Undo during fast recovery after partial ACK. */ 2679/* Undo during fast recovery after partial ACK. */
2704static bool tcp_try_undo_partial(struct sock *sk, const int acked) 2680static bool tcp_try_undo_partial(struct sock *sk, u32 prior_snd_una)
2705{ 2681{
2706 struct tcp_sock *tp = tcp_sk(sk); 2682 struct tcp_sock *tp = tcp_sk(sk);
2707 2683
2708 if (tp->undo_marker && tcp_packet_delayed(tp)) { 2684 if (tp->undo_marker && tcp_packet_delayed(tp)) {
2709 /* Plain luck! Hole if filled with delayed 2685 /* Plain luck! Hole if filled with delayed
2710 * packet, rather than with a retransmit. 2686 * packet, rather than with a retransmit. Check reordering.
2711 */ 2687 */
2712 tcp_update_reordering(sk, tcp_fackets_out(tp) + acked, 1); 2688 tcp_check_sack_reordering(sk, prior_snd_una, 1);
2713 2689
2714 /* We are getting evidence that the reordering degree is higher 2690 /* We are getting evidence that the reordering degree is higher
2715 * than we realized. If there are no retransmits out then we 2691 * than we realized. If there are no retransmits out then we
@@ -2745,6 +2721,14 @@ static void tcp_rack_identify_loss(struct sock *sk, int *ack_flag)
2745 } 2721 }
2746} 2722}
2747 2723
2724static bool tcp_force_fast_retransmit(struct sock *sk)
2725{
2726 struct tcp_sock *tp = tcp_sk(sk);
2727
2728 return after(tcp_highest_sack_seq(tp),
2729 tp->snd_una + tp->reordering * tp->mss_cache);
2730}
2731
2748/* Process an event, which can update packets-in-flight not trivially. 2732/* Process an event, which can update packets-in-flight not trivially.
2749 * Main goal of this function is to calculate new estimate for left_out, 2733 * Main goal of this function is to calculate new estimate for left_out,
2750 * taking into account both packets sitting in receiver's buffer and 2734 * taking into account both packets sitting in receiver's buffer and
@@ -2757,19 +2741,17 @@ static void tcp_rack_identify_loss(struct sock *sk, int *ack_flag)
2757 * It does _not_ decide what to send, it is made in function 2741 * It does _not_ decide what to send, it is made in function
2758 * tcp_xmit_retransmit_queue(). 2742 * tcp_xmit_retransmit_queue().
2759 */ 2743 */
2760static void tcp_fastretrans_alert(struct sock *sk, const int acked, 2744static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una,
2761 bool is_dupack, int *ack_flag, int *rexmit) 2745 bool is_dupack, int *ack_flag, int *rexmit)
2762{ 2746{
2763 struct inet_connection_sock *icsk = inet_csk(sk); 2747 struct inet_connection_sock *icsk = inet_csk(sk);
2764 struct tcp_sock *tp = tcp_sk(sk); 2748 struct tcp_sock *tp = tcp_sk(sk);
2765 int fast_rexmit = 0, flag = *ack_flag; 2749 int fast_rexmit = 0, flag = *ack_flag;
2766 bool do_lost = is_dupack || ((flag & FLAG_DATA_SACKED) && 2750 bool do_lost = is_dupack || ((flag & FLAG_DATA_SACKED) &&
2767 (tcp_fackets_out(tp) > tp->reordering)); 2751 tcp_force_fast_retransmit(sk));
2768 2752
2769 if (!tp->packets_out && tp->sacked_out) 2753 if (!tp->packets_out && tp->sacked_out)
2770 tp->sacked_out = 0; 2754 tp->sacked_out = 0;
2771 if (!tp->sacked_out && tp->fackets_out)
2772 tp->fackets_out = 0;
2773 2755
2774 /* Now state machine starts. 2756 /* Now state machine starts.
2775 * A. ECE, hence prohibit cwnd undoing, the reduction is required. */ 2757 * A. ECE, hence prohibit cwnd undoing, the reduction is required. */
@@ -2816,11 +2798,11 @@ static void tcp_fastretrans_alert(struct sock *sk, const int acked,
2816 if (tcp_is_reno(tp) && is_dupack) 2798 if (tcp_is_reno(tp) && is_dupack)
2817 tcp_add_reno_sack(sk); 2799 tcp_add_reno_sack(sk);
2818 } else { 2800 } else {
2819 if (tcp_try_undo_partial(sk, acked)) 2801 if (tcp_try_undo_partial(sk, prior_snd_una))
2820 return; 2802 return;
2821 /* Partial ACK arrived. Force fast retransmit. */ 2803 /* Partial ACK arrived. Force fast retransmit. */
2822 do_lost = tcp_is_reno(tp) || 2804 do_lost = tcp_is_reno(tp) ||
2823 tcp_fackets_out(tp) > tp->reordering; 2805 tcp_force_fast_retransmit(sk);
2824 } 2806 }
2825 if (tcp_try_undo_dsack(sk)) { 2807 if (tcp_try_undo_dsack(sk)) {
2826 tcp_try_keep_open(sk); 2808 tcp_try_keep_open(sk);
@@ -3030,15 +3012,15 @@ static void tcp_ack_tstamp(struct sock *sk, struct sk_buff *skb,
3030 * is before the ack sequence we can discard it as it's confirmed to have 3012 * is before the ack sequence we can discard it as it's confirmed to have
3031 * arrived at the other end. 3013 * arrived at the other end.
3032 */ 3014 */
3033static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets, 3015static int tcp_clean_rtx_queue(struct sock *sk, u32 prior_fack,
3034 u32 prior_snd_una, int *acked, 3016 u32 prior_snd_una,
3035 struct tcp_sacktag_state *sack) 3017 struct tcp_sacktag_state *sack)
3036{ 3018{
3037 const struct inet_connection_sock *icsk = inet_csk(sk); 3019 const struct inet_connection_sock *icsk = inet_csk(sk);
3038 u64 first_ackt, last_ackt; 3020 u64 first_ackt, last_ackt;
3039 struct tcp_sock *tp = tcp_sk(sk); 3021 struct tcp_sock *tp = tcp_sk(sk);
3040 u32 prior_sacked = tp->sacked_out; 3022 u32 prior_sacked = tp->sacked_out;
3041 u32 reord = tp->packets_out; 3023 u32 reord = tp->snd_nxt; /* lowest acked un-retx un-sacked seq */
3042 struct sk_buff *skb, *next; 3024 struct sk_buff *skb, *next;
3043 bool fully_acked = true; 3025 bool fully_acked = true;
3044 long sack_rtt_us = -1L; 3026 long sack_rtt_us = -1L;
@@ -3053,6 +3035,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3053 3035
3054 for (skb = skb_rb_first(&sk->tcp_rtx_queue); skb; skb = next) { 3036 for (skb = skb_rb_first(&sk->tcp_rtx_queue); skb; skb = next) {
3055 struct tcp_skb_cb *scb = TCP_SKB_CB(skb); 3037 struct tcp_skb_cb *scb = TCP_SKB_CB(skb);
3038 const u32 start_seq = scb->seq;
3056 u8 sacked = scb->sacked; 3039 u8 sacked = scb->sacked;
3057 u32 acked_pcount; 3040 u32 acked_pcount;
3058 3041
@@ -3083,7 +3066,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3083 first_ackt = last_ackt; 3066 first_ackt = last_ackt;
3084 3067
3085 last_in_flight = TCP_SKB_CB(skb)->tx.in_flight; 3068 last_in_flight = TCP_SKB_CB(skb)->tx.in_flight;
3086 reord = min(pkts_acked, reord); 3069 if (before(start_seq, reord))
3070 reord = start_seq;
3087 if (!after(scb->end_seq, tp->high_seq)) 3071 if (!after(scb->end_seq, tp->high_seq))
3088 flag |= FLAG_ORIG_SACK_ACKED; 3072 flag |= FLAG_ORIG_SACK_ACKED;
3089 } 3073 }
@@ -3161,15 +3145,12 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3161 int delta; 3145 int delta;
3162 3146
3163 /* Non-retransmitted hole got filled? That's reordering */ 3147 /* Non-retransmitted hole got filled? That's reordering */
3164 if (reord < prior_fackets && reord <= tp->fackets_out) 3148 if (before(reord, prior_fack))
3165 tcp_update_reordering(sk, tp->fackets_out - reord, 0); 3149 tcp_check_sack_reordering(sk, reord, 0);
3166 3150
3167 delta = prior_sacked - tp->sacked_out; 3151 delta = prior_sacked - tp->sacked_out;
3168 tp->lost_cnt_hint -= min(tp->lost_cnt_hint, delta); 3152 tp->lost_cnt_hint -= min(tp->lost_cnt_hint, delta);
3169 } 3153 }
3170
3171 tp->fackets_out -= min(pkts_acked, tp->fackets_out);
3172
3173 } else if (skb && rtt_update && sack_rtt_us >= 0 && 3154 } else if (skb && rtt_update && sack_rtt_us >= 0 &&
3174 sack_rtt_us > tcp_stamp_us_delta(tp->tcp_mstamp, skb->skb_mstamp)) { 3155 sack_rtt_us > tcp_stamp_us_delta(tp->tcp_mstamp, skb->skb_mstamp)) {
3175 /* Do not re-arm RTO if the sack RTT is measured from data sent 3156 /* Do not re-arm RTO if the sack RTT is measured from data sent
@@ -3210,7 +3191,6 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3210 } 3191 }
3211 } 3192 }
3212#endif 3193#endif
3213 *acked = pkts_acked;
3214 return flag; 3194 return flag;
3215} 3195}
3216 3196
@@ -3519,12 +3499,11 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3519 u32 ack_seq = TCP_SKB_CB(skb)->seq; 3499 u32 ack_seq = TCP_SKB_CB(skb)->seq;
3520 u32 ack = TCP_SKB_CB(skb)->ack_seq; 3500 u32 ack = TCP_SKB_CB(skb)->ack_seq;
3521 bool is_dupack = false; 3501 bool is_dupack = false;
3522 u32 prior_fackets;
3523 int prior_packets = tp->packets_out; 3502 int prior_packets = tp->packets_out;
3524 u32 delivered = tp->delivered; 3503 u32 delivered = tp->delivered;
3525 u32 lost = tp->lost; 3504 u32 lost = tp->lost;
3526 int acked = 0; /* Number of packets newly acked */
3527 int rexmit = REXMIT_NONE; /* Flag to (re)transmit to recover losses */ 3505 int rexmit = REXMIT_NONE; /* Flag to (re)transmit to recover losses */
3506 u32 prior_fack;
3528 3507
3529 sack_state.first_sackt = 0; 3508 sack_state.first_sackt = 0;
3530 sack_state.rate = &rs; 3509 sack_state.rate = &rs;
@@ -3556,7 +3535,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3556 icsk->icsk_retransmits = 0; 3535 icsk->icsk_retransmits = 0;
3557 } 3536 }
3558 3537
3559 prior_fackets = tp->fackets_out; 3538 prior_fack = tcp_highest_sack_seq(tp);
3560 rs.prior_in_flight = tcp_packets_in_flight(tp); 3539 rs.prior_in_flight = tcp_packets_in_flight(tp);
3561 3540
3562 /* ts_recent update must be made after we are sure that the packet 3541 /* ts_recent update must be made after we are sure that the packet
@@ -3612,8 +3591,7 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3612 goto no_queue; 3591 goto no_queue;
3613 3592
3614 /* See if we can take anything off of the retransmit queue. */ 3593 /* See if we can take anything off of the retransmit queue. */
3615 flag |= tcp_clean_rtx_queue(sk, prior_fackets, prior_snd_una, &acked, 3594 flag |= tcp_clean_rtx_queue(sk, prior_fack, prior_snd_una, &sack_state);
3616 &sack_state);
3617 3595
3618 tcp_rack_update_reo_wnd(sk, &rs); 3596 tcp_rack_update_reo_wnd(sk, &rs);
3619 3597
@@ -3625,7 +3603,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3625 3603
3626 if (tcp_ack_is_dubious(sk, flag)) { 3604 if (tcp_ack_is_dubious(sk, flag)) {
3627 is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED | FLAG_NOT_DUP)); 3605 is_dupack = !(flag & (FLAG_SND_UNA_ADVANCED | FLAG_NOT_DUP));
3628 tcp_fastretrans_alert(sk, acked, is_dupack, &flag, &rexmit); 3606 tcp_fastretrans_alert(sk, prior_snd_una, is_dupack, &flag,
3607 &rexmit);
3629 } 3608 }
3630 3609
3631 if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP)) 3610 if ((flag & FLAG_FORWARD_PROGRESS) || !(flag & FLAG_NOT_DUP))
@@ -3641,7 +3620,8 @@ static int tcp_ack(struct sock *sk, const struct sk_buff *skb, int flag)
3641no_queue: 3620no_queue:
3642 /* If data was DSACKed, see if we can undo a cwnd reduction. */ 3621 /* If data was DSACKed, see if we can undo a cwnd reduction. */
3643 if (flag & FLAG_DSACKING_ACK) 3622 if (flag & FLAG_DSACKING_ACK)
3644 tcp_fastretrans_alert(sk, acked, is_dupack, &flag, &rexmit); 3623 tcp_fastretrans_alert(sk, prior_snd_una, is_dupack, &flag,
3624 &rexmit);
3645 /* If this ack opens up a zero window, clear backoff. It was 3625 /* If this ack opens up a zero window, clear backoff. It was
3646 * being used to time the probes, and is probably far higher than 3626 * being used to time the probes, and is probably far higher than
3647 * it needs to be for normal retransmission. 3627 * it needs to be for normal retransmission.
@@ -3663,7 +3643,8 @@ old_ack:
3663 if (TCP_SKB_CB(skb)->sacked) { 3643 if (TCP_SKB_CB(skb)->sacked) {
3664 flag |= tcp_sacktag_write_queue(sk, skb, prior_snd_una, 3644 flag |= tcp_sacktag_write_queue(sk, skb, prior_snd_una,
3665 &sack_state); 3645 &sack_state);
3666 tcp_fastretrans_alert(sk, acked, is_dupack, &flag, &rexmit); 3646 tcp_fastretrans_alert(sk, prior_snd_una, is_dupack, &flag,
3647 &rexmit);
3667 tcp_xmit_recovery(sk, rexmit); 3648 tcp_xmit_recovery(sk, rexmit);
3668 } 3649 }
3669 3650