From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by passt.top (Postfix) with ESMTPS id 6B34F5A026E for ; Sun, 7 Apr 2024 08:52:31 +0200 (CEST) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2d485886545so61129501fa.2 for ; Sat, 06 Apr 2024 23:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712472751; x=1713077551; darn=passt.top; 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=qAyXqvt9U8fHKk0W6h9uw+yrsIp/DxsfeA5YNrlsGVw=; b=nEKqx6EDyhXAL8NJWcTOzqjReoCBgKJrxhr0LZcQggQVhbO5Wh0uQ2XgxiE5zQNwsu uz6NphrvlYgUMlW+CDJvx00sVD0AnbQbJSq9V2CDNRiQ+b331qLOSTbrUSNJplWx8//h 2HEO1QR89CwDIgwvpY1BFCCUP9vu9HKc6Y46CJyUU82FZYI13cMpQc8tDlaAaCuiB6Uw Z15Uq4UJhbBz27Oi+5yMY2YSGgk5ljMAbBBAVNNzndaexigfmH+3gps8Rx01dPtocEix KckcJUESvNUPOYjpC8/tDO3D6DLnHMFpDCGVQUrdGhJcly4NaOctzTzfcQKV5tNcrl1Q G7zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712472751; x=1713077551; 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=qAyXqvt9U8fHKk0W6h9uw+yrsIp/DxsfeA5YNrlsGVw=; b=xByd3RF/YJYvYhBU31/IdWnzaFX2I9xMqsTccpOnF2YdWaNZPrwD9/Sv24CTD+i4gi wN3vqustJP1SjC4Qr09oucp1MmmTyBMMdmynwB99ZZ6khGfnb/VY/xcu7DBEOt8Lpgj7 FQ9sIFg5wXBtLsQ5kFzxsOaEqqNEogII/XyuXge0ESfZ1QPOUCLpik7mdYMHWarRrwsM nMET4gqlwNAAjg6G2msArGLDEDxjxhFK9ld2ndHkSI6NlGu6DDIe0c/tbffUcUtZytO5 9oiuDz2VMkZQR3dqVeRmiXh4Np6JT5b+XigV3lWuvUl+FRyHFpnvs94naJZpqsrzIOjb kYLg== X-Forwarded-Encrypted: i=1; AJvYcCU7a0p1BQ1QH/nB6oXD/ayfKoNQ7h3QuJaxIMD/RsXax9I6kJ+WhfypP5FY5qdnkS3vAfIpNzCxxa9fHGedoe8PyykD X-Gm-Message-State: AOJu0Yw91rszYPR6FdWWhectDIFP7wYfSK6lk9nIiiAMt+bZTlKyBnlA mp9nFaHNycGWHtRp4yWLWV3xEYbdpPsartthCUzQGn+qDAQTXcgVLRQqeVZSaUAsy5Gi6qIUf7H diZZMR8L+UNTjUQdNPCptDYDz2tE= X-Google-Smtp-Source: AGHT+IEJ996UMY19e4Z8jgo/X/gDlHqevvLbWrco9JNElM8yycbUya6s5V0k+yRgnnZPZHbmv6z/dOXf4YtXlZc0VXo= X-Received: by 2002:a2e:b162:0:b0:2d8:75df:6163 with SMTP id a2-20020a2eb162000000b002d875df6163mr2727438ljm.17.1712472750366; Sat, 06 Apr 2024 23:52:30 -0700 (PDT) MIME-Version: 1.0 References: <20240406182107.261472-1-jmaloy@redhat.com> <20240406182107.261472-3-jmaloy@redhat.com> In-Reply-To: From: Jason Xing Message-ID: Subject: Re: [net-next 2/2] tcp: correct handling of extreme menory squeeze To: Eric Dumazet Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MailFrom: kerneljasonxing@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: VISZGUNOR6B4OVSMXRLIURHTBJNXKJ77 X-Message-ID-Hash: VISZGUNOR6B4OVSMXRLIURHTBJNXKJ77 X-Mailman-Approved-At: Mon, 08 Apr 2024 11:51:32 +0200 CC: jmaloy@redhat.com, netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, passt-dev@passt.top, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com, eric.dumazet@gmail.com, menglong8.dong@gmail.com, dongmenglong.8@bytedance.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Date: Sun, 07 Apr 2024 06:52:31 X-Original-Date: Sun, 7 Apr 2024 14:51:53 +0800 On Sun, Apr 7, 2024 at 2:38=E2=80=AFAM Eric Dumazet w= rote: > > On Sat, Apr 6, 2024 at 8:21=E2=80=AFPM wrote: > > > > From: Jon Maloy > > > > Testing of the previous commit ("tcp: add support for SO_PEEK_OFF") > > in this series along with the pasta protocol splicer revealed a bug in > > the way tcp handles window advertising during extreme memory squeeze > > situations. > > > > The excerpt of the below logging session shows what is happeing: > > > > [5201<->54494]: =3D=3D=3D=3D Activating log @ tcp_select_window()/2= 68 =3D=3D=3D=3D > > [5201<->54494]: (inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM) -= -> TRUE > > [5201<->54494]: tcp_select_window(<-) tp->rcv_wup: 2812454294, tp->rc= v_wnd: 5812224, tp->rcv_nxt 2818016354, returning 0 > > [5201<->54494]: ADVERTISING WINDOW SIZE 0 > > [5201<->54494]: __tcp_transmit_skb(<-) tp->rcv_wup: 2812454294, tp->rcv= _wnd: 5812224, tp->rcv_nxt 2818016354 > > > > [5201<->54494]: tcp_recvmsg_locked(->) > > [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: (win_now: 250164, new_win: 262144 >=3D (2 * win_now= ): 500328))? --> time_to_ack: 0 > > [5201<->54494]: NOT calling tcp_send_ack() > > [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: tcp_recvmsg_locked(<-) returning 131072 bytes, window n= ow: 250164, qlen: 83 > > > > [...] > > I would prefer a packetdrill test, it is not clear what is happening... > > In particular, have you used SO_RCVBUF ? > > > > > [5201<->54494]: tcp_recvmsg_locked(->) > > [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: (win_now: 250164, new_win: 262144 >=3D (2 * win_now= ): 500328))? --> time_to_ack: 0 > > [5201<->54494]: NOT calling tcp_send_ack() > > [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: tcp_recvmsg_locked(<-) returning 131072 bytes, window n= ow: 250164, qlen: 1 > > > > [5201<->54494]: tcp_recvmsg_locked(->) > > [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: (win_now: 250164, new_win: 262144 >=3D (2 * win_now= ): 500328))? --> time_to_ack: 0 > > [5201<->54494]: NOT calling tcp_send_ack() > > [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: tcp_recvmsg_locked(<-) returning 57036 bytes, window no= w: 250164, qlen: 0 > > > > [5201<->54494]: tcp_recvmsg_locked(->) > > [5201<->54494]: __tcp_cleanup_rbuf(->) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: NOT calling tcp_send_ack() > > [5201<->54494]: __tcp_cleanup_rbuf(<-) tp->rcv_wup: 2812454294, tp->r= cv_wnd: 5812224, tp->rcv_nxt 2818016354 > > [5201<->54494]: tcp_recvmsg_locked(<-) returning -11 bytes, window now:= 250164, qlen: 0 > > > > We can see that although we are adverising a window size of zero, > > tp->rcv_wnd is not updated accordingly. This leads to a discrepancy > > between this side's and the peer's view of the current window size. > > - The peer thinks the window is zero, and stops sending. > > - This side ends up in a cycle where it repeatedly caclulates a new > > window size it finds too small to advertise. > > > > Hence no messages are received, and no acknowledges are sent, and > > the situation remains locked even after the last queued receive buffer > > has been consumed. > > > > We fix this by setting tp->rcv_wnd to 0 before we return from the > > function tcp_select_window() in this particular case. > > Further testing shows that the connection recovers neatly from the > > squeeze situation, and traffic can continue indefinitely. > > > > Reviewed-by: Stefano Brivio > > Signed-off-by: Jon Maloy > > --- > > net/ipv4/tcp_output.c | 14 +++++++++----- > > 1 file changed, 9 insertions(+), 5 deletions(-) > > > > diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c > > index 9282fafc0e61..57ead8f3c334 100644 > > --- a/net/ipv4/tcp_output.c > > +++ b/net/ipv4/tcp_output.c > > @@ -263,11 +263,15 @@ static u16 tcp_select_window(struct sock *sk) > > u32 cur_win, new_win; > > > > /* Make the window 0 if we failed to queue the data because we > > - * are out of memory. The window is temporary, so we don't stor= e > > - * it on the socket. > > + * are out of memory. The window needs to be stored in the sock= et > > + * for the connection to recover. > > */ > > - if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) > > - return 0; > > + if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) = { > > + new_win =3D 0; > > + tp->rcv_wnd =3D 0; > > + tp->rcv_wup =3D tp->rcv_nxt; > > + goto out; > > + } > > > > cur_win =3D tcp_receive_window(tp); > > new_win =3D __tcp_select_window(sk); > > @@ -301,7 +305,7 @@ static u16 tcp_select_window(struct sock *sk) > > > > /* RFC1323 scaling applied */ > > new_win >>=3D tp->rx_opt.rcv_wscale; > > - > > +out: > > /* If we advertise zero window, disable fast path. */ > > if (new_win =3D=3D 0) { > > tp->pred_flags =3D 0; > > -- > > 2.42.0 > > > > Any particular reason to not cc Menglong Dong ? > (I just did) He is not working at Tencent any more. Let me CC here one more time.