Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1801803ybl; Sat, 1 Feb 2020 06:37:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzbOJL0pa4M5h3tvXt1lmeMlcNlAzpwv0vllN+d+81FXcPNT+OKKRTZJyH3UfmApQdPUqqf X-Received: by 2002:a05:6808:a08:: with SMTP id n8mr4865309oij.38.1580567845889; Sat, 01 Feb 2020 06:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580567845; cv=none; d=google.com; s=arc-20160816; b=ihHNuiYJ8+YvxucAkbXg0yaZZYvS2ZoWY1SfDC3fbVXL3f4QeJh4dtUjg1HGyw4KZI khmEGKQmkMlTWsvSrl92vvMRXO1DCBC+V505Cq0n6gOvZgGyJVH+pTzLCcOIt89S+X5F JeVbLdNH12Xm+avXYtm7r3SwGCAsvPKLX3w8v1Ch72qk61lIletWDsFmZCtkzBSEAGeR E5qEhCJ2FG5D6HWXHGZp/b7icysacBIhtf2bosqcRwzyhAl4Kqk6cWZE2/MCZlIOAdaW z/3i1oNIvtU4ZOkjJKSFfDUi/g4nAUne5RN+PLH363PKGQrkOs+TcrZtu8OukVLuElrq rMBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ToTlhUmffyf/A4SVkFIr/tfQPx5sGPUvI56+zcHPEUw=; b=qU5GDZ6NFvjpspNMjudfWTEUphrR+nrt+i7xVTH5pjiLfF1REJRSolgy/28UF6tbnB adx4YP0wIJbAEQOFNJN7EUT8GeojisdpokY0zE+zl9YiOWWn/LR/CGh2M81AoQfMCSJx meSH/SssCfZoveHYG7ZWvjegu2Ak1yY6syxPejeP+TY9YeSsSGIPame74JeJzuhFaDIx 2xH9j6E86riUOAJnGH/J13TDgbzr7eBwkt8MPOlZDl59oRiy7lU4AyuLAlqnhI6xV2pC AxEd4ggCOPFipJPVOf9rkyaTDxNjEvwmLshKZLaRD39T+9slWjymvxQAiuNGP5EojPon /okw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cfiA1kjc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si6181684otq.121.2020.02.01.06.37.13; Sat, 01 Feb 2020 06:37:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cfiA1kjc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbgBAOgS (ORCPT + 99 others); Sat, 1 Feb 2020 09:36:18 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:56031 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbgBAOgS (ORCPT ); Sat, 1 Feb 2020 09:36:18 -0500 Received: by mail-wm1-f66.google.com with SMTP id q9so11112308wmj.5; Sat, 01 Feb 2020 06:36:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to; bh=ToTlhUmffyf/A4SVkFIr/tfQPx5sGPUvI56+zcHPEUw=; b=cfiA1kjcC+BVeP9rXotWDpsyjbC+sJuhp+Xv8Oo5uG40Tl6RNehPE8FVbcESG+prbW 3Iu7m5yc8g1I7Ree380egdQKtrBapc6W2p+x5aNoxylxYlNgD/zOW/q52hFB0iNQyxqj K1ARpQV+GgaKcaEBPUVqRfdAbDqOyGRHPbBxa8JkgCB23IsZo9NrIyONQTC/W14sIq+Q vhKbaHiMpV4QWCUpMn/Ht/45ieORhzT57+Myp+qzsoLKBT1hQmAmXkhexrgthm3hXjkC tdUG1QGmnRNfyPTFXkPeH+PhKBqYotgqaaQDeF/EeSct+eVQsjzDIAoUfG+grOMiAbAt WciQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to; bh=ToTlhUmffyf/A4SVkFIr/tfQPx5sGPUvI56+zcHPEUw=; b=W1BepHMpFQ2DpM2W8RLiLpDpkrv4GNhyPCjY+1wHpEGYFbxKgrQakcxj6tH7VNqcTx P2Nq2pxx56hDIJf1TbRX674nmm07nK1jUb+8H+IDiLhf/1lVLJN4rPE0kW2p8gEBZLI6 JKw5AilXlDbjAidzn9qowmscwwALF/tl2rjR06LimwcymZXce46CksGXMfpG+FPcW31O sKvNbLfs5UQFhpTPt3KGWfuXdDNCdETu3CTBlhQ0ZsXF8G7K7kZDSIVvSgomY0ojVKSL nBY9ADwOfIdCFN6m3wDaX3UnkIx8PNKRyI7Mcj1talBUYus/iVeD89lIRu97tpjtkNFi c0rA== X-Gm-Message-State: APjAAAVLxdPz8YW02k/bpzn/e8SiM9epZjOPeQ8AsngOaZHi9p15sazG Etoyk+XLgXNich0GFGnBooNQxCOX0ns= X-Received: by 2002:a1c:a947:: with SMTP id s68mr18954093wme.61.1580567775804; Sat, 01 Feb 2020 06:36:15 -0800 (PST) Received: from localhost.localdomain ([88.128.88.116]) by smtp.gmail.com with ESMTPSA id b16sm17677481wrj.23.2020.02.01.06.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Feb 2020 06:36:14 -0800 (PST) From: SeongJae Park To: Neal Cardwell Cc: sj38.park@gmail.com, Eric Dumazet , Eric Dumazet , David Miller , aams@amazon.com, Netdev , linux-kselftest@vger.kernel.org, LKML , shuah@kernel.org, Yuchung Cheng , David Laight , SeongJae Park Subject: Re: Re: [PATCH v2 1/2] tcp: Reduce SYN resend delay if a suspicous ACK is received Date: Sat, 1 Feb 2020 15:36:08 +0100 Message-Id: <20200201143608.6742-1-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: (raw) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 1 Feb 2020 08:51:48 -0500 Neal Cardwell wrote: > On Sat, Feb 1, 2020 at 2:19 AM wrote: > > > > From: SeongJae Park > > > > When closing a connection, the two acks that required to change closing > > socket's status to FIN_WAIT_2 and then TIME_WAIT could be processed in > > reverse order. This is possible in RSS disabled environments such as a > > connection inside a host. > > > > For example, expected state transitions and required packets for the > > disconnection will be similar to below flow. > > > > 00 (Process A) (Process B) > > 01 ESTABLISHED ESTABLISHED > > 02 close() > > 03 FIN_WAIT_1 > > 04 ---FIN--> > > 05 CLOSE_WAIT > > 06 <--ACK--- > > 07 FIN_WAIT_2 > > 08 <--FIN/ACK--- > > 09 TIME_WAIT > > 10 ---ACK--> > > 11 LAST_ACK > > 12 CLOSED CLOSED > > > > In some cases such as LINGER option applied socket, the FIN and FIN/ACK > > will be substituted to RST and RST/ACK, but there is no difference in > > the main logic. > > > > The acks in lines 6 and 8 are the acks. If the line 8 packet is > > processed before the line 6 packet, it will be just ignored as it is not > > a expected packet, and the later process of the line 6 packet will > > change the status of Process A to FIN_WAIT_2, but as it has already > > handled line 8 packet, it will not go to TIME_WAIT and thus will not > > send the line 10 packet to Process B. Thus, Process B will left in > > CLOSE_WAIT status, as below. > > > > 00 (Process A) (Process B) > > 01 ESTABLISHED ESTABLISHED > > 02 close() > > 03 FIN_WAIT_1 > > 04 ---FIN--> > > 05 CLOSE_WAIT > > 06 (<--ACK---) > > 07 (<--FIN/ACK---) > > 08 (fired in right order) > > 09 <--FIN/ACK--- > > 10 <--ACK--- > > 11 (processed in reverse order) > > 12 FIN_WAIT_2 > > > > Later, if the Process B sends SYN to Process A for reconnection using > > the same port, Process A will responds with an ACK for the last flow, > > which has no increased sequence number. Thus, Process A will send RST, > > wait for TIMEOUT_INIT (one second in default), and then try > > reconnection. If reconnections are frequent, the one second latency > > spikes can be a big problem. Below is a tcpdump results of the problem: > > > > 14.436259 IP 127.0.0.1.45150 > 127.0.0.1.4242: Flags [S], seq 2560603644 > > 14.436266 IP 127.0.0.1.4242 > 127.0.0.1.45150: Flags [.], ack 5, win 512 > > 14.436271 IP 127.0.0.1.45150 > 127.0.0.1.4242: Flags [R], seq 2541101298 > > /* ONE SECOND DELAY */ > > 15.464613 IP 127.0.0.1.45150 > 127.0.0.1.4242: Flags [S], seq 2560603644 > > > > This commit mitigates the problem by reducing the delay for the next SYN > > if the suspicous ACK is received while in SYN_SENT state. > > > > Following commit will add a selftest, which can be also helpful for > > understanding of this issue. > > > > Signed-off-by: SeongJae Park > > --- > > net/ipv4/tcp_input.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > > index 2a976f57f7e7..980bd04b9d95 100644 > > --- a/net/ipv4/tcp_input.c > > +++ b/net/ipv4/tcp_input.c > > @@ -5893,8 +5893,14 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, > > * the segment and return)" > > */ > > if (!after(TCP_SKB_CB(skb)->ack_seq, tp->snd_una) || > > - after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) > > + after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) { > > + /* Previous FIN/ACK or RST/ACK might be ignored. */ > > + if (icsk->icsk_retransmits == 0) > > + inet_csk_reset_xmit_timer(sk, > > + ICSK_TIME_RETRANS, TCP_ATO_MIN, > > + TCP_RTO_MAX); > > goto reset_and_undo; > > + } > > > > if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && > > !between(tp->rx_opt.rcv_tsecr, tp->retrans_stamp, > > -- > > Scheduling a timer for TCP_ATO_MIN, typically 40ms, sounds like it > might be a bit on the slow side. How about TCP_TIMEOUT_MIN, which is > typically 2ms on a HZ=1000 kernel? > > I think this would be closer to what Eric mentioned: "sending the SYN > a few ms after the RST seems way better than waiting 1 second as if we > received no packet at all." Agreed, it seems much better! Because this is just a small change in a tiny patchset containing only two patches, I will send the updated version of only this patch in reply to this mail, as soon as I finish tests. Thanks, SeongJae Park > > neal