From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=V0s9nD1U; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 056145A0265 for ; Thu, 04 Jun 2026 07:26:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780550804; bh=8QiT48ub0pva1+hcyYB4feBaIDH9nzVXFY1c731sIHI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=V0s9nD1UoGAdplo8n9JvbZJEtS258uLUqs8pVMJ9KaLisjBJ43OnTtRtcTS4rBROc 696p6AoDbdrfUNEyrTuwP0uZYuEKoQmltBPcmbtWcrPBnV6U/TpF/WqCPiRKXMa44i 8ncONecUVN8H6R6v8gPuNqyHxHB0FyWrq6Ye5GADpYCjzjEbkLrDfyVHIvdfgs3mEy 789W05RiiuUuK7Pp025dmcakeVbPjsu1FD8HSVUjC0yFBV0VGCzcIYX8oAR40N9wkk vRuv1upobVI7rbHYZ4moxeo7ANGx9FbJBiQaFLnTZNY+/3PjGx1fbJ6oRKrqtB8QdY nZcSyUNRnB4TA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gWCjc5KFwz4wV3; Thu, 04 Jun 2026 15:26:44 +1000 (AEST) Date: Thu, 4 Jun 2026 15:26:36 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 8/8] tcp_splice: Exit forwarding earlier when stalled read side Message-ID: References: <20260528050213.679685-1-david@gibson.dropbear.id.au> <20260528050213.679685-9-david@gibson.dropbear.id.au> <20260604064146.2dbb9e3f@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="j/El1cGhJymsPo1s" Content-Disposition: inline In-Reply-To: <20260604064146.2dbb9e3f@elisabeth> Message-ID-Hash: EBUMA2FLNLKOL6RCML3JPCJLCT76AMCP X-Message-ID-Hash: EBUMA2FLNLKOL6RCML3JPCJLCT76AMCP X-MailFrom: dgibson@gandalf.ozlabs.org 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: --j/El1cGhJymsPo1s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 04, 2026 at 06:41:47AM +0200, Stefano Brivio wrote: > On Thu, 28 May 2026 15:02:13 +1000 > David Gibson wrote: >=20 > > 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. > >=20 > > Furthermore, there's also nothing to be done write side if we've hit EA= GAIN > > on the read side and the pipe is empty, so exit early for that case as > > well. > >=20 > > Signed-off-by: David Gibson > > --- > > tcp_splice.c | 18 +++++++++++------- > > 1 file changed, 11 insertions(+), 7 deletions(-) > >=20 > > 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, > > =20 > > flow_trace(conn, "%zi from read-side call", readlen); > > =20 > > - if (!readlen) { > > - conn_event(conn, FIN_RCVD(fromsidei)); > > - } else if (readlen > 0) { > > + if (readlen <=3D 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] +=3D readlen; > > =20 > > if (readlen >=3D (long)c->tcp.pipe_size * 90 / 100) > > @@ -530,10 +538,6 @@ static int tcp_splice_forward(struct ctx *c, > > break; > > =20 > > conn->pending[fromsidei] -=3D written; > > - > > - if (conn->events & FIN_RCVD(fromsidei) && > > - !conn->pending[fromsidei]) > > - break; >=20 > 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. >=20 > The first part makes sense as an additional condition to exit the loop > and avoid an additional splice() call that would just return EAGAIN. >=20 > 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? Good point. If there was data in the pipe before the read-splice(), then we get EOF, then we empty the pipe with the write-splice() we know we're done and don't need to read-splice() again. I'm also pretty sure it's harmless, as long as repeated read-splice()s after EOF return either EOF again or EAGAIN, and I can't really see it doing anything else. Given that, and the fact you're already testing, I guess it makes more sense to do a fixup on top, rather than respinning? --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --j/El1cGhJymsPo1s Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmohDIAACgkQzQJF27ox 2GcrvQ/9GGdYqKQKrz6bzKSPUsOHdxi3vc6lMCGJa+q6g1Q1XxdqcrhLF1V6ed2a nxA6vAv83rr8Y4Ntqtog4l5+AtaKk2zW/TKJ9gZISDX/PW2LS73Q6RV4LTVUqKNR /13kpU05XjJu5Wy9mNlgOY3m2IoexxJsSZv3ZhYauDGOs3YN/AzTMzPBjGvDFjHI Fd1kJHwS1DA2RBiHVMP7S+/aq6NTCeVA+IRLyrS72Syt4AVEtQMmkKWKTCTXRVCR mlQUO/AHp3Cpo2gZPUhmQC2FqnlNhkaD4d6MHqOAWQAbRsgj4IkiuOUrtbC/o9Ys z/h3rtjjo1tUMZBTF40jWGYr6YtQpTJsxtABBLUWvXRaPyQiVpG09W6oeVt/2PXt wY2js9hz3S0S1X9azB87nadV67in49EZFHkePFumZt2EeYrtoQse+wV3zORLuqxh f/7cW3swt2Mkbv/8/dcrN9B3HsTD6efUzF51BW3UlzFD2rwqeqk7BmvPNwhamkEn EGyFMXIXMvtfeBoCJlxbUdYdm6wtnmYo70WtxMddwsIvgyFl3SaNM4MT0Vd9CHot MB2yVXMXP1zN1kQT7M9iXGY9Tu4kbPdD2Cr7lOXilZXDrnPO01n0lytkfoYL/2ku 4Y3mggpMd3I8mnlw8jc+c60DmHdf19PciJOCRn8PVCsUvIgIuL4= =Zkc+ -----END PGP SIGNATURE----- --j/El1cGhJymsPo1s--