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=Q2xI7Fj5; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 56E565A0262 for ; Thu, 04 Jun 2026 12:21:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780568464; bh=HxOaEflQMHL4Xy82nLDhqp6A2l8qK3lVNvHEAq+H5Ao=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q2xI7Fj5q3jfhry9U0zOfR2D9rb99ymsWFM+cyokSmPZwtgDmASDEhxa4g7Q+9CVV I692S63ViViJRanT+rJJuvS7WzydSK0WNbuiA6MKvyQiJkycXNHfA4WTvK+32Swd6k o5I2oFPgHABWqcg3bnCasYPdFHbsZmIwSNS7iORExKGqwHhfON9c2TIIQZ0xusC3GC pSCwU0Z7yVAFoo8x/l2k98+vjsbHEyDuu/NgC+ILoVydVhVl873ni9BP8gPzYfR+Cn zclwG4lUCknBQ/qOCpQMXEDc4sCI6c/RkZftS5jrtY3Y9Y2tc7VkW/LPlkOaeB9WeH xZzpuEuzCIykQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gWLFD1Hbyz4wTx; Thu, 04 Jun 2026 20:21:04 +1000 (AEST) Date: Thu, 4 Jun 2026 17:08:00 +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> <20260604074456.06254db2@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mqgFRnZQU0m/Nl/w" Content-Disposition: inline In-Reply-To: <20260604074456.06254db2@elisabeth> Message-ID-Hash: 4P2VXBB42CH5XGB5IX6Y2SXWYHTHXAAD X-Message-ID-Hash: 4P2VXBB42CH5XGB5IX6Y2SXWYHTHXAAD 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: --mqgFRnZQU0m/Nl/w Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 04, 2026 at 07:44:56AM +0200, Stefano Brivio wrote: > On Thu, 4 Jun 2026 15:26:36 +1000 > David Gibson wrote: >=20 > > 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 do= esn'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 hi= t EAGAIN > > > > 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 > > >=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? =20 > >=20 > > 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. > >=20 > > 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. > >=20 > > 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 > But the commit message of this one would still be misleading because > we're not actually "moving" the condition, and the fix-up would just > add back these four lines (I guess?), so I think it would be more > practical if you could send a new version of 8/8 only (you can base it > on 7/8). Sure, will do. --=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 --mqgFRnZQU0m/Nl/w Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmohJEIACgkQzQJF27ox 2GdMEA/+MLUSGzexdMyDnEBN01rhnap9CNBnRiPaaG/EZyEA8TtE+4tf9EaGsENp 95EUp8x6gqXltMDCiOE22ZvRZt6NBwHaCygdvCSBlvNE7hH/zx56DKnRWBwPtxK0 sGri2ZcDESwNpK5jS6fIWWup89K5BWxdj3EVyCScqH8KoOlftJtdK4TgCCFEQTFg Kf3/6r2usRHZ7Fk5cdzRmmHzrJBp+BTW+L5EbuH3Ss+Y8vcxvv5RYCKMr/YwN6El wMse4hchN6zLlAsRuj6xL3VeWEpHVXA9lhmlNaiCz0mkG6avgpLYogLdz/VbPM5t XD8v7fFfjeGqheQjXZ/RjcpkP8wS+2Gmi0UlAhr++uz/R5e82DB0HUjpa/Oa60np vSATuRHgqVxslZHZeAHlRbXT1rOVnJv3V+vNARn68jiUUFGpNuWS4yfcooXqezeM 975mTZg41bwekZhEFJRLRCxNPxXsyiirK2P4bm73o+Hp5BFVNH7/krxp9d7ggtXk OyT1B4WxuqIivpPiCsAGF1ENkugGXqucrTe44jzLZrvVJZEc/3lkvJ7+2dwhLQpx dK6WKVZzJ6yrPno+56Sp6EOBsGaCbsxUjP3S8QZ0r6uyE2QWcl0f2Fr5V+7ZgLnb G03RwnMtbnF6Z6lV/UGres9UhJo3q0/4F094+5OwEvWciHgWgHM= =lLlT -----END PGP SIGNATURE----- --mqgFRnZQU0m/Nl/w--