Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3114615pxj; Mon, 7 Jun 2021 02:39:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+DFIOWAIQx3WUZ4Z2Fp68XOjcCPQ3rxUTxVoQh+ULaBge4pCGqIfcY7GbqSn8x78ncG1J X-Received: by 2002:a17:906:c42:: with SMTP id t2mr17201586ejf.68.1623058776498; Mon, 07 Jun 2021 02:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623058776; cv=none; d=google.com; s=arc-20160816; b=Fu4SsWJ/Zj+liCKl3GVzWheKAxRv4HX65+jvQ4tgjA6fMVyY9IJgbvXbNa/FoEwFqm L1X15i12GlhggVNHjuNKu49vFQDBh5l9TFGegdugxXT0icahU+wofv+aGdCUdMp1yT6M l900uyH2m+yWdCFW49XK0WMFjiFVAqWGeKDrIe/AOJii5Egmq2Yit+EY6j7u7ECKj8Tx /0PubBxILN9BsvgLo8l2fn9kBdH9p7O5g1B2tJuBPRPGZ1WKW4zv7ogaQpMYMeapUTgH LlyDVMZzFrFZGocubQMcoBIPJIUy6cGPlPygCZ18+nuqTJnR165lBiyE2y88VHTefkiD pTBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=9vOPvWQaFzjFDBlTUV9sfSOyJhM023Zyk+psuGsN2Qo=; b=Hyo4cAqpqmxRA/g4RtPJPtTeAGIhHwnDM2k341OmA6AK2u1cKuf8shnObnsPriZbLX cy4ZVaMDNcg5WJT0Fw/cYdIVfGDf55ZxPyK8sFlK4rLoKgRz4Lp+VUsftMVP8tcnbcDI LdHu+xscP5x5Tr2OjJxU2atcy7JA923eYCcbz15u/SUTBtyfv1CVfgu0kNFFfr1kDp/b 7QfJ5bprFfFt/+yuIOEd88uoKpbq7yDsr+JbRswQ4z87l84NemJRhsd77bl2GKrW1niM YSoAMpITC560/aiPwOHsp/D7RMmjpUnWmHS1lPlWdCkywCgubhJEVFuxE75Hfn5Ztafi zFHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f13si12100011edy.493.2021.06.07.02.39.13; Mon, 07 Jun 2021 02:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbhFGJhj (ORCPT + 99 others); Mon, 7 Jun 2021 05:37:39 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:50717 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhFGJhi (ORCPT ); Mon, 7 Jun 2021 05:37:38 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=chengshuyi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UbaGK7H_1623058536; Received: from localhost(mailfrom:chengshuyi@linux.alibaba.com fp:SMTPD_---0UbaGK7H_1623058536) by smtp.aliyun-inc.com(127.0.0.1); Mon, 07 Jun 2021 17:35:44 +0800 From: Shuyi Cheng To: chengshuyi@linux.alibaba.com, edumazet@google.com, davem@davemloft.net, kuba@kernel.org, yoshfuji@linux-ipv6.org, dsahern@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH net-next] net: tcp: Updating MSS, when the sending window is smaller than MSS. Date: Mon, 7 Jun 2021 17:35:34 +0800 Message-Id: <1623058534-78782-1-git-send-email-chengshuyi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the lo network card is used for communication, the tcp server reduces the size of the receiving buffer, causing the tcp client to have a delay of 200ms. Examples are as follows: Suppose that the MTU of the lo network card is 65536, and the tcp server sets the receive buffer size to 42KB. According to the tcp_bound_to_half_wnd function, the MSS of the server and client is 21KB. Then, the tcp server sets the buffer size of the connection to 16KB. At this time, the MSS of the server is 8KB, and the MSS of the client is still 21KB. But it will cause the client to fail to send the message, that is, tcp_write_xmit fails. Mainly because tcp_snd_wnd_test failed, and then entered the zero window detection phase, resulting in a 200ms delay. Therefore, we mainly modify two places. One is the tcp_current_mss function. When the sending window is smaller than the current mss, mss needs to be updated. The other is the tcp_bound_to_half_wnd function. When the sending window is smaller than the current mss, the mss value should be calculated according to the current sending window, not max_window. Signed-off-by: Shuyi Cheng --- include/net/tcp.h | 11 ++++++++--- net/ipv4/tcp_output.c | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index e668f1b..fcdef16 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -641,6 +641,11 @@ static inline void tcp_clear_xmit_timers(struct sock *sk) static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) { int cutoff; + int window; + + window = tp->max_window; + if (tp->snd_wnd && tp->snd_wnd < pktsize) + window = tp->snd_wnd; /* When peer uses tiny windows, there is no use in packetizing * to sub-MSS pieces for the sake of SWS or making sure there @@ -649,10 +654,10 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) * On the other hand, for extremely large MSS devices, handling * smaller than MSS windows in this way does make sense. */ - if (tp->max_window > TCP_MSS_DEFAULT) - cutoff = (tp->max_window >> 1); + if (window > TCP_MSS_DEFAULT) + cutoff = (window >> 1); else - cutoff = tp->max_window; + cutoff = window; if (cutoff && pktsize > cutoff) return max_t(int, cutoff, 68U - tp->tcp_header_len); diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index bde781f..88dcdf2 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -1833,7 +1833,8 @@ unsigned int tcp_current_mss(struct sock *sk) if (dst) { u32 mtu = dst_mtu(dst); - if (mtu != inet_csk(sk)->icsk_pmtu_cookie) + if (mtu != inet_csk(sk)->icsk_pmtu_cookie || + (tp->snd_wnd && tp->snd_wnd < mss_now)) mss_now = tcp_sync_mss(sk, mtu); } -- 1.8.3.1