From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by passt.top (Postfix) with ESMTPS id 2B8B85A0272 for ; Mon, 8 Apr 2024 12:03:48 +0200 (CEST) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-56e2e851794so14670a12.0 for ; Mon, 08 Apr 2024 03:03:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712570627; x=1713175427; 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=zUeK8tUltCiiNIWWzwpRkvxOb1EySFIlgtsCvzHp/MA=; b=ZKN7V16VKSVo+BqAobHHYuyOZX7Y29OJaqnAbHKm0EWCpKoX/LsL4fvDrMYFEhoP2f ccBFnuV6UrwypSkh174nwXOalMqADhivlzYPxb8uDLWyvHxiNIx1W2RT9/5JaaSiXEjL AhJ/s1jyWmouDRO9UOIOmpfGEk60Aj4pvHnSGyrea/1InImzfFMF+327rtIx0z+fWshN R7jSu0vk9WLOM1oDMAUKKuyFFjpfvrtRGb5YUa2dtEEl+bZiIKxbaaiNPfNqW62/jrDv uI6+EtEz13Hu0EJ6LYYwGlYHmRyxQQQ6emLd96nESi/5EX2QVsARxSeDSIujdLN8FqKi bxsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712570627; x=1713175427; 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=zUeK8tUltCiiNIWWzwpRkvxOb1EySFIlgtsCvzHp/MA=; b=XwY2FisQLARPq0PVSUL1YHMyGWFYhcYV+oTIO4Lvy3V2FdEUl1/TkVjwViIs6vfSwT z9g/U787uRJTHgrT4zjbbxDh6qLC6Gubpqg9jNv5/0I1YD8RDGtUpmscdljfmmamXkkl W/MCChsOHULdiGiPJH9YHymugd4PqqY3DeWdxqBUgueV9RJ/pCzK1VUVPyEHtUKvACuO kvI/CpccOe1DLq0qdjkNR5mokZSxb1CSstwIP3JOCZtFPBRT5Rr5gBB3yIAaaUySrQ2T EuZyfcbJlYbkeG+5Vepg+dAk2gAKAOrOdmkcK3SY714O8wvBAF9pt756ml2rZQkaQi0C CTnA== X-Forwarded-Encrypted: i=1; AJvYcCVRIVMoMur9PC0LC26/+gQ2bj2xfZAnFSM0hfXt3r0wdWgh+ze46Lq0SfO4hOyRs3zBMXflvEaNoc2caYtsXwmO7BY2 X-Gm-Message-State: AOJu0YzwHpxde/XbR85vbckwkAnyRP5LYlgG9C0KFLr39iAhQ/hb6SWS a9iepd9hnFsFQLaSyTpFvpRzVeJo2Hw7uU/7pS7lQ393Vb9ayPDQtFqEi6HzWYEplM6Gu6f61YN ljqtFsfy/MKpSR3ENrUJZboB91RKVvrtBh6zl X-Google-Smtp-Source: AGHT+IHo4xqDV2ksYOcRZu/IBTlWIBBQ4JZAobA8bJwE8WOGynuS/UjeVbuj/3gPonZ9dTtC8OkJ9NXvnh5DfV9DROQ= X-Received: by 2002:a05:6402:2554:b0:56e:68ac:3d50 with SMTP id l20-20020a056402255400b0056e68ac3d50mr58769edb.4.1712570627209; Mon, 08 Apr 2024 03:03:47 -0700 (PDT) MIME-Version: 1.0 References: <20240406182107.261472-1-jmaloy@redhat.com> <20240406182107.261472-3-jmaloy@redhat.com> In-Reply-To: From: Eric Dumazet Message-ID: Subject: Re: [net-next 2/2] tcp: correct handling of extreme menory squeeze To: jmaloy@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-MailFrom: edumazet@google.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: ABCNQSO53V7K2PVWFJNJNLUXFHK6ZPYR X-Message-ID-Hash: ABCNQSO53V7K2PVWFJNJNLUXFHK6ZPYR X-Mailman-Approved-At: Fri, 12 Apr 2024 07:37:46 +0200 CC: 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 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: Mon, 08 Apr 2024 10:03:48 X-Original-Date: Mon, 8 Apr 2024 12:03:35 +0200 On Sat, Apr 6, 2024 at 8:37=E2=80=AFPM 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 I do not think this patch is good. If we reach zero window, it is a sign something is wrong. TCP has heuristics to slow down the sender if the receiver does not drain the receive queue fast enough. MSG_PEEK is an obvious reason, and SO_RCVLOWAT too. I suggest you take a look at tcp_set_rcvlowat(), see what is needed for SO_PEEK_OFF (ab)use ? In short, when SO_PEEK_OFF is in action : - TCP needs to not delay ACK when receive queue starts to fill - TCP needs to make sure sk_rcvbuf and tp->window_clamp grow (if autotuning is enabled)