Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3709801rwb; Mon, 7 Aug 2023 19:25:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9dbG1s/IREsBjj8FqPGiwy127iyUTbm5pcowKoXjqfjiw3PzXchOh2tbk4zim4AXtEuWB X-Received: by 2002:a17:907:78c8:b0:98f:8481:24b3 with SMTP id kv8-20020a17090778c800b0098f848124b3mr9256437ejc.37.1691461543573; Mon, 07 Aug 2023 19:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691461543; cv=none; d=google.com; s=arc-20160816; b=VEqatS4zI0zN5InDh/5iQhh5Ju6PRkrCS3ACYAGE3UtTkliY64O/9wj2bJgVn+vnzs AKZfaXHqeRS/VPo/cMsdYNBlzsrnDu0kjUFpCqwIWBdJuXaZad/2UMWNxVcJuExaXV7r RuOAeSZb4hAsCzL8O93xVoRGjxsXcue8qHZR8aEd9yjQJLu1EtRqNlmarGmcoWXeI8EY SDgio8eB0VwXxtyxlbPKdi8ATDvwq1YW6zWffv8F9evCSar1DkPbm1M9+vTFEeT1EHuM lhQEl0raz3egUcenveS5qwRuaeL3ftV4ikTPcJrvPYbE56TUHoccaeIZCz/IPv7uY7dN ti4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8vbR+3AXDJwndsjWTNdO9o3kq69tlinQ654fL9RtrZ4=; fh=4oOjgGHCQKScQt8OalkLOEr9H0OzhErBk9VGPlbpQX4=; b=yFMVYUOobUfpfyqDhzdTvf2q+w4R2cqXPOzj8PMcPggPO7QoV6iwLdS6Gge2WIM8+3 JyzmS8fE8Pd9yquuGvYVRSUlIUy9EK+gzFaTNMGDbvU7lSymwSU/dtoqEkKGc+2jHhoB 0L33BELD1aJaydzMh+9JLUm3GgrWNxRqb2SOcR4uAHOesO36yvJtRQpmSuCJXUWNQ3/b qL68MlpHCBA8hu0MzH689zQcP3JJ8De8SDqSewCPrlwT6koZ+a6bEl/BiREKkczJqYOR w+K9BoNkoLZp97e6VamUiOdy8Zd8AnD7IzmY8wm0mwC86k/4yi6+VI1iwJZ4ELeDB1Za k5MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=oy20Rb49; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a1709064d9100b0099c971a698asi3227186eju.179.2023.08.07.19.25.18; Mon, 07 Aug 2023 19:25:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=oy20Rb49; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229983AbjHHB6a (ORCPT + 99 others); Mon, 7 Aug 2023 21:58:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjHHB63 (ORCPT ); Mon, 7 Aug 2023 21:58:29 -0400 Received: from mail-yb1-xb42.google.com (mail-yb1-xb42.google.com [IPv6:2607:f8b0:4864:20::b42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF189F1; Mon, 7 Aug 2023 18:58:28 -0700 (PDT) Received: by mail-yb1-xb42.google.com with SMTP id 3f1490d57ef6-d3563cb41e9so4285923276.0; Mon, 07 Aug 2023 18:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691459908; x=1692064708; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8vbR+3AXDJwndsjWTNdO9o3kq69tlinQ654fL9RtrZ4=; b=oy20Rb49UbMDTh1WwIzKz9xsAcSuB3bmzVm87cc9ts2dYBIqAJehfFV6m2zhpDCiYO 1H/ukdmkfOTjW1fWe4nxWYIV7NBmUr2rqK875tKI8x9TLx3F/bHgLklJ6P9/dIIx9cXU XW2T1QZRo7bsDqLYhDBJ61/EJQHPDVJYcdNdY/ZVcE7iD59HbR9sjT18jS/oX//tgqcm 8AixuTjznnRMtGpVjnzPTds2O26k1K+tSt6gXUz9b1gpQ1n1gplBO0Qs7d58lm3oF3TS JU5IGpdZEnBmvW8WqIhCcEpH4xHJJhpMjr/gKhqWnfWnfH7aSgW4c/Y3K0E2ix6hONUe nqYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691459908; x=1692064708; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8vbR+3AXDJwndsjWTNdO9o3kq69tlinQ654fL9RtrZ4=; b=J84dtNdSDSjatL4kIsayKOLRaVXIw8V2hxz91ORHEr/IzZxjuwCaha7GOTobwdQsy1 s0eRb0wVAdJOqdGEhHYWvBuwfTKvsOWtDQMhN30rfFHqIUi5/TyNeEyKows/YCO/vLiu GKX9iM1fQ0sfsuQL9LDOz5ubb1EWPqM4/n+ibVHNuZn42jSjyNDqQtNCFESL+Ru9kEkr vJ5qnWgLM9lluBBBi2X5PdTn4Uvt/I//LIdV8AVGEOePS3kFtfNbn2En5GljEOHPiwwS +WynD5VwqnVvCNzApM8e5FSxp3sHogg2gxVyvZY/aeCnH+zmVnkkNaJ+m+M3Dv3AZEiR +pzQ== X-Gm-Message-State: AOJu0Yx/pGj6oxdSv0kkrgSDDaN2umYp4aTQnwV05ymJbrORFxjGsRmu hhoDtoYUvIxK19c082czPN4NJxabqG6TOI0Awq29G7d2oxBfK/IC X-Received: by 2002:a25:410e:0:b0:d4c:83a8:268d with SMTP id o14-20020a25410e000000b00d4c83a8268dmr5489882yba.38.1691459907805; Mon, 07 Aug 2023 18:58:27 -0700 (PDT) MIME-Version: 1.0 References: <20230807134547.2782227-1-imagedong@tencent.com> <20230807134547.2782227-2-imagedong@tencent.com> In-Reply-To: From: Menglong Dong Date: Tue, 8 Aug 2023 09:58:16 +0800 Message-ID: Subject: Re: [PATCH net-next v2 1/3] net: tcp: send zero-window ACK when no memory To: Eric Dumazet Cc: ncardwell@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 7, 2023 at 10:05=E2=80=AFPM Eric Dumazet = wrote: > > On Mon, Aug 7, 2023 at 3:47=E2=80=AFPM wrote: > > > > From: Menglong Dong > > > > For now, skb will be dropped when no memory, which makes client keep > > retrans util timeout and it's not friendly to the users. > > > > In this patch, we reply an ACK with zero-window in this case to update > > the snd_wnd of the sender to 0. Therefore, the sender won't timeout the > > connection and will probe the zero-window with the retransmits. > > > > Signed-off-by: Menglong Dong > > --- > > v2: > > - send 0 rwin ACK for the receive queue empty case when necessary > > - send the ACK immediately by using the ICSK_ACK_NOW flag > > --- > > include/net/inet_connection_sock.h | 3 ++- > > net/ipv4/tcp_input.c | 14 +++++++++++--- > > net/ipv4/tcp_output.c | 14 +++++++++++--- > > 3 files changed, 24 insertions(+), 7 deletions(-) > > > > diff --git a/include/net/inet_connection_sock.h b/include/net/inet_conn= ection_sock.h > > index c2b15f7e5516..be3c858a2ebb 100644 > > --- a/include/net/inet_connection_sock.h > > +++ b/include/net/inet_connection_sock.h > > @@ -164,7 +164,8 @@ enum inet_csk_ack_state_t { > > ICSK_ACK_TIMER =3D 2, > > ICSK_ACK_PUSHED =3D 4, > > ICSK_ACK_PUSHED2 =3D 8, > > - ICSK_ACK_NOW =3D 16 /* Send the next ACK immediately (onc= e) */ > > + ICSK_ACK_NOW =3D 16, /* Send the next ACK immediately (onc= e) */ > > + ICSK_ACK_NOMEM =3D 32, > > }; > > > > void inet_csk_init_xmit_timers(struct sock *sk, > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > > index 8e96ebe373d7..aae485d0a3b6 100644 > > --- a/net/ipv4/tcp_input.c > > +++ b/net/ipv4/tcp_input.c > > @@ -5059,12 +5059,20 @@ static void tcp_data_queue(struct sock *sk, str= uct sk_buff *skb) > > > > /* Ok. In sequence. In window. */ > > queue_and_out: > > - if (skb_queue_len(&sk->sk_receive_queue) =3D=3D 0) > > - sk_forced_mem_schedule(sk, skb->truesize); > > - else if (tcp_try_rmem_schedule(sk, skb, skb->truesize))= { > > + if (skb_queue_len(&sk->sk_receive_queue) =3D=3D 0) { > > + if (tcp_try_rmem_schedule(sk, skb, skb->truesiz= e)) { > > + sk_forced_mem_schedule(sk, skb->truesiz= e); > > I think we want sk->sk_data_ready() here, to let applications drain the q= ueue, > regardless of sk->sk_rcvlowat value. > > > > + inet_csk(sk)->icsk_ack.pending |=3D > > + (ICSK_ACK_NOMEM | ICSK_ACK_NOW)= ; > > + inet_csk_schedule_ack(sk); > > + } > > + } else if (tcp_try_rmem_schedule(sk, skb, skb->truesize= )) { > > reason =3D SKB_DROP_REASON_PROTO_MEM; > > NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDR= OP); > > sk->sk_data_ready(sk); > > We also want to keep this sk->sk_data_ready(sk) call. > > > + inet_csk(sk)->icsk_ack.pending |=3D > > + (ICSK_ACK_NOMEM | ICSK_ACK_NOW); > > + inet_csk_schedule_ack(sk); > > goto drop; > > } > > This would suggest a different code refactoring, to avoid code duplicatio= n. > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > index 57c8af1859c16eba5e952a23ea959b628006f9c1..dde6c44f2c1e33dcf60c23b49= cd99f270874ca96 > 100644 > --- a/net/ipv4/tcp_input.c > +++ b/net/ipv4/tcp_input.c > @@ -5050,13 +5050,17 @@ static void tcp_data_queue(struct sock *sk, > struct sk_buff *skb) > > /* Ok. In sequence. In window. */ > queue_and_out: > - if (skb_queue_len(&sk->sk_receive_queue) =3D=3D 0) > - sk_forced_mem_schedule(sk, skb->truesize); > - else if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { > - reason =3D SKB_DROP_REASON_PROTO_MEM; > - NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPRCVQDROP= ); > + if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { > + /* TODO: maybe ratelimit these WIN 0 ACK ? */ > + inet_csk(sk)->icsk_ack.pending |=3D > CSK_ACK_NOMEM | ICSK_ACK_NOW; > + inet_csk_schedule_ack(sk); > sk->sk_data_ready(sk); > - goto drop; > + if (skb_queue_len(&sk->sk_receive_queue)) { > + reason =3D SKB_DROP_REASON_PROTO_MEM; > + NET_INC_STATS(sock_net(sk), > LINUX_MIB_TCPRCVQDROP); > + goto drop; > + } > + sk_forced_mem_schedule(sk, skb->truesize); > } > > eaten =3D tcp_queue_rcv(sk, skb, &fragstolen); Looks much better, thank you!