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=202512 header.b=d/GD6+91; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 1E7F05A004E for ; Mon, 12 Jan 2026 05:03:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1768190582; bh=LOnwrnqsP2DuxTD7P44BhvTHAoUZc25OysNwnYQIA7Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d/GD6+91g9sV87LJzlDlNOj1tKCl7S20SCDPuBNBjjKHhmZJnVxFQcQeAxKhZQeS1 903O18oG77Hlu4060Fynby692b7+U01dotod+J6XNaz2WxsKBVhu1RtpK+z2ORZFej shCXl0VTUkf7u42Zi8PdVsTvhPalFEyfkdGRicIoKgjeYt8QLVWFWCJvpxFaO5+7cj gWvdqzuDAKjht8L/W7eB0NQF1YzjGybVKz67ex/4TlTXKd+Gd0d0Q+MItC21p+WPT5 vmzY5USwl1JUu29M2Hbu3bRBpxyUntlpbrz/xZ6+lEkRAAtR0TjPBZEccOy0nBk0A/ PBHfnYPnk46MQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dqJd26fDBz4w8x; Mon, 12 Jan 2026 15:03:02 +1100 (AEDT) Date: Mon, 12 Jan 2026 15:02:52 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] tcp: Fix rounding issue in check for approximating window to zero Message-ID: References: <20260109141443.3541507-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="qP/e80Ppc5wJ6u+c" Content-Disposition: inline In-Reply-To: <20260109141443.3541507-1-sbrivio@redhat.com> Message-ID-Hash: Q7XJANN53HXTJ3BPKEFCZNQGNU7DMZRL X-Message-ID-Hash: Q7XJANN53HXTJ3BPKEFCZNQGNU7DMZRL 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: --qP/e80Ppc5wJ6u+c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 09, 2026 at 03:14:43PM +0100, Stefano Brivio wrote: > In general, we approximate the advertised window to zero if we would > otherwise advertise less than a MSS worth, and the reasoning behind > that is explained in cf1925fb7b77 ("tcp: Don't limit window to > less-than-MSS values, use zero instead"). >=20 > Then, in commit b40f5cd8c8e1 ("tcp: Use less-than-MSS window on no > queued data, or no data sent recently"), I introduced some conditions > under which we won't do that, including a check on whether any data > was sent recently. >=20 > As an arbitrary but probably reasonable threshold, we consider data to > have recently been sent if that occurred less than ten times the > round-trip time (RTT) ago. >=20 > The time elapsed since the last data transmission is reported by the > kernel in milliseconds, in the tcpi_last_data_sent field of struct > tcp_info, and the RTT is reported in microseconds instead, in > tcpi_rtt. >=20 > To avoid the risk of overflow in a simple way, for the purpose of this > comparison, I converted tcpi_rtt to milliseconds first, but this means > that the check will always be false (and we'll never approximate the > window to zero) if the RTT is below one millisecond. >=20 > This, in turn, reintroduces nasty delay issues in transfers in > non-local connections which have however almost-local (low) latency. >=20 > Given that we want to use ten times the RTT as an arbitrary "long > enough" upper bound, round the RTT up while converting it to > milliseconds. >=20 > As an alternative, we could perform the comparison in microseconds, > but we would need a slightly more complicated implementation to > exclude overflows, and it's definitely not worth it given the nature > of this threshold. >=20 > Fixes: b40f5cd8c8e1 ("tcp: Use less-than-MSS window on no queued data, or= no data sent recently") > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tcp.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/tcp.c b/tcp.c > index e7fa85f..9b7f505 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1182,6 +1182,7 @@ int tcp_update_seqack_wnd(const struct ctx *c, stru= ct tcp_tap_conn *conn, > if ((conn->flags & LOCAL) || tcp_rtt_dst_low(conn)) { > new_wnd_to_tap =3D tinfo->tcpi_snd_wnd; > } else { > + unsigned rtt_ms_ceiling =3D DIV_ROUND_UP(tinfo->tcpi_rtt, 1000); > uint32_t sendq; > int limit; > =20 > @@ -1225,7 +1226,7 @@ int tcp_update_seqack_wnd(const struct ctx *c, stru= ct tcp_tap_conn *conn, > * with pending data in the outbound queue > */ > if (limit < MSS_GET(conn) && sendq && > - tinfo->tcpi_last_data_sent < tinfo->tcpi_rtt / 1000 * 10) > + tinfo->tcpi_last_data_sent < rtt_ms_ceiling * 10) > limit =3D 0; > =20 > new_wnd_to_tap =3D MIN((int)tinfo->tcpi_snd_wnd, limit); > --=20 > 2.43.0 >=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 --qP/e80Ppc5wJ6u+c Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlkcmsACgkQzQJF27ox 2Gd1SQ/+MRDZ9lL6PEmwo+1dOisjQPUd2Bef6pPyOdBVP0ojHH2qqlBpkdQj/BDe ZfZEBm+Ha8URBC9TKOvGOAE/71k82lTYabWgJxEHYtAwGw83R/r1oEcOWpN1fvGm RJnwHo6uBIOGz+a2mW0Yhv9Ea2lc8QL3hI+ZDqGm6DjxW4K3FaaOPAPqMPII8BQm cvQzCc9TsmeT+twfK9kFfgguVbhExyV8TEeOnI/+HlzLvFybj3t8zck1nVK7ZHKu 3m+xfpN/c7L2taCMWZD9AAds1JqZPRBPUHhYV8g7ysBNkpD8U1+tzScDt/nmjZnT ewHa+YI60p6yDgddC5wMk13qivw2+OYYz2r9yFKJwjIIPPI7n0K08sFRjQ+pmEKJ crHMe7a+khBUgm366AL5Wn7o1CAUEFn6GAkTvw+lZ510ICXWFgjfr4b8uDll5ht9 TWSnfrFsnh/bSwLRzd9WGqcNOzjMFZYdipAoBInEvEP7sNvmtEICmhFXi1tnIIVk c2ODwZa+nNoCjQRx5Jq4y1Pr4COJZBCCOid6FqtAr5+kry2cJZ825rNSGlBJijD/ JgILiby+pMQjz54alDh0Xlzn8vjqILA1coMymiHkm3vyAEUCqH91LzW0xys4HoiU WtnYZUE2uMFUTk7hJSvzjyHJlrP+TEiPj4HXRNBlLOw+yODNq3E= =Zx+w -----END PGP SIGNATURE----- --qP/e80Ppc5wJ6u+c--