Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C88FBC43387 for ; Wed, 16 Jan 2019 23:06:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 933EA20675 for ; Wed, 16 Jan 2019 23:06:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dtrcGBMm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387975AbfAPXGB (ORCPT ); Wed, 16 Jan 2019 18:06:01 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43241 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387904AbfAPXFz (ORCPT ); Wed, 16 Jan 2019 18:05:55 -0500 Received: by mail-pl1-f195.google.com with SMTP id gn14so3724065plb.10 for ; Wed, 16 Jan 2019 15:05:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wTu0k4hqSiiGyJUjl4skW273vNwz4o/PabdANwcl1s8=; b=dtrcGBMmHIG6MH+vsYPzmbTC3hA4LJ8np+OX1wSEI4XhFwuSTsulPULO1u7KiDWQlB AOufAwbjXKabhA3qWmMfFI07LbkH35oSFMgsq2Tx1sIj4MYyn9gYJrPZp9vY7zAMdBpA GP9q18PfevQMZnR/ttluAHOjWV+SIckpi6h2eSlDlDYrctC+GvTeygQSKMExi+sdIG8B vQ5+mUI89k7YP8s2emdJd3i7FdkNI+Qki26xAwYZalTACrmlQH9ryUaWh11c7w98n3Ku +pbKvsvYVNGdDhT7JSzWikdrBLUoigIKOfMG91KGDYykmbhF05hifvkb5YJHWlTJyW3s 5QyA== 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 :references:mime-version:content-transfer-encoding; bh=wTu0k4hqSiiGyJUjl4skW273vNwz4o/PabdANwcl1s8=; b=BxUfufUV/v+ee9mexxoFge0jmWT5LqThT4yMxE6UDpSEPG7DOVcDMNdmx6EVEkH3sH oUi3jmvAdY1HcG6KFFwceJfj3ZWgtWKqGU4sJVSgrXAW8UWf80933ie5hWCHRV76OlsG 6zOSbXs7Qat7DaFbzoWXy6j5mCrFprFbAkefbNpj+Pbu41/9Ha0bpsVZ7cezh0AiqjXC VoP2TemWnouCkp2aLvLsBWFgG++DvcOZH8eWFRfURIhIO2tnzJN44SCXKGeXu7DdrAfw RngXfYiuQH+H5ug2td9N3PMAqcX+ULTHrYYhOLRY3v+hQROLGnfvmJnbD9urvBhr9a2a bRzg== X-Gm-Message-State: AJcUukcGWPmsX0Oa2kjQHPjZc/se+SWnr841AKon1Tjx2Y7WwkTtD8qC ASa/kzeUvVxgJSDjpuNxuAnplg== X-Google-Smtp-Source: ALg8bN66GQh2At/D3mSMI3iszUXutANDm7XalvU+MYQUS4qzrrKg9JKN3I+IaqsFHjppD0kcMSWa1A== X-Received: by 2002:a17:902:8a8a:: with SMTP id p10mr12561013plo.50.1547679954574; Wed, 16 Jan 2019 15:05:54 -0800 (PST) Received: from ycheng2.svl.corp.google.com ([2620:15c:2c4:201:d660:6c0b:8a4f:4c77]) by smtp.gmail.com with ESMTPSA id k186sm8481087pge.13.2019.01.16.15.05.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 15:05:53 -0800 (PST) From: Yuchung Cheng To: davem@davemloft.net, edumazet@google.com Cc: netdev@vger.kernel.org, ncardwell@google.com, soheil@google.com, Yuchung Cheng Subject: [PATCH net-next 3/8] tcp: always set retrans_stamp on recovery Date: Wed, 16 Jan 2019 15:05:30 -0800 Message-Id: <20190116230535.162758-4-ycheng@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190116230535.162758-1-ycheng@google.com> References: <20190116230535.162758-1-ycheng@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Previously TCP socket's retrans_stamp is not set if the retransmission has failed to send. As a result if a socket is experiencing local issues to retransmit packets, determining when to abort a socket is complicated w/o knowning the starting time of the recovery since retrans_stamp may remain zero. This complication causes sub-optimal behavior that TCP may use the latest, instead of the first, retransmission time to compute the elapsed time of a stalling connection due to local issues. Then TCP may disrecard TCP retries settings and keep retrying until it finally succeed: not a good idea when the local host is already strained. The simple fix is to always timestamp the start of a recovery. It's worth noting that retrans_stamp is also used to compare echo timestamp values to detect spurious recovery. This patch does not break that because retrans_stamp is still later than when the original packet was sent. Signed-off-by: Yuchung Cheng Signed-off-by: Eric Dumazet Reviewed-by: Neal Cardwell Reviewed-by: Soheil Hassas Yeganeh --- net/ipv4/tcp_output.c | 9 ++++----- net/ipv4/tcp_timer.c | 23 +++-------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 57a56e205070..d2d494c74811 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2963,13 +2963,12 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs) #endif TCP_SKB_CB(skb)->sacked |= TCPCB_RETRANS; tp->retrans_out += tcp_skb_pcount(skb); - - /* Save stamp of the first retransmit. */ - if (!tp->retrans_stamp) - tp->retrans_stamp = tcp_skb_timestamp(skb); - } + /* Save stamp of the first (attempted) retransmit. */ + if (!tp->retrans_stamp) + tp->retrans_stamp = tcp_skb_timestamp(skb); + if (tp->undo_retrans < 0) tp->undo_retrans = 0; tp->undo_retrans += tcp_skb_pcount(skb); diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index e7d09e3705b8..1e61f0bd6e24 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c @@ -22,28 +22,14 @@ #include #include -static u32 tcp_retransmit_stamp(const struct sock *sk) -{ - u32 start_ts = tcp_sk(sk)->retrans_stamp; - - if (unlikely(!start_ts)) { - struct sk_buff *head = tcp_rtx_queue_head(sk); - - if (!head) - return 0; - start_ts = tcp_skb_timestamp(head); - } - return start_ts; -} - static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); u32 elapsed, start_ts; s32 remaining; - start_ts = tcp_retransmit_stamp(sk); - if (!icsk->icsk_user_timeout || !start_ts) + start_ts = tcp_sk(sk)->retrans_stamp; + if (!icsk->icsk_user_timeout) return icsk->icsk_rto; elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts; remaining = icsk->icsk_user_timeout - elapsed; @@ -197,10 +183,7 @@ static bool retransmits_timed_out(struct sock *sk, if (!inet_csk(sk)->icsk_retransmits) return false; - start_ts = tcp_retransmit_stamp(sk); - if (!start_ts) - return false; - + start_ts = tcp_sk(sk)->retrans_stamp; if (likely(timeout == 0)) { linear_backoff_thresh = ilog2(TCP_RTO_MAX/rto_base); -- 2.20.1.97.g81188d93c3-goog