From patchwork Tue Sep 20 03:39:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neal Cardwell X-Patchwork-Id: 672079 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sdT6s13wlz9rxm for ; Tue, 20 Sep 2016 13:40:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=PYATddma; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932441AbcITDkb (ORCPT ); Mon, 19 Sep 2016 23:40:31 -0400 Received: from mail-qk0-f182.google.com ([209.85.220.182]:35209 "EHLO mail-qk0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753870AbcITDjh (ORCPT ); Mon, 19 Sep 2016 23:39:37 -0400 Received: by mail-qk0-f182.google.com with SMTP id t7so4310713qkh.2 for ; Mon, 19 Sep 2016 20:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zXfcn9O1ry/Cz4YUbaAQiIeyruh/VCDa0Hx4jGK5IPY=; b=PYATddmayn7ysJZ5Q7IKt+uGKgpAiCSDQDquZAA2CUN+qyzriu4sES9gBaFxFOBQdh VkGq7ahCBAiEwzmyduTPc5V/wfGWnXXLGjmaPxOB2medRyf76eIQFMNa60rk0ULj+eAp ab3ieVM5zy2F/NHBgP3UJXf3vsqU5FkweSYOp/hMWXc7aq7+DxWTmcRUiBQ8kxLvLLT9 yeIigFLvTHdeCuqD1b4pr+/bi0hz7f89r6EiVZmskORC9Snq1EIYMzF5zoQNBPq3KgD0 p54oKPwb32tZJdxZRh3XTxYXf5w6rH6xTrKy0S6robCEOmGSOwxS1AC+tdoIGCo3tUbi pSJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zXfcn9O1ry/Cz4YUbaAQiIeyruh/VCDa0Hx4jGK5IPY=; b=jnbjZUXDUudmGUqkkrpo88fl0S6fIz+l50i7Suvi6+QzFSwABkYpmPfN9AU4zRZWbx 6/8XK1ELykAkDzX4s6tYQfjEKCiHfQWjKkws4STQJPe763nejHVyCejGi3vKHJU3Vvf4 u/WurZhObQgNM7zmopfTIXdizY1otSTSCZ2mDq+Xa9TTdmXfaEgkn5HYG6Xt+sSkJEGH btHGP3IitHSyZy4fAHRflbXqrP37nrcdHrJ9RiJ7KgCxpmR6Y+/50veaRyWYC5hRpip0 UnTUogAyd6z0luQlQNAqfonBoNpjsgm3k+x3Kl8aOHxLAlhV6TVV3Ww5d14e6IoYC9qc od8A== X-Gm-Message-State: AE9vXwOATKVROz6OZBpS/CiyjHKJKRZNyJh+Ya0td9AISRh6wuAYJrcCCy9eNVZniVx3fsFg X-Received: by 10.55.159.77 with SMTP id i74mr32904085qke.60.1474342776472; Mon, 19 Sep 2016 20:39:36 -0700 (PDT) Received: from joy.nyc.corp.google.com ([100.101.230.104]) by smtp.gmail.com with ESMTPSA id m4sm14901942qkf.29.2016.09.19.20.39.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Sep 2016 20:39:35 -0700 (PDT) From: Neal Cardwell To: David Miller Cc: netdev@vger.kernel.org, Neal Cardwell , Van Jacobson , Yuchung Cheng , Nandita Dukkipati , Eric Dumazet , Soheil Hassas Yeganeh Subject: [PATCH v4 net-next 06/16] tcp: count packets marked lost for a TCP connection Date: Mon, 19 Sep 2016 23:39:13 -0400 Message-Id: <1474342763-16715-7-git-send-email-ncardwell@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1474342763-16715-1-git-send-email-ncardwell@google.com> References: <1474342763-16715-1-git-send-email-ncardwell@google.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Count the number of packets that a TCP connection marks lost. Congestion control modules can use this loss rate information for more intelligent decisions about how fast to send. Specifically, this is used in TCP BBR policer detection. BBR uses a high packet loss rate as one signal in its policer detection and policer bandwidth estimation algorithm. The BBR policer detection algorithm cannot simply track retransmits, because a retransmit can be (and often is) an indicator of packets lost long, long ago. This is particularly true in a long CA_Loss period that repairs the initial massive losses when a policer kicks in. Signed-off-by: Van Jacobson Signed-off-by: Neal Cardwell Signed-off-by: Yuchung Cheng Signed-off-by: Nandita Dukkipati Signed-off-by: Eric Dumazet Signed-off-by: Soheil Hassas Yeganeh --- include/linux/tcp.h | 1 + net/ipv4/tcp_input.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 6433cc8..38590fb 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -267,6 +267,7 @@ struct tcp_sock { * receiver in Recovery. */ u32 prr_out; /* Total number of pkts sent during Recovery. */ u32 delivered; /* Total data packets delivered incl. rexmits */ + u32 lost; /* Total data packets lost incl. rexmits */ u32 rcv_wnd; /* Current receiver window */ u32 write_seq; /* Tail(+1) of data held in tcp send buffer */ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index ac5b38f..024b579 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -899,12 +899,29 @@ static void tcp_verify_retransmit_hint(struct tcp_sock *tp, struct sk_buff *skb) tp->retransmit_high = TCP_SKB_CB(skb)->end_seq; } +/* Sum the number of packets on the wire we have marked as lost. + * There are two cases we care about here: + * a) Packet hasn't been marked lost (nor retransmitted), + * and this is the first loss. + * b) Packet has been marked both lost and retransmitted, + * and this means we think it was lost again. + */ +static void tcp_sum_lost(struct tcp_sock *tp, struct sk_buff *skb) +{ + __u8 sacked = TCP_SKB_CB(skb)->sacked; + + if (!(sacked & TCPCB_LOST) || + ((sacked & TCPCB_LOST) && (sacked & TCPCB_SACKED_RETRANS))) + tp->lost += tcp_skb_pcount(skb); +} + static void tcp_skb_mark_lost(struct tcp_sock *tp, struct sk_buff *skb) { if (!(TCP_SKB_CB(skb)->sacked & (TCPCB_LOST|TCPCB_SACKED_ACKED))) { tcp_verify_retransmit_hint(tp, skb); tp->lost_out += tcp_skb_pcount(skb); + tcp_sum_lost(tp, skb); TCP_SKB_CB(skb)->sacked |= TCPCB_LOST; } } @@ -913,6 +930,7 @@ void tcp_skb_mark_lost_uncond_verify(struct tcp_sock *tp, struct sk_buff *skb) { tcp_verify_retransmit_hint(tp, skb); + tcp_sum_lost(tp, skb); if (!(TCP_SKB_CB(skb)->sacked & (TCPCB_LOST|TCPCB_SACKED_ACKED))) { tp->lost_out += tcp_skb_pcount(skb); TCP_SKB_CB(skb)->sacked |= TCPCB_LOST; @@ -1890,6 +1908,7 @@ void tcp_enter_loss(struct sock *sk) struct sk_buff *skb; bool new_recovery = icsk->icsk_ca_state < TCP_CA_Recovery; bool is_reneg; /* is receiver reneging on SACKs? */ + bool mark_lost; /* Reduce ssthresh if it has not yet been made inside this window. */ if (icsk->icsk_ca_state <= TCP_CA_Disorder || @@ -1923,8 +1942,12 @@ void tcp_enter_loss(struct sock *sk) if (skb == tcp_send_head(sk)) break; + mark_lost = (!(TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) || + is_reneg); + if (mark_lost) + tcp_sum_lost(tp, skb); TCP_SKB_CB(skb)->sacked &= (~TCPCB_TAGBITS)|TCPCB_SACKED_ACKED; - if (!(TCP_SKB_CB(skb)->sacked&TCPCB_SACKED_ACKED) || is_reneg) { + if (mark_lost) { TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_ACKED; TCP_SKB_CB(skb)->sacked |= TCPCB_LOST; tp->lost_out += tcp_skb_pcount(skb);