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=G+XRt2dV; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 760875A061E for ; Thu, 28 May 2026 07:02:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779944535; bh=JOyjJAf0MQQq5V5xP0t8ccfgNTZeTPJAYBbRruMxXyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+XRt2dVyBHY5YOgrBBQW/5G1JuCbiOS+gyfe7LAnzlrpYS+AOR53unbC/FiRQEy5 fGuIYh9oPC7ag4ZGv5TtNABhrfpogDW2K5VUWFCJB87nEo8CbMA5a58wpSYoIsb18g tJurfEgSJq7sQxy4xV+mLA4f9L5eLpB27ow/7XO4R6bDngUegBiDUXzPPoYahdmr4X nfvLWtLd22B2cp54WhyYHmXTEvfbRc9QQvmfv7Qo4OKt7Hr+1ms2/xoXPajdUpyDFl MRTecJbw4LuKpHK6Yj4Z04wlGUvkMskzJv7zCp56dQaPeO19DqinKT1c9HDaAZGvhL XmAnY6INrOwnA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQvVb0mgxz4wM1; Thu, 28 May 2026 15:02:15 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 7/8] tcp_splice: Remove questionable "optimisation" of pending bytes tracking Date: Thu, 28 May 2026 15:02:12 +1000 Message-ID: <20260528050213.679685-8-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: QH4K6PNSOGXSYVRAGDFZU736TK74TCEK X-Message-ID-Hash: QH4K6PNSOGXSYVRAGDFZU736TK74TCEK 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: We have a special path that avoids updating conn->pending when the amounts read and written are equal. This has a conceptual complexity cost, in particular, it means that conn->pending[] is not accurate to its normal meaning for a section of the loop body. conn->pending[] shares a cacheline with conn->pipe[] and conn->s[], so it's almost certainly cache-hot. It's questionable that avoiding the update of pending even outweighs the extra conditional branch, let alone saves anything of significance. Remove it. This allows us to move the updates to conn->pending closer to the actual splice() calls, making it easier to reason about its value. It also lets us move the conn->pending updates so they can piggy back on existing tests rather than needing a conditional expression to avoid clobbering it when splice() returns -1 (EAGAIN). Signed-off-by: David Gibson --- tcp_splice.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 5f412584..565596d3 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -500,6 +500,8 @@ static int tcp_splice_forward(struct ctx *c, if (!readlen) { conn_event(conn, FIN_RCVD(fromsidei)); } else if (readlen > 0) { + conn->pending[fromsidei] += readlen; + if (readlen >= (long)c->tcp.pipe_size * 90 / 100) more = SPLICE_F_MORE; @@ -524,16 +526,11 @@ static int tcp_splice_forward(struct ctx *c, flow_trace(conn, "%zi from write-side call (passed %zi)", written, c->tcp.pipe_size); - /* Most common case: skip updating count of pending bytes */ - if (readlen > 0 && readlen == written) - continue; - - conn->pending[fromsidei] += readlen > 0 ? readlen : 0; - conn->pending[fromsidei] -= written > 0 ? written : 0; - if (written < 0) break; + conn->pending[fromsidei] -= written; + if (conn->events & FIN_RCVD(fromsidei) && !conn->pending[fromsidei]) break; -- 2.54.0