RACK loss detection
Subsystems (4)
cover RACK loss detection
RACK (Recent ACK) loss recovery uses the notion of time instead of packet sequence (FACK) or counts (dupthresh).
It's inspired by the FACK heuristic in tcp_mark_lost_retrans(): when a limited transmit (new data packet) is sacked in recovery, then any retransmission sent before that newly sacked packet was sent must have been lost, since at least one round trip time has elapsed.
But that existing heuristic from tcp_mark_lost_retrans() has several limitations:
1) it can't detect tail drops since it depends on limited transmit
2) it's disabled upon reordering (assumes no reordering)
3) it's only enabled in fast recovery but not timeout recovery
RACK addresses these limitations with a core idea: an unacknowledged packet P1 is deemed lost if a packet P2 that was sent later is is s/acked, since at least one round trip has passed.
Since RACK cares about the time sequence instead of the data sequence of packets, it can detect tail drops when a later retransmission is s/acked, while FACK or dupthresh can't. For reordering RACK uses a dynamically adjusted reordering window ("reo_wnd") to reduce false positives on ever (small) degree of reordering, similar to the delayed Early Retransmit.
In the current patch set RACK is only a supplemental loss detection and does not trigger fast recovery. However we are developing RACK to replace or consolidate FACK/dupthresh, early retransmit, and thin-dupack. These heuristics all implicitly bear the time notion. For example, the delayed Early Retransmit is simply applying RACK to trigger the fast recovery with small inflight.
RACK requires measuring the minimum RTT. Tracking a global min is less robust due to traffic engineering pathing changes. Therefore it uses a windowed filter by Kathleen Nichols. The min RTT can also be useful for various other purposes like congestion control or stat monitoring.
This patch has been used on Google servers for well over 1 year. RACK has also been implemented in the QUIC protocol. We are submitting an IETF draft as well.
Yuchung Cheng (7):
tcp: apply Kern's check on RTTs used for congestion control
tcp: track min RTT using windowed min-filter
tcp: remove tcp_mark_lost_retrans()
tcp: add tcp_tsopt_ecr_before helper
tcp: skb_mstamp_after helper
tcp: track the packet timings in RACK
tcp: use RACK to detect losses
Documentation/networking/ip-sysctl.txt | 17 ++++ include/linux/skbuff.h | 9 ++ include/linux/tcp.h | 11 +- include/net/tcp.h | 21 ++++ net/ipv4/Makefile | 1 + net/ipv4/sysctl_net_ipv4.c | 14 +++ net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 180 +++++++++++++++++++-------------- net/ipv4/tcp_minisocks.c | 3 + net/ipv4/tcp_output.c | 6 -- net/ipv4/tcp_recovery.c | 109 ++++++++++++++++++++ 11 files changed, 286 insertions(+), 86 deletions(-) create mode 100644 net/ipv4/tcp_recovery.c
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 1/7 tcp: apply Kern's check on RTTs used for congestion control
Currently ca_seq_rtt_us does not use Kern's check. Fix that by checking if any packet acked is a retransmit, for both RTT used for RTT estimation and congestion control.
--- net/ipv4/tcp_input.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/ipv4/tcp_input.c +1 -4
@@ -2925,9 +2925,6 @@ static inline bool tcp_ack_update_rtt(struct sock *sk, const int flag,* Karn's algorithm forbids taking RTT if some retransmitted data * is acked (RFC6298). */ -if (flag &FLAG_RETRANS_DATA_ACKED ) - seq_rtt_us =-1L ; -if (seq_rtt_us <0 ) seq_rtt_us = sack_rtt_us;
@@ -3169,7 +3166,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets, flag |=FLAG_SACK_RENEGING ;skb_mstamp_get (&now); -if (likely (first_ackt.v64)) { +if (likely (first_ackt.v64) && !(flag &FLAG_RETRANS_DATA_ACKED )) { seq_rtt_us =skb_mstamp_us_delta (&now, &first_ackt); ca_rtt_us =skb_mstamp_us_delta (&now, &last_ackt); }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH net-next 1/7] tcp: apply Kern's check on RTTs used for congestion control
Quoted 4 lines · Yuchung Cheng
Currently
ca_seq_rtt_usdoes not use Kern's check. Fix that by checking if any packet acked is a retransmit, for both RTT used for RTT estimation and congestion control.
*snip*
This patch (commit 9e45a3e) puzzles me, because Karn's check was already in effect:
http://lxr.free-electrons.com/source/net/ipv4/tcp_input.c?v=4.3#L3117
Since first_ackt/last_ackt is only set when non-retransmitted packets are ACKed (sequentially), we know them to be unambiguous samples for RTTM. Even if a (sequential) ACK covers retransmitted packets, we can still make a valid RTTM if that ACK also covers non-retransmitted packets. But this patch seems to prevent that?
Re: [PATCH net-next 1/7] tcp: apply Kern's check on RTTs used for congestion control
Quoted 12 lines · Kenneth Klette Jonassen
Quoted 4 lines · Yuchung Cheng
Currently
ca_seq_rtt_usdoes not use Kern's check. Fix that by checking if any packet acked is a retransmit, for both RTT used for RTT estimation and congestion control.*snip*
This patch (commit 9e45a3e) puzzles me, because Karn's check was already in effect:
http://lxr.free-electrons.com/source/net/ipv4/tcp_input.c?v=4.3#L3117
Quoted 5 lines
Since first_ackt/last_ackt is only set when non-retransmitted packets are ACKed (sequentially), we know them to be unambiguous samples for RTTM. Even if a (sequential) ACK covers retransmitted packets, we can still make a valid RTTM if that ACK also covers non-retransmitted packets. But this patch seems to prevent that?
Perhaps the commit message is not clear. Here is an example: an ACK acks 2 packets where the 1st packet was retransmitted but the 2nd packet is not.
Since we don't know if the ACk was caused by the retransmission (plugs a hole) or by the original, we should not take an RTT sample. In other words, we should refrain from taking RTT sample as long as the ACK covers any retransmitted sequence.
PATCH 2/7 tcp: track min RTT using windowed min-filter
In reply to Yuchung ChengKathleen Nichols' algorithm for tracking the minimum RTT of a data stream over some measurement window. It uses constant space and constant time per update. Yet it almost always delivers the same minimum as an implementation that has to keep all the data in the window. The measurement window is tunable via sysctl.net.ipv4.tcp_min_rtt_wlen with a default value of 5 minutes.
The algorithm keeps track of the best, 2nd best & 3rd best min values, maintaining an invariant that the measurement time of the n'th best >= n-1'th best. It also makes sure that the three values are widely separated in the time window since that bounds the worse case error when that data is monotonically increasing over the window.
Upon getting a new min, we can forget everything earlier because it has no value - the new min is less than everything else in the window by definition and it's the most recent. So we restart fresh on every new min and overwrites the 2nd & 3rd choices. The same property holds for the 2nd & 3rd best.
Therefore we have to maintain two invariants to maximize the information in the samples, one on values (1st.v <= 2nd.v <= 3rd.v) and the other on times (now-win <=1st.t <= 2nd.t <= 3rd.t <= now). These invariants determine the structure of the code
The RTT input to the windowed filter is the minimum RTT measured from ACK or SACK, or as the last resort from TCP timestamps.
The accessor tcp_min_rtt() returns the minimum RTT seen in the window. ~0U indicates it is not available. The minimum is 1usec even if the true RTT is below that.
--- Documentation/networking/ip-sysctl.txt | 8 ++++ include/linux/tcp.h | 3 ++ include/net/tcp.h | 7 +++ net/ipv4/sysctl_net_ipv4.c | 7 +++ net/ipv4/tcp.c | 1 + net/ipv4/tcp_input.c | 78 +++++++++++++++++++++++++++++++--- net/ipv4/tcp_minisocks.c | 1 + 7 files changed, 100 insertions(+), 5 deletions(-)
Documentation/networking/ip-sysctl.txt +8 -0
@@ -384,6 +384,14 @@ tcp_mem - vector of 3 INTEGERs: min, pressure, max Defaults are calculated at boot time from amount of available memory. +tcp_min_rtt_wlen - INTEGER + The window length of the windowed min filter to track the minimum RTT. + A shorter window lets a flow more quickly pick up new (higher) + minimum RTT when it is moved to a longer path (e.g., due to traffic + engineering). A longer window makes the filter more resistant to RTT + inflations such as transient congestion. The unit is seconds. + Default: 300 + tcp_moderate_rcvbuf - BOOLEAN If set, TCP performs receive buffer auto-tuning, attempting to automatically size the buffer (no greater than tcp_rmem[2]) to
include/linux/tcp.h +3 -0
@@ -217,6 +217,9 @@ struct tcp_sock {u32 mdev_max_us;/* maximal mdev for the last rtt period */ u32 rttvar_us;/* smoothed mdev_max */ u32 rtt_seq;/* sequence number to update rttvar */ +struct rtt_meas { +u32 rtt, ts;/* RTT in usec and sampling time in jiffies. */ + } rtt_min[3 ];u32 packets_out;/* Packets which are "in flight" */ u32 retrans_out;/* Retransmitted packets out */
include/net/tcp.h +7 -0
@@ -279,6 +279,7 @@ extern int sysctl_tcp_limit_output_bytes;extern int sysctl_tcp_challenge_ack_limit;extern unsigned int sysctl_tcp_notsent_lowat;extern int sysctl_tcp_min_tso_segs; +extern int sysctl_tcp_min_rtt_wlen;extern int sysctl_tcp_autocorking;extern int sysctl_tcp_invalid_ratelimit;extern int sysctl_tcp_pacing_ss_ratio;
@@ -671,6 +672,12 @@ static inline bool tcp_ca_dst_locked(const struct dst_entry *dst)return dst_metric_locked (dst,RTAX_CC_ALGO ); } +/* Minimum RTT in usec. ~0 means not available. */ +static inline u32 tcp_min_rtt (const struct tcp_sock *tp) +{ +return tp->rtt_min[0 ].rtt; +} +/* Compute the actual receive window we are currently advertising. * Rcv_nxt can be after the window if our peer push more data * than the offered window.
net/ipv4/sysctl_net_ipv4.c +7 -0
@@ -577,6 +577,13 @@ static struct ctl_table ipv4_table[] = { .proc_handler = proc_dointvec }, { + .procname = "tcp_min_rtt_wlen", + .data = &sysctl_tcp_min_rtt_wlen, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, + { .procname = "tcp_low_latency", .data = &sysctl_tcp_low_latency, .maxlen = sizeof(int),
net/ipv4/tcp.c +1 -0
@@ -388,6 +388,7 @@ void tcp_init_sock(struct sock *sk) icsk->icsk_rto =TCP_TIMEOUT_INIT ; tp->mdev_us =jiffies_to_usecs (TCP_TIMEOUT_INIT ); + tp->rtt_min[0 ].rtt = ~0U ;/* So many TCP implementations out there (incorrectly) count the * initial SYN frame in their delayed-ACK and congestion control
net/ipv4/tcp_input.c +73 -5
112 lines not on this page · raw message
net/ipv4/tcp_minisocks.c +1 -0
@@ -470,6 +470,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk, newtp->srtt_us =0 ; newtp->mdev_us =jiffies_to_usecs (TCP_TIMEOUT_INIT ); + newtp->rtt_min[0 ].rtt = ~0U ; newicsk->icsk_rto =TCP_TIMEOUT_INIT ; newtp->packets_out =0 ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Re: [PATCH net-next 2/7] tcp: track min RTT using windowed min-filter
On Fri, Oct 16, 2015 at 09:57:42PM -0700, Yuchung Cheng wrote:
...
include/linux/tcp.h struct tcp_sock { · line 222
Quoted 11 lines
include/linux/tcp.h +3
-0@@ -217,6 +217,9 @@ struct tcp_sock {u32 mdev_max_us;/* maximal mdev for the last rtt period */ u32 rttvar_us;/* smoothed mdev_max */ u32 rtt_seq;/* sequence number to update rttvar */ +struct rtt_meas { +u32 rtt, ts;/* RTT in usec and sampling time in jiffies. */ + } rtt_min[3 ];
First, thanks for all the work in this patch series. In particular, applying Kern's check to ca_seq_rtt_us should fix some bad behavior I've observed recently.
I only have a couple comments, so I abbreviated most of your patch. Should rtt_meas.rtt be rtt_meas.rtt_us in order to be more consistent with the naming of related variables?
...
Quoted 4 lines
net/ipv4/tcp_input.c +0
-0
...
net/ipv4/tcp_input.c void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) · line 3032
Quoted 7 lines
net/ipv4/tcp_input.c +1
-1@@ -2961,7 +3028,7 @@ void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) rtt_us =skb_mstamp_us_delta (&now, &tcp_rsk (req)->snt_synack); } -tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L ); +tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L , rtt_us); }
This didn't apply to net-next for me. I see seq_rtt_us instead of rtt_us and a check on the existence of tp->srtt_us. Maybe I've misapplied the patch? I'll try again and test the patch series against the bad behavior I mentioned above as soon as I can. Hopefully today.
-Andrew Shewmaker
Neal Cardwell
maintainerRe: [PATCH net-next 2/7] tcp: track min RTT using windowed min-filter
Quoted 9 lines · Andrew Shewmaker
Quoted 4 lines
net/ipv4/tcp_input.c +0
-0...
Quoted 4 lines
net/ipv4/tcp_input.c +0
-0@@ -2961,7 +3028,7 @@ void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) rtt_us =skb_mstamp_us_delta (&now, &tcp_rsk (req)->snt_synack); }
Quoted 7 lines
net/ipv4/tcp_input.c void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) · line 3032
Quoted 3 lines
net/ipv4/tcp_input.c +1
-1-tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L ); +tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L , rtt_us); }This didn't apply to net-next for me. I see
seq_rtt_usinstead ofrtt_usand a check on the existence oftp->srtt_us. Maybe I've misapplied the patch?
This patch series applies cleanly for me against David Miller's net-next at SHA1 4be3158 (from Friday Oct 16). (Using "git am" on the mbox patches from http://patchwork.ozlabs.org/project/netdev/list/
...)
On top of what SHA1 are you applying the series?
neal
Re: [PATCH net-next 2/7] tcp: track min RTT using windowed min-filter
Quoted 18 lines · Neal Cardwell
Quoted 9 lines · Andrew Shewmaker
Quoted 4 lines
net/ipv4/tcp_input.c +0
-0...
Quoted 4 lines
net/ipv4/tcp_input.c +0
-0@@ -2961,7 +3028,7 @@ void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) rtt_us =skb_mstamp_us_delta (&now, &tcp_rsk (req)->snt_synack); }Quoted 7 lines
net/ipv4/tcp_input.c void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) · line 3032
Quoted 3 lines
net/ipv4/tcp_input.c +1
-1-tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L ); +tcp_ack_update_rtt (sk,FLAG_SYN_ACKED , rtt_us,-1L , rtt_us); }This didn't apply to net-next for me. I see
seq_rtt_usinstead ofrtt_usand a check on the existence oftp->srtt_us. Maybe I've misapplied the patch?
Quoted 6 lines
This patch series applies cleanly for me against David Miller's net-next at SHA1 4be3158 (from Friday Oct 16). (Using "git am" on the mbox patches from http://patchwork.ozlabs.org/project/netdev/list/
...)On top of what SHA1 are you applying the series?
Doesn't matter which one ... it was the wrong one :)
I'd executed a git pull before applying the patch set, but I ended up having to force it. Once I did, it applied cleanly.
Apologies for the false alarm,
Andrew
Re: [PATCH net-next 2/7] tcp: track min RTT using windowed min-filter
In reply to Andrew ShewmakerQuoted 17 lines · Andrew Shewmaker
On Fri, Oct 16, 2015 at 09:57:42PM -0700, Yuchung Cheng wrote:
...include/linux/tcp.h struct tcp_sock { · line 222
Quoted 11 lines
include/linux/tcp.h +3
-0@@ -217,6 +217,9 @@ struct tcp_sock {u32 mdev_max_us;/* maximal mdev for the last rtt period */ u32 rttvar_us;/* smoothed mdev_max */ u32 rtt_seq;/* sequence number to update rttvar */ +struct rtt_meas { +u32 rtt, ts;/* RTT in usec and sampling time in jiffies. */ + } rtt_min[3 ];First, thanks for all the work in this patch series. In particular, applying Kern's check to
ca_seq_rtt_usshould fix some bad behavior I've observed recently.
I'd have to run more tests to be sure, but net-next with this patch series significantly improves upon the poor behavior I was seeing where randomly dropped packets greatly limited the usefulness of RTTs as a signal of congestion. I still see some measurements that exceed the amount of delay possible from queue buildup, but fewer than before.
Thanks!
-Andrew
PATCH 3/7 tcp: remove tcp_mark_lost_retrans()
In reply to Yuchung ChengRemove the existing lost retransmit detection because RACK subsumes it completely. This also stops the overloading the ack_seq field of the skb control block.
--- include/linux/tcp.h | 2 -- net/ipv4/tcp_input.c | 65 --------------------------------------------------- net/ipv4/tcp_output.c | 6 ----- 3 files changed, 73 deletions(-)
include/linux/tcp.h +0 -2
@@ -283,8 +283,6 @@ struct tcp_sock {int lost_cnt_hint;u32 retransmit_high;/* L-bits may be on up to this seqno */ -u32 lost_retrans_low;/* Sent seq after any rxmit (lowest) */ -u32 prior_ssthresh;/* ssthresh saved at recovery start */ u32 high_seq;/* snd_nxt at onset of congestion */
net/ipv4/tcp_input.c +0 -65
77 lines not on this page · raw message
net/ipv4/tcp_output.c +0 -6
@@ -2655,8 +2655,6 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb) net_dbg_ratelimited("retrans_out leaked\n"); }#endif -if (!tp->retrans_out) - tp->lost_retrans_low = tp->snd_nxt;TCP_SKB_CB (skb)->sacked |=TCPCB_RETRANS ; tp->retrans_out +=tcp_skb_pcount (skb);
@@ -2664,10 +2662,6 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)if (!tp->retrans_stamp) tp->retrans_stamp =tcp_skb_timestamp (skb); -/* snd_nxt is stored to detect loss of retransmitted segment, -* see tcp_input.c tcp_sacktag_write_queue(). -*/ -TCP_SKB_CB (skb)->ack_seq = tp->snd_nxt; }else if (err != -EBUSY ) {NET_INC_STATS_BH (sock_net (sk),LINUX_MIB_TCPRETRANSFAIL ); }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 4/7 tcp: add tcp_tsopt_ecr_before helper
In reply to Yuchung Chenga helper to prepare the main RACK patch
--- net/ipv4/tcp_input.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/ipv4/tcp_input.c +7 -2
@@ -2250,14 +2250,19 @@ static inline void tcp_moderate_cwnd(struct tcp_sock *tp) tp->snd_cwnd_stamp = tcp_time_stamp; } +static bool tcp_tsopt_ecr_before (const struct tcp_sock *tp,u32 when) +{ +return tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && +before (tp->rx_opt.rcv_tsecr, when); +} +/* Nothing was retransmitted or returned timestamp is less * than timestamp of the first retransmission. */ static inline bool tcp_packet_delayed (const struct tcp_sock *tp) {return !tp->retrans_stamp || - (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && -before (tp->rx_opt.rcv_tsecr, tp->retrans_stamp)); +tcp_tsopt_ecr_before (tp, tp->retrans_stamp); }/* Undo procedures. */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 5/7 tcp: skb_mstamp_after helper
In reply to Yuchung Chenga helper to prepare the first main RACK patch.
--- include/linux/skbuff.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/skbuff.h +9 -0
@@ -463,6 +463,15 @@ static inline u32 skb_mstamp_us_delta(const struct skb_mstamp *t1,return delta_us; } +static inline bool skb_mstamp_after (const struct skb_mstamp *t1, +const struct skb_mstamp *t0) +{ +s32 diff = t1->stamp_jiffies - t0->stamp_jiffies; + +if (!diff) + diff = t1->stamp_us - t0->stamp_us; +return diff >0 ; +}/** * struct sk_buff - socket buffer
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 6/7 tcp: track the packet timings in RACK
In reply to Yuchung ChengThis patch is the first half of the RACK loss recovery.
RACK loss recovery uses the notion of time instead
of packet sequence (FACK) or counts (dupthresh). It's inspired by the previous FACK heuristic in tcp_mark_lost_retrans(): when a limited transmit (new data packet) is sacked, then current retransmitted sequence below the newly sacked sequence must been lost, since at least one round trip time has elapsed.
But it has several limitations:
1) can't detect tail drops since it depends on limited transmit
2) is disabled upon reordering (assumes no reordering)
3) only enabled in fast recovery ut not timeout recovery
RACK (Recently ACK) addresses these limitations with the notion of time instead: a packet P1 is lost if a later packet P2 is s/acked, as at least one round trip has passed.
Since RACK cares about the time sequence instead of the data sequence of packets, it can detect tail drops when later retransmission is s/acked while FACK or dupthresh can't. For reordering RACK uses a dynamically adjusted reordering window ("reo_wnd") to reduce false positives on ever (small) degree of reordering.
This patch implements tcp_advanced_rack() which tracks the most recent transmission time among the packets that have been delivered (ACKed or SACKed) in tp->rack.mstamp. This timestamp is the key to determine which packet has been lost.
Consider an example that the sender sends six packets:
T1: P1 (lost)
T2: P2
T3: P3
T4: P4
T100: sack of P2. rack.mstamp = T2
T101: retransmit P1
T102: sack of P2,P3,P4. rack.mstamp = T4
T205: ACK of P4 since the hole is repaired. rack.mstamp = T101
We need to be careful about spurious retransmission because it may falsely advance tp->rack.mstamp by an RTT or an RTO, causing RACK to falsely mark all packets lost, just like a spurious timeout.
We identify spurious retransmission by the ACK's TS echo value. If TS option is not applicable but the retransmission is acknowledged less than min-RTT ago, it is likely to be spurious. We refrain from using the transmission time of these spurious retransmissions.
The second half is implemented in the next patch that marks packet lost using RACK timestamp.
--- include/linux/tcp.h | 6 ++++++ include/net/tcp.h | 5 +++++ net/ipv4/Makefile | 1 + net/ipv4/tcp_input.c | 14 ++++++++++++++ net/ipv4/tcp_minisocks.c | 2 ++ net/ipv4/tcp_recovery.c | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 net/ipv4/tcp_recovery.c
include/linux/tcp.h +6 -0
@@ -194,6 +194,12 @@ struct tcp_sock {u32 window_clamp;/* Maximal window to advertise */ u32 rcv_ssthresh;/* Current window clamp */ +/* Information of the most recently (s)acked skb */ +struct tcp_rack { +struct skb_mstamp mstamp;/* (Re)sent time of the skb */ +u8 advanced;/* mstamp advanced since last lost marking */ +u8 reord;/* reordering detected */ + } rack;u16 advmss;/* Advertised MSS */ u8 unused; u8 nonagle : 4,/* Disable Nagle algorithm? */
include/net/tcp.h +5 -0
@@ -1750,6 +1750,11 @@ int tcpv4_offload_init(void);void tcp_v4_init (void );void tcp_init (void ); +/* tcp_recovery.c */ + +extern void tcp_rack_advance (struct tcp_sock *tp, +const struct skb_mstamp *xmit_time,u8 sacked); +/* * Save and compile IPv4 options, return a pointer to it */
net/ipv4/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y := route.o inetpeer.o protocol.o \ inet_timewait_sock.o inet_connection_sock.o \ tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \ tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \ + tcp_recovery.o \ tcp_offload.o datagram.o raw.o udp.o udplite.o \ udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \ fib_frontend.o fib_semantics.o fib_trie.o \
net/ipv4/tcp_input.c +14 -0
@@ -1173,6 +1173,8 @@ static u8 tcp_sacktag_one(struct sock *sk,return sacked;if (!(sacked &TCPCB_SACKED_ACKED )) { +tcp_rack_advance (tp, xmit_time, sacked); +if (sacked &TCPCB_SACKED_RETRANS ) {/* If the segment is not tagged as lost, * we do not clear RETRANS, believing
@@ -2256,6 +2258,16 @@ static bool tcp_tsopt_ecr_before(const struct tcp_sock *tp, u32 when)before (tp->rx_opt.rcv_tsecr, when); } +/* skb is spurious retransmitted if the returned timestamp echo +* reply is prior to the skb transmission time +*/ +static bool tcp_skb_spurious_retrans (const struct tcp_sock *tp, +const struct sk_buff *skb) +{ +return (TCP_SKB_CB (skb)->sacked &TCPCB_RETRANS ) && +tcp_tsopt_ecr_before (tp,tcp_skb_timestamp (skb)); +} +/* Nothing was retransmitted or returned timestamp is less * than timestamp of the first retransmission. */
@@ -3135,6 +3147,8 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,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);if (sacked &TCPCB_LOST ) tp->lost_out -= acked_pcount;
net/ipv4/tcp_minisocks.c +2 -0
@@ -548,6 +548,8 @@ struct sock *tcp_create_openreq_child(const struct sock *sk,tcp_ecn_openreq_child (newtp, req); newtp->fastopen_rsk =NULL ; newtp->syn_data_acked =0 ; + newtp->rack.mstamp.v64 =0 ; + newtp->rack.advanced =0 ; newtp->saved_syn = req->saved_syn; req->saved_syn =NULL ;
net/ipv4/tcp_recovery.c new file +32 -0
@@ -0,0 +1,32 @@ +#include <linux/tcp.h> +#include <net/tcp.h> + +/* Record the most recently (re)sent time among the (s)acked packets */ +void tcp_rack_advance (struct tcp_sock *tp, +const struct skb_mstamp *xmit_time,u8 sacked) +{ +if (tp->rack.mstamp.v64 && + !skb_mstamp_after (xmit_time, &tp->rack.mstamp)) +return ; + +if (sacked &TCPCB_RETRANS ) { +struct skb_mstamp now; + +/* If the sacked packet was retransmitted, it's ambiguous +* whether the retransmission or the original (or the prior +* retransmission) was sacked. +* +* If the original is lost, there is no ambiguity. Otherwise +* we assume the original can be delayed up to aRTT + min_rtt. +* the aRTT term is bounded by the fast recovery or timeout, +* so it's at least one RTT (i.e., retransmission is at least +* an RTT later). +*/ +skb_mstamp_get (&now); +if (skb_mstamp_us_delta (&now, xmit_time) <tcp_min_rtt (tp)) +return ; + } + + tp->rack.mstamp = *xmit_time; + tp->rack.advanced =1 ; +}
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
PATCH 7/7 tcp: use RACK to detect losses
In reply to Yuchung ChengThis patch implements the second half of RACK that uses the the most recent transmit time among all delivered packets to detect losses.
tcp_rack_mark_lost() is called upon receiving a dubious ACK. It then checks if an not-yet-sacked packet was sent at least "reo_wnd" prior to the sent time of the most recently delivered. If so the packet is deemed lost.
The "reo_wnd" reordering window starts with 1msec for fast loss detection and changes to min-RTT/4 when reordering is observed. We found 1msec accommodates well on tiny degree of reordering (<3 pkts) on faster links. We use min-RTT instead of SRTT because reordering is more of a path property but SRTT can be inflated by self-inflicated congestion. The factor of 4 is borrowed from the delayed early retransmit and seems to work reasonably well.
Since RACK is still experimental, it is now used as a supplemental loss detection on top of existing algorithms. It is only effective after the fast recovery starts or after the timeout occurs. The fast recovery is still triggered by FACK and/or dupack threshold instead of RACK.
We introduce a new sysctl net.ipv4.tcp_recovery for future experiments of loss recoveries. For now RACK can be disabled by setting it to 0.
--- Documentation/networking/ip-sysctl.txt | 9 ++++ include/net/tcp.h | 9 ++++ net/ipv4/sysctl_net_ipv4.c | 7 ++++ net/ipv4/tcp_input.c | 9 +++- net/ipv4/tcp_recovery.c | 77 ++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 2 deletions(-)
Documentation/networking/ip-sysctl.txt +9 -0
@@ -433,6 +433,15 @@ tcp_orphan_retries - INTEGER you should think about lowering this value, such sockets may consume significant resources. Cf. tcp_max_orphans. +tcp_recovery - INTEGER + This value is a bitmap to enable various experimental loss recovery + features. + + RACK: 0x1 enables the RACK loss detection for fast detection of lost + retransmissions and tail drops. + + Default: 0x1 + tcp_reordering - INTEGER Initial reordering level of packets in a TCP stream. TCP stack can then dynamically adjust flow reordering level
include/net/tcp.h +9 -0
@@ -567,6 +567,7 @@ void tcp_resume_early_retransmit(struct sock *sk);void tcp_rearm_rto (struct sock *sk);void tcp_synack_rtt_meas (struct sock *sk,struct request_sock *req);void tcp_reset (struct sock *sk); +void tcp_skb_mark_lost_uncond_verify (struct tcp_sock *tp,struct sk_buff *skb);/* tcp_timer.c */ void tcp_init_xmit_timers (struct sock *);
@@ -1752,6 +1753,14 @@ void tcp_init(void);/* tcp_recovery.c */ +/* Flags to enable various loss recovery features. See below */ +extern int sysctl_tcp_recovery; + +/* Use TCP RACK to detect (some) tail and retransmit losses */ +#define TCP_RACK_LOST_RETRANS 0x1 + +extern int tcp_rack_mark_lost (struct sock *sk); +extern void tcp_rack_advance (struct tcp_sock *tp,const struct skb_mstamp *xmit_time,u8 sacked);
net/ipv4/sysctl_net_ipv4.c +7 -0
@@ -496,6 +496,13 @@ static struct ctl_table ipv4_table[] = { .proc_handler = proc_dointvec }, { + .procname = "tcp_recovery", + .data = &sysctl_tcp_recovery, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, + { .procname = "tcp_reordering", .data = &sysctl_tcp_reordering, .maxlen = sizeof(int),
net/ipv4/tcp_input.c +7 -2
@@ -881,6 +881,7 @@ static void tcp_update_reordering(struct sock *sk, const int metric,if (metric >0 )tcp_disable_early_retrans (tp); + tp->rack.reord =1 ; }/* This must be called before lost_out is incremented */
@@ -906,8 +907,7 @@ static void tcp_skb_mark_lost(struct tcp_sock *tp, struct sk_buff *skb) } } -static void tcp_skb_mark_lost_uncond_verify (struct tcp_sock *tp, -struct sk_buff *skb) +void tcp_skb_mark_lost_uncond_verify (struct tcp_sock *tp,struct sk_buff *skb) {tcp_verify_retransmit_hint (tp, skb);
@@ -2806,6 +2806,11 @@ 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)) + flag |=FLAG_LOST_RETRANS ; +/* E. Process state. */ switch (icsk->icsk_ca_state) {case TCP_CA_Recovery:
net/ipv4/tcp_recovery.c +77 -0
83 lines not on this page · raw message
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
David Miller
maintainerFrom: Yuchung Cheng <[email protected]>
Date: Fri, 16 Oct 2015 21:57:40 -0700
Quoted 32 lines
RACK (Recent ACK) loss recovery uses the notion of time instead of packet sequence (FACK) or counts (dupthresh).
It's inspired by the FACK heuristic in
tcp_mark_lost_retrans(): when a limited transmit (new data packet) is sacked in recovery, then any retransmission sent before that newly sacked packet was sent must have been lost, since at least one round trip time has elapsed.But that existing heuristic from
tcp_mark_lost_retrans()has several limitations:
1) it can't detect tail drops since it depends on limited transmit
2) it's disabled upon reordering (assumes no reordering)
3) it's only enabled in fast recovery but not timeout recoveryRACK addresses these limitations with a core idea: an unacknowledged packet P1 is deemed lost if a packet P2 that was sent later is is s/acked, since at least one round trip has passed.
Since RACK cares about the time sequence instead of the data sequence of packets, it can detect tail drops when a later retransmission is s/acked, while FACK or dupthresh can't. For reordering RACK uses a dynamically adjusted reordering window ("
reo_wnd") to reduce false positives on ever (small) degree of reordering, similar to the delayed Early Retransmit.In the current patch set RACK is only a supplemental loss detection and does not trigger fast recovery. However we are developing RACK to replace or consolidate FACK/dupthresh, early retransmit, and thin-dupack. These heuristics all implicitly bear the time notion. For example, the delayed Early Retransmit is simply applying RACK to trigger the fast recovery with small inflight.
Quoted 8 lines
RACK requires measuring the minimum RTT. Tracking a global min is less robust due to traffic engineering pathing changes. Therefore it uses a windowed filter by Kathleen Nichols. The min RTT can also be useful for various other purposes like congestion control or stat monitoring.
This patch has been used on Google servers for well over 1 year. RACK has also been implemented in the QUIC protocol. We are submitting an IETF draft as well.
This looks really great, in fact in my eyes the entire series is justified merely by patch #3 :-)
Series applied, thanks.