fix DCTCP ECE Ack series
Subsystems (3)
cover fix DCTCP ECE Ack series
This patch set address that the existing DCTCP implementation does not fully implement the ACK policy specified in the RFC. This improves the responsiveness of CE status change particularly on flows with small inflight.
Yuchung Cheng (3):
tcp: helpers to send special ack
tcp: do not cancel delay-AcK on DCTCP special ACK
tcp: do not delay ACK in DCTCP upon CE status change
include/net/tcp.h | 2 ++ net/ipv4/tcp_dctcp.c | 52 +++++++++++++------------------------------ net/ipv4/tcp_input.c | 3 ++- net/ipv4/tcp_output.c | 32 +++++++++++++++++++------- 4 files changed, 44 insertions(+), 45 deletions(-)
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
PATCH 1/3 tcp: helpers to send special DCTCP ack
Refactor and create helpers to send the special ACK in DCTCP.
--- net/ipv4/tcp_output.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
net/ipv4/tcp_output.c +17 -5
@@ -1023,8 +1023,8 @@ static void tcp_update_skb_after_send(struct tcp_sock *tp, struct sk_buff *skb)* We are working here with either a clone of the original * SKB, or a fresh unique copy made by the retransmit engine. */ -static int tcp_transmit_skb (struct sock *sk,struct sk_buff *skb,int clone_it, -gfp_t gfp_mask) +static int __tcp_transmit_skb (struct sock *sk,struct sk_buff *skb, +int clone_it,gfp_t gfp_mask,u32 rcv_nxt) {const struct inet_connection_sock *icsk =inet_csk (sk);struct inet_sock *inet;
@@ -1100,7 +1100,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, th->source = inet->inet_sport; th->dest = inet->inet_dport; th->seq =htonl (tcb->seq); - th->ack_seq =htonl (tp->rcv_nxt); + th->ack_seq =htonl (rcv_nxt); *(((__be16 *)th) +6 ) =htons (((tcp_header_size >>2 ) <<12 ) | tcb->tcp_flags);
@@ -1178,6 +1178,13 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,return err; } +static int tcp_transmit_skb (struct sock *sk,struct sk_buff *skb,int clone_it, +gfp_t gfp_mask) +{ +return __tcp_transmit_skb (sk, skb, clone_it, gfp_mask, +tcp_sk (sk)->rcv_nxt); +} +/* This routine just queues the buffer for sending. * * NOTE: probe0 timer is not checked, do not forget tcp_push_pending_frames,
@@ -3571,7 +3578,7 @@ void tcp_send_delayed_ack(struct sock *sk) }/* This routine sends an ack and also updates the window. */ -void tcp_send_ack (struct sock *sk) +void __tcp_send_ack (struct sock *sk,u32 rcv_nxt) {struct sk_buff *buff;
@@ -3604,7 +3611,12 @@ void tcp_send_ack(struct sock *sk)skb_set_tcp_pure_ack (buff);/* Send it off, this clears delayed acks for us. */ -tcp_transmit_skb (sk, buff,0 , (__force gfp_t )0 ); +__tcp_transmit_skb (sk, buff,0 , (__force gfp_t )0 , rcv_nxt); +} + +void tcp_send_ack (struct sock *sk) +{ +__tcp_send_ack (sk,tcp_sk (sk)->rcv_nxt); }EXPORT_SYMBOL_GPL (tcp_send_ack);
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
PATCH 2/3 tcp: do not cancel delay-AcK on DCTCP special ACK
In reply to Yuchung ChengCurrently when a DCTCP receiver delays an ACK and receive a data packet with a different CE mark from the previous one's, it sends two immediate ACKs acking previous and latest sequences respectly (for ECN accounting).
Previously sending the first ACK may mark off the delayed ACK timer (tcp_event_ack_sent). This may subsequently prevent sending the second ACK to acknowledge the latest sequence (tcp_ack_snd_check). The culprit is that tcp_send_ack() assumes it always acknowleges the latest sequence, which is not true for the first special ACK.
The fix is to not make the assumption in tcp_send_ack and check the actual ack sequence before cancelling the delayed ACK. Further it's safer to pass the ack sequence number as a local variable into tcp_send_ack routine, instead of intercepting tp->rcv_nxt to avoid future bugs like this.
--- include/net/tcp.h | 1 + net/ipv4/tcp_dctcp.c | 34 ++++------------------------------ net/ipv4/tcp_output.c | 10 +++++++--- 3 files changed, 12 insertions(+), 33 deletions(-)
include/net/tcp.h +1 -0
@@ -539,6 +539,7 @@ void tcp_send_fin(struct sock *sk);void tcp_send_active_reset (struct sock *sk,gfp_t priority);int tcp_send_synack (struct sock *);void tcp_push_one (struct sock *,unsigned int mss_now); +void __tcp_send_ack (struct sock *sk,u32 rcv_nxt);void tcp_send_ack (struct sock *sk);void tcp_send_delayed_ack (struct sock *sk);void tcp_send_loss_probe (struct sock *sk);
net/ipv4/tcp_dctcp.c +4 -30
@@ -133,21 +133,8 @@ static void dctcp_ce_state_0_to_1(struct sock *sk)* ACK has not sent yet. */ if (!ca->ce_state && -inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) { -u32 tmp_rcv_nxt; - -/* Save current rcv_nxt. */ - tmp_rcv_nxt = tp->rcv_nxt; - -/* Generate previous ack with CE=0. */ - tp->ecn_flags &= ~TCP_ECN_DEMAND_CWR ; - tp->rcv_nxt = ca->prior_rcv_nxt; - -tcp_send_ack (sk); - -/* Recover current rcv_nxt. */ - tp->rcv_nxt = tmp_rcv_nxt; - } +inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) +__tcp_send_ack (sk, ca->prior_rcv_nxt); ca->prior_rcv_nxt = tp->rcv_nxt; ca->ce_state =1 ;
@@ -164,21 +151,8 @@ static void dctcp_ce_state_1_to_0(struct sock *sk)* ACK has not sent yet. */ if (ca->ce_state && -inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) { -u32 tmp_rcv_nxt; - -/* Save current rcv_nxt. */ - tmp_rcv_nxt = tp->rcv_nxt; - -/* Generate previous ack with CE=1. */ - tp->ecn_flags |=TCP_ECN_DEMAND_CWR ; - tp->rcv_nxt = ca->prior_rcv_nxt; - -tcp_send_ack (sk); - -/* Recover current rcv_nxt. */ - tp->rcv_nxt = tmp_rcv_nxt; - } +inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) +__tcp_send_ack (sk, ca->prior_rcv_nxt); ca->prior_rcv_nxt = tp->rcv_nxt; ca->ce_state =0 ;
net/ipv4/tcp_output.c +7 -3
@@ -160,7 +160,8 @@ static void tcp_event_data_sent(struct tcp_sock *tp, }/* Account for an ACK we sent. */ -static inline void tcp_event_ack_sent (struct sock *sk,unsigned int pkts) +static inline void tcp_event_ack_sent (struct sock *sk,unsigned int pkts, +u32 rcv_nxt) {struct tcp_sock *tp =tcp_sk (sk);
@@ -171,6 +172,9 @@ static inline void tcp_event_ack_sent(struct sock *sk, unsigned int pkts)if (hrtimer_try_to_cancel (&tp->compressed_ack_timer) ==1 )__sock_put (sk); } + +if (unlikely (rcv_nxt != tp->rcv_nxt)) +return ;/* Special ACK sent by DCTCP to reflect ECN */ tcp_dec_quickack_mode (sk, pkts);inet_csk_clear_xmit_timer (sk,ICSK_TIME_DACK ); }
@@ -1141,7 +1145,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, icsk->icsk_af_ops->send_check (sk, skb);if (likely (tcb->tcp_flags &TCPHDR_ACK )) -tcp_event_ack_sent (sk,tcp_skb_pcount (skb)); +tcp_event_ack_sent (sk,tcp_skb_pcount (skb), rcv_nxt);if (skb->len != tcp_header_size) {tcp_event_data_sent (tp, sk);
@@ -3613,12 +3617,12 @@ void __tcp_send_ack(struct sock *sk, u32 rcv_nxt)/* Send it off, this clears delayed acks for us. */ __tcp_transmit_skb (sk, buff,0 , (__force gfp_t )0 , rcv_nxt); } +EXPORT_SYMBOL_GPL (__tcp_send_ack);void tcp_send_ack (struct sock *sk) {__tcp_send_ack (sk,tcp_sk (sk)->rcv_nxt); } -EXPORT_SYMBOL_GPL (tcp_send_ack);/* This routine sends a packet with an out of date sequence * number. It assumes the other end will try to ack it.
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
PATCH 3/3 tcp: do not delay ACK in DCTCP upon CE status change
In reply to Yuchung ChengPer DCTCP RFC8257 (Section 3.2) the ACK reflecting the CE status change has to be sent immediately so the sender can respond quickly:
""" When receiving packets, the CE codepoint MUST be processed as follows:
1. If the CE codepoint is set and DCTCP.CE is false, set DCTCP.CE to true and send an immediate ACK.
2. If the CE codepoint is not set and DCTCP.CE is true, set DCTCP.CE to false and send an immediate ACK.
"""
Previously DCTCP implementation may continue to delay the ACK. This patch fixes that to implement the RFC by forcing an immediate ACK.
Tested with this packetdrill script provided by Larry Brakmo
0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 0.000 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 0.000 setsockopt(3, SOL_TCP, TCP_CONGESTION, "dctcp", 5) = 0 0.000 bind(3, ..., ...) = 0
0.000 listen(3, 1) = 0
0.100 < [ect0] SEW 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7> 0.100 > SE. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8> 0.110 < [ect0] . 1:1(0) ack 1 win 257
0.200 accept(3, ..., ...) = 4
+0 setsockopt(4, SOL_SOCKET, SO_DEBUG, [1], 4) = 0
0.200 < [ect0] . 1:1001(1000) ack 1 win 257
0.200 > [ect01] . 1:1(0) ack 1001
0.200 write(4, ..., 1) = 1
0.200 > [ect01] P. 1:2(1) ack 1001
0.200 < [ect0] . 1001:2001(1000) ack 2 win 257
+0.005 < [ce] . 2001:3001(1000) ack 2 win 257
+0.000 > [ect01] . 2:2(0) ack 2001
// Previously the ACK below would be delayed by 40ms +0.000 > [ect01] E. 2:2(0) ack 3001
+0.500 < F. 9501:9501(0) ack 4 win 257
--- include/net/tcp.h | 1 + net/ipv4/tcp_dctcp.c | 30 ++++++++++++++++++------------ net/ipv4/tcp_input.c | 3 ++- 3 files changed, 21 insertions(+), 13 deletions(-)
include/net/tcp.h +1 -0
@@ -342,6 +342,7 @@ ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags); +void tcp_enter_quickack_mode (struct sock *sk,unsigned int max_quickacks);static inline void tcp_dec_quickack_mode (struct sock *sk,const unsigned int pkts) {
net/ipv4/tcp_dctcp.c +18 -12
@@ -129,12 +129,15 @@ static void dctcp_ce_state_0_to_1(struct sock *sk)struct dctcp *ca =inet_csk_ca (sk);struct tcp_sock *tp =tcp_sk (sk); -/* State has changed from CE=0 to CE=1 and delayed -* ACK has not sent yet. -*/ -if (!ca->ce_state && -inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) -__tcp_send_ack (sk, ca->prior_rcv_nxt); +if (!ca->ce_state) { +/* State has changed from CE=0 to CE=1, force an immediate +* ACK to reflect the new CE state. If an ACK was delayed, +* send that first to reflect the prior CE state. +*/ +if (inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) +__tcp_send_ack (sk, ca->prior_rcv_nxt); +tcp_enter_quickack_mode (sk,1 ); + } ca->prior_rcv_nxt = tp->rcv_nxt; ca->ce_state =1 ;
@@ -147,12 +150,15 @@ static void dctcp_ce_state_1_to_0(struct sock *sk)struct dctcp *ca =inet_csk_ca (sk);struct tcp_sock *tp =tcp_sk (sk); -/* State has changed from CE=1 to CE=0 and delayed -* ACK has not sent yet. -*/ -if (ca->ce_state && -inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) -__tcp_send_ack (sk, ca->prior_rcv_nxt); +if (ca->ce_state) { +/* State has changed from CE=1 to CE=0, force an immediate +* ACK to reflect the new CE state. If an ACK was delayed, +* send that first to reflect the prior CE state. +*/ +if (inet_csk (sk)->icsk_ack.pending &ICSK_ACK_TIMER ) +__tcp_send_ack (sk, ca->prior_rcv_nxt); +tcp_enter_quickack_mode (sk,1 ); + } ca->prior_rcv_nxt = tp->rcv_nxt; ca->ce_state =0 ;
net/ipv4/tcp_input.c +2 -1
@@ -215,7 +215,7 @@ static void tcp_incr_quickack(struct sock *sk, unsigned int max_quickacks) icsk->icsk_ack.quick = quickacks; } -static void tcp_enter_quickack_mode (struct sock *sk,unsigned int max_quickacks) +void tcp_enter_quickack_mode (struct sock *sk,unsigned int max_quickacks) {struct inet_connection_sock *icsk =inet_csk (sk);
@@ -223,6 +223,7 @@ static void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks) icsk->icsk_ack.pingpong =0 ; icsk->icsk_ack.ato =TCP_ATO_MIN ; } +EXPORT_SYMBOL (tcp_enter_quickack_mode);/* Send ACKs quickly, if "quick" count is not exhausted * and the session is not interactive.
Signature · 1 line
2.18.0.203.gfac676dfb9-goog
Re: [PATCH net 1/3] tcp: helpers to send special DCTCP ack
In reply to Yuchung ChengQuoted 7 lines · Yuchung Cheng
Refactor and create helpers to send the special ACK in DCTCP.
Signed-off-by Yuchung Cheng <[email protected]>Acked-by Neal Cardwell <[email protected]>--- net/ipv4/tcp_output.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
tcp_send_ack() could be an inline, but that is a very minor point.
Re: [PATCH net 2/3] tcp: do not cancel delay-AcK on DCTCP special ACK
In reply to Yuchung ChengQuoted 17 lines · Yuchung Cheng
Currently when a DCTCP receiver delays an ACK and receive a data packet with a different CE mark from the previous one's, it sends two immediate ACKs acking previous and latest sequences respectly (for ECN accounting).
Previously sending the first ACK may mark off the delayed ACK timer (
tcp_event_ack_sent). This may subsequently prevent sending the second ACK to acknowledge the latest sequence (tcp_ack_snd_check). The culprit is thattcp_send_ack()assumes it always acknowleges the latest sequence, which is not true for the first special ACK.The fix is to not make the assumption in
tcp_send_ackand check the actual ack sequence before cancelling the delayed ACK. Further it's safer to pass the ack sequence number as a local variable intotcp_send_ackroutine, instead of interceptingtp->rcv_nxtto avoid future bugs like this.
Quoted 3 lines
Reported-by Neal Cardwell <[email protected]>Signed-off-by Yuchung Cheng <[email protected]>Acked-by Neal Cardwell <[email protected]>
Re: [PATCH net 3/3] tcp: do not delay ACK in DCTCP upon CE status change
In reply to Yuchung ChengQuoted 8 lines · Yuchung Cheng
Per DCTCP RFC8257 (Section 3.2) the ACK reflecting the CE status change has to be sent immediately so the sender can respond quickly:
""" When receiving packets, the CE codepoint MUST be processed as follows:
1. If the CE codepoint is set and DCTCP.CE is false, set DCTCP.CE to true and send an immediate ACK.
Quoted 6 lines
2. If the CE codepoint is not set and DCTCP.CE is true, set DCTCP.CE to false and send an immediate ACK.
"""Previously DCTCP implementation may continue to delay the ACK. This patch fixes that to implement the RFC by forcing an immediate ACK.
Oh well, more ACK packets ;)
David Miller
maintainerFrom: Yuchung Cheng <[email protected]>
Date: Wed, 18 Jul 2018 13:56:33 -0700
Quoted 4 lines
This patch set address that the existing DCTCP implementation does not fully implement the ACK policy specified in the RFC. This improves the responsiveness of CE status change particularly on flows with small inflight.
Series applied, and queued up for -stable, thanks.