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=Qw2WXmKD; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7B64F5A0275 for ; Thu, 28 May 2026 07:02:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779944535; bh=AIMQiYV1GXAII6g5hbDErh21gBNYf9HkslOUXMNST8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qw2WXmKDqKfIZV05wXTeCMYXj8e5Zvnmjkzok5MXU6jWaiZld8TkXMwuwFhbXVt3T 4MSHqF6nGPO6WtJ3TnR9LxncasgQrKr3+hhretsCahw8zHGPawd5gZ4PvyuxP56EvI Kn4CFsgH2r9h0k1u4/ZuQ+PyPoI4j7Ph0QDlytUenvDSNxl3L9mmBysGou4J7qovz/ 0Xvko9IC14lqthg7emIQL/iWcD9rb4rXhK+INlVHEOaXXQaui+cAp7qmjr1DMn5LdU mNxQ3REyAvM4fpJ8DTtu1NNBzTpxLvbUcpQ7vgfF4VRkLzEXbhp4WPaOr6dyIPHWLX ParpFKm2XxqhA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQvVb0rpkz4wM3; Thu, 28 May 2026 15:02:15 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 8/8] tcp_splice: Exit forwarding earlier when stalled read side Date: Thu, 28 May 2026 15:02:13 +1000 Message-ID: <20260528050213.679685-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528050213.679685-1-david@gibson.dropbear.id.au> References: <20260528050213.679685-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UMWRLQ7YLG6Q7YKIYDZIZ46NZ7FQEGR4 X-Message-ID-Hash: UMWRLQ7YLG6Q7YKIYDZIZ46NZ7FQEGR4 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: David Gibson 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: 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; } /* We need write-side wakeups if and only if we have data in the pipe to -- 2.54.0