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=hiwYllmi; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 749535A0265 for ; Fri, 05 Jun 2026 18:27:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780676828; bh=PKKVZoHuF8l7yUIOLFMCnXlBGNkZyC+X5rGEac2XYhI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hiwYllmiV2xm5Z4Ltoi2eAJb9rlhmST89WlkbPLKrU2QOCKzN382EDw1OwXADAqdf VfwnRurJ3Xub8PgxIY1RfWE7j0wTc+52owiI7BG3FIKWv12+NXSm/yUbrcRP30Q9Li AYoeUfQjur31Mzk/d1+Da3zpVBsQn2oD2TBlAr9J2zxUUrarT0mJw4srho4sHkAvuo iBITIAi5K4sG9CIsGBSIEYqc2bIogrBKw+KT3+/qIxM9P1b2o9VGn1UNLE/ol6AF7/ RT5HAG4Ms5T68yt/7HHfAweGy/+h1S6tKtPtPDmK9Gj3ii//5mEaJoVB8pu+FBKyZW KJE8OmA9S1rhg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gX6K8539gz58bP; Sat, 06 Jun 2026 02:27:08 +1000 (AEST) Date: Sat, 6 Jun 2026 02:26:56 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v2 8/8] tcp_splice: Improve EOF and read stall exit conditions Message-ID: References: <20260528050213.679685-9-david@gibson.dropbear.id.au> <20260605003808.1596631-1-david@gibson.dropbear.id.au> <20260605125940.09263492@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="qV/cOZGBZz7frft1" Content-Disposition: inline In-Reply-To: <20260605125940.09263492@elisabeth> Message-ID-Hash: BFFEGHJ4QXT5PTJ4SUFZOSY7XKFAG3I2 X-Message-ID-Hash: BFFEGHJ4QXT5PTJ4SUFZOSY7XKFAG3I2 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: --qV/cOZGBZz7frft1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 05, 2026 at 12:59:42PM +0200, Stefano Brivio wrote: > On Fri, 5 Jun 2026 10:34:16 +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 makes > > sense: at EOF there's nothing left to do read-side and with nothing in = the > > pipe there's nothing to do write side either. > >=20 > > The same is true if the read side hit an EAGAIN and the pipe is empty: > > there's nothing we can do (for now) read side, and with an empty pipe > > nothing write side either. So, generalise the condition to exit on eit= her > > EOF or EAGAIN read side. > >=20 > > Furthermore, if the read side is at EOF or EAGAIN and there's already > > nothing in the pipe before the write-side splice(), then that write side > > splice() can't accomplish anything, so exit the loop early in that case > > avoiding a harmless but unnecessary write-splice(). > >=20 > > Signed-off-by: David Gibson > > --- > > tcp_splice.c | 20 +++++++++++++++----- > > 1 file changed, 15 insertions(+), 5 deletions(-) > >=20 > > Changes in v2: > > * Duplicate rather than move the test, it's valuable in both places. > > * Make comments and commit message clearer > >=20 > > diff --git a/tcp_splice.c b/tcp_splice.c > > index 565596d3..1e3c7749 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) > > @@ -531,9 +539,11 @@ static int tcp_splice_forward(struct ctx *c, > > =20 > > conn->pending[fromsidei] -=3D written; > > =20 > > - if (conn->events & FIN_RCVD(fromsidei) && > > - !conn->pending[fromsidei]) > > + if (!conn->pending[fromsidei] && readlen <=3D 0) { > > + /* Read side is EOF or EAGAIN, and we emptied the pipe. > > + * No more we can do for now, */ >=20 > Changed "now," to "now.", added empty comment line, applied. Oops, thanks. >=20 > > break; > > + } > > } > > =20 > > /* We need write-side wakeups if and only if we have data in the pipe= to >=20 > --=20 > Stefano >=20 --=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 --qV/cOZGBZz7frft1 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoi+MAACgkQzQJF27ox 2Gdcyg/+LnLijz91yUyIbGaOYgun7pOqvOm2O0MnsNsndM/5PNDT73SCvhqnpkIe WynAIVJH6NRPvKjm/DhrTEV8JWDALc2uIVNGbICQD9LIU5F3zt2CnD3hMQp4LYF9 H0bFG7h1bNJwI76FvITJEuPgMvCu2G/pEArXvlCLMfIyxcykwmex1VyA64H3/3Rh pIW6C1wTbufTaWTwofHyZSL9zlwSPQdpUSFeTvDYyHTTK4Sda4Dz1LY3I5OHS5B3 FLK1/eZeiuMfEI31EbmqLEw5TkMl9zMxrGf2Hf4qcLX2llLm9toXh1UuqQmIMJB6 C0iIuHCZUSFaZargA5F15mnLjO9ZySD0UuOIOBwgsUdhkG+UjUAHEgL6Gs6uZUpz l/KkhZJzv8JISpNSm9e3xTCNFnzAXIQtzvxrJavOpVJVnnTrnxA52v9vQ/OfW2Xk +FWSGPSY5btRgOifAkoR/b+IVjSvfs9N6dgokiEq9FFXyrFSjfCWDv+MDkrBBdm3 EbKPkVEfK6OLR1BGvMn9HL2faZJJemjlzimFgMmOR29ZF7CqVQPvWOulVMQe4Kbq lYd/9xgb3ET4RGv4s6mFcfVp4sOyejyeEu/Zv0Z92DiBzxfcOtxUtD1gewjml2K4 pymeeutWZNO4RLUWDOu7/lI8nEZB5mMKV6GMIQTAHSfEGVrBVmM= =LBlB -----END PGP SIGNATURE----- --qV/cOZGBZz7frft1--