tcp_recovery.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <linux/tcp.h>
  2. #include <net/tcp.h>
  3. int sysctl_tcp_recovery __read_mostly = TCP_RACK_LOST_RETRANS;
  4. /* Marks a packet lost, if some packet sent later has been (s)acked.
  5. * The underlying idea is similar to the traditional dupthresh and FACK
  6. * but they look at different metrics:
  7. *
  8. * dupthresh: 3 OOO packets delivered (packet count)
  9. * FACK: sequence delta to highest sacked sequence (sequence space)
  10. * RACK: sent time delta to the latest delivered packet (time domain)
  11. *
  12. * The advantage of RACK is it applies to both original and retransmitted
  13. * packet and therefore is robust against tail losses. Another advantage
  14. * is being more resilient to reordering by simply allowing some
  15. * "settling delay", instead of tweaking the dupthresh.
  16. *
  17. * The current version is only used after recovery starts but can be
  18. * easily extended to detect the first loss.
  19. */
  20. int tcp_rack_mark_lost(struct sock *sk)
  21. {
  22. struct tcp_sock *tp = tcp_sk(sk);
  23. struct sk_buff *skb;
  24. u32 reo_wnd, prior_retrans = tp->retrans_out;
  25. if (inet_csk(sk)->icsk_ca_state < TCP_CA_Recovery || !tp->rack.advanced)
  26. return 0;
  27. /* Reset the advanced flag to avoid unnecessary queue scanning */
  28. tp->rack.advanced = 0;
  29. /* To be more reordering resilient, allow min_rtt/4 settling delay
  30. * (lower-bounded to 1000uS). We use min_rtt instead of the smoothed
  31. * RTT because reordering is often a path property and less related
  32. * to queuing or delayed ACKs.
  33. *
  34. * TODO: measure and adapt to the observed reordering delay, and
  35. * use a timer to retransmit like the delayed early retransmit.
  36. */
  37. reo_wnd = 1000;
  38. if (tp->rack.reord && tcp_min_rtt(tp) != ~0U)
  39. reo_wnd = max(tcp_min_rtt(tp) >> 2, reo_wnd);
  40. tcp_for_write_queue(skb, sk) {
  41. struct tcp_skb_cb *scb = TCP_SKB_CB(skb);
  42. if (skb == tcp_send_head(sk))
  43. break;
  44. /* Skip ones already (s)acked */
  45. if (!after(scb->end_seq, tp->snd_una) ||
  46. scb->sacked & TCPCB_SACKED_ACKED)
  47. continue;
  48. if (skb_mstamp_after(&tp->rack.mstamp, &skb->skb_mstamp)) {
  49. if (skb_mstamp_us_delta(&tp->rack.mstamp,
  50. &skb->skb_mstamp) <= reo_wnd)
  51. continue;
  52. /* skb is lost if packet sent later is sacked */
  53. tcp_skb_mark_lost_uncond_verify(tp, skb);
  54. if (scb->sacked & TCPCB_SACKED_RETRANS) {
  55. scb->sacked &= ~TCPCB_SACKED_RETRANS;
  56. tp->retrans_out -= tcp_skb_pcount(skb);
  57. NET_INC_STATS(sock_net(sk),
  58. LINUX_MIB_TCPLOSTRETRANSMIT);
  59. }
  60. } else if (!(scb->sacked & TCPCB_RETRANS)) {
  61. /* Original data are sent sequentially so stop early
  62. * b/c the rest are all sent after rack_sent
  63. */
  64. break;
  65. }
  66. }
  67. return prior_retrans - tp->retrans_out;
  68. }
  69. /* Record the most recently (re)sent time among the (s)acked packets */
  70. void tcp_rack_advance(struct tcp_sock *tp,
  71. const struct skb_mstamp *xmit_time, u8 sacked)
  72. {
  73. if (tp->rack.mstamp.v64 &&
  74. !skb_mstamp_after(xmit_time, &tp->rack.mstamp))
  75. return;
  76. if (sacked & TCPCB_RETRANS) {
  77. struct skb_mstamp now;
  78. /* If the sacked packet was retransmitted, it's ambiguous
  79. * whether the retransmission or the original (or the prior
  80. * retransmission) was sacked.
  81. *
  82. * If the original is lost, there is no ambiguity. Otherwise
  83. * we assume the original can be delayed up to aRTT + min_rtt.
  84. * the aRTT term is bounded by the fast recovery or timeout,
  85. * so it's at least one RTT (i.e., retransmission is at least
  86. * an RTT later).
  87. */
  88. skb_mstamp_get(&now);
  89. if (skb_mstamp_us_delta(&now, xmit_time) < tcp_min_rtt(tp))
  90. return;
  91. }
  92. tp->rack.mstamp = *xmit_time;
  93. tp->rack.advanced = 1;
  94. }