From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aUWb/u/5; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id DD9E25A0271 for ; Thu, 04 Jun 2026 06:41:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780548111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rppNIQOm8pOqr0xwpqjvd0pSY+uKM7M5qlOx1cABm6M=; b=aUWb/u/5fSVTRmc4XPcUaKQt1kwQQtFgrcxV5vRHWRpbIw9WgvTdlYceAn8+G/k1Ce+ATU Vw+KkvMTBXuDDYNGB99Z3FlmW/0NmncTxLSpuitW9I8E9r6Brsyr749WYNuIHbumceRm+q xB1SjqEqXVDgoUPDYdlOresScuOzcc8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-V1Qca3bKPXacyj-dkBZzAQ-1; Thu, 04 Jun 2026 00:41:50 -0400 X-MC-Unique: V1Qca3bKPXacyj-dkBZzAQ-1 X-Mimecast-MFC-AGG-ID: V1Qca3bKPXacyj-dkBZzAQ_1780548109 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490aadb1386so6603515e9.0 for ; Wed, 03 Jun 2026 21:41:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780548109; x=1781152909; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rppNIQOm8pOqr0xwpqjvd0pSY+uKM7M5qlOx1cABm6M=; b=jned02JSohbE8hZIBGYu+wr7DRECyrIxJLF85f4JIHtjHWOOQ7o6Wzt3G8uhtJCk54 xXFQnk8ZoptXOiQZBMBsc/nXvv0GXgCmoHzw1S6VgeM5BtVzoy1OVRVoVAjvE9GS2xID xfNgWvFnyWue6xYiGX9gHmoR4ErJ6glrw3wgs2TgA+OoU9Tn9mERFDBSJy1FHuDRZKd1 NXb4N+cTALh8GQxVM+ikMuI3+J+bRUomfpTF8qn+3XzB5oGRaqaCwzD9NDfEkRunae9H LCqSjoEgLIKnEKQY/hVTdJZYJt6hwFhIb2eg2GsNnkJJsfp+HhVqHpMh1XdWz83x28j1 wyQQ== X-Gm-Message-State: AOJu0YxI7uLUEqoWrs6D38lNAf766v0TDCaAWw7YUIEc9Fpvku1c/GLO UHBXRe84BKcilJy6r6IyALjUbLYwp4lvhK3nNCFM9Z4+K0EFvI8f8vRu1XLpEy51FIlanFNV9id JZ0uIB7bAfV0AlHzGehORdE8gC1NXH0kq+dcrYlmJla43KOi4FP2/IQaOeJHyQg== X-Gm-Gg: Acq92OErQS1cfTbG5m4GKFPyJ/tbHtUCw/vrGvXBZW7qr2YQMZ0OJsf7lLJh8b3h/qY 7MggClYDJF2RX7EVDwusTzQysPjZFI1jAnXLQUYZweWzmA8sOL/7Jhkw5F6fhSOgxzpGVnUgly5 afvOY7lh7mjXI2U/IBjkbruoGXlu1VWUZrb2Ejnc8KTt8SqkJY2uURTM9jH1alxSpz4WNV9dvYH xThr2XspIC1u6dDXxVMr2u4+jscgQt6EwgKd9aQgTBUuJ7UhPkFFuTMW23f8zqG72WC3uGBdPgy C+t7bWOAKJS5Hlkf6DiKMzvgfYP5blUoM8IxgG79NIs6i7NBjhb8JpQKJouBvZ6+5auIuUJGRz7 n7jtBYrqIZb7gthmyfNx9ZUYksEBw2hDPRX2HHrx/kKs= X-Received: by 2002:a05:600c:83c6:b0:48a:53cb:8604 with SMTP id 5b1f17b1804b1-490bc5001e0mr31091315e9.14.1780548109108; Wed, 03 Jun 2026 21:41:49 -0700 (PDT) X-Received: by 2002:a05:600c:83c6:b0:48a:53cb:8604 with SMTP id 5b1f17b1804b1-490bc5001e0mr31091095e9.14.1780548108636; Wed, 03 Jun 2026 21:41:48 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3c183asm42833795e9.6.2026.06.03.21.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 21:41:47 -0700 (PDT) From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 8/8] tcp_splice: Exit forwarding earlier when stalled read side Message-ID: <20260604064146.2dbb9e3f@elisabeth> In-Reply-To: <20260528050213.679685-9-david@gibson.dropbear.id.au> References: <20260528050213.679685-1-david@gibson.dropbear.id.au> <20260528050213.679685-9-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Thu, 04 Jun 2026 06:41:47 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 47pHcJcp7zZkUUUQ3bYiT4awHpcpQwL-GAgtphPWxZo_1780548109 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: MOSWJZVVI6VRIVTSY6FEJUH57IZRXNNO X-Message-ID-Hash: MOSWJZVVI6VRIVTSY6FEJUH57IZRXNNO X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top 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: On Thu, 28 May 2026 15:02:13 +1000 David Gibson wrote: > At the end of our loop we have a conditional 'break' that exits if we're > at EOF on the read side and have nothing left in the pipe. This doesn't > depend on anything write-side, so we can move it earlier, avoiding an > unnecessary write side splice in this case. > > Furthermore, there's also nothing to be done write side if we've hit EAGAIN > on the read side and the pipe is empty, so exit early for that case as > well. > > Signed-off-by: David Gibson > --- > tcp_splice.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/tcp_splice.c b/tcp_splice.c > index 565596d3..623ca926 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -497,9 +497,17 @@ static int tcp_splice_forward(struct ctx *c, > > flow_trace(conn, "%zi from read-side call", readlen); > > - if (!readlen) { > - conn_event(conn, FIN_RCVD(fromsidei)); > - } else if (readlen > 0) { > + if (readlen <= 0) { > + if (!readlen) /* EOF */ > + conn_event(conn, FIN_RCVD(fromsidei)); > + > + /* We're either blocked or at EOF on the read side, and > + * there's nothing in the pipe so there's nothing to do > + * write side either. > + */ > + if (!conn->pending[fromsidei]) > + break; > + } else { > conn->pending[fromsidei] += readlen; > > if (readlen >= (long)c->tcp.pipe_size * 90 / 100) > @@ -530,10 +538,6 @@ static int tcp_splice_forward(struct ctx *c, > break; > > conn->pending[fromsidei] -= written; > - > - if (conn->events & FIN_RCVD(fromsidei) && > - !conn->pending[fromsidei]) > - break; The rest of the series looks good to me and I'm running tests now before pushing, but I can't convince myself of the correctness of this change. The first part makes sense as an additional condition to exit the loop and avoid an additional splice() call that would just return EAGAIN. But this one is a different condition because it happens to check conn->pending[fromsidei] right after we subtracted 'written' from it, and we know we have no input data anymore, so it avoids a useless (although I think harmless) read-side splice() call in the next iteration of the loop, doesn't it? > } > > /* We need write-side wakeups if and only if we have data in the pipe to -- Stefano