Skip to content

Commit a0496ef

Browse files
yuchungchengdavem330
authored andcommitted
tcp: do not delay ACK in DCTCP upon CE status change
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. 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 Signed-off-by: Yuchung Cheng <ycheng@google.com> Acked-by: Neal Cardwell <ncardwell@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27cde44 commit a0496ef

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎include/net/tcp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos,
342342
struct pipe_inode_info *pipe, size_t len,
343343
unsigned int flags);
344344

345+
void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks);
345346
static inline void tcp_dec_quickack_mode(struct sock *sk,
346347
const unsigned int pkts)
347348
{

‎net/ipv4/tcp_dctcp.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@ static void dctcp_ce_state_0_to_1(struct sock *sk)
129129
struct dctcp *ca = inet_csk_ca(sk);
130130
struct tcp_sock *tp = tcp_sk(sk);
131131

132-
/* State has changed from CE=0 to CE=1 and delayed
133-
* ACK has not sent yet.
134-
*/
135-
if (!ca->ce_state &&
136-
inet_csk(sk)->icsk_ack.pending & ICSK_ACK_TIMER)
137-
__tcp_send_ack(sk, ca->prior_rcv_nxt);
132+
if (!ca->ce_state) {
133+
/* State has changed from CE=0 to CE=1, force an immediate
134+
* ACK to reflect the new CE state. If an ACK was delayed,
135+
* send that first to reflect the prior CE state.
136+
*/
137+
if (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_TIMER)
138+
__tcp_send_ack(sk, ca->prior_rcv_nxt);
139+
tcp_enter_quickack_mode(sk, 1);
140+
}
138141

139142
ca->prior_rcv_nxt = tp->rcv_nxt;
140143
ca->ce_state = 1;
@@ -147,12 +150,15 @@ static void dctcp_ce_state_1_to_0(struct sock *sk)
147150
struct dctcp *ca = inet_csk_ca(sk);
148151
struct tcp_sock *tp = tcp_sk(sk);
149152

150-
/* State has changed from CE=1 to CE=0 and delayed
151-
* ACK has not sent yet.
152-
*/
153-
if (ca->ce_state &&
154-
inet_csk(sk)->icsk_ack.pending & ICSK_ACK_TIMER)
155-
__tcp_send_ack(sk, ca->prior_rcv_nxt);
153+
if (ca->ce_state) {
154+
/* State has changed from CE=1 to CE=0, force an immediate
155+
* ACK to reflect the new CE state. If an ACK was delayed,
156+
* send that first to reflect the prior CE state.
157+
*/
158+
if (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_TIMER)
159+
__tcp_send_ack(sk, ca->prior_rcv_nxt);
160+
tcp_enter_quickack_mode(sk, 1);
161+
}
156162

157163
ca->prior_rcv_nxt = tp->rcv_nxt;
158164
ca->ce_state = 0;

‎net/ipv4/tcp_input.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ static void tcp_incr_quickack(struct sock *sk, unsigned int max_quickacks)
215215
icsk->icsk_ack.quick = quickacks;
216216
}
217217

218-
static void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks)
218+
void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks)
219219
{
220220
struct inet_connection_sock *icsk = inet_csk(sk);
221221

222222
tcp_incr_quickack(sk, max_quickacks);
223223
icsk->icsk_ack.pingpong = 0;
224224
icsk->icsk_ack.ato = TCP_ATO_MIN;
225225
}
226+
EXPORT_SYMBOL(tcp_enter_quickack_mode);
226227

227228
/* Send ACKs quickly, if "quick" count is not exhausted
228229
* and the session is not interactive.

0 commit comments

Comments
 (0)