From 60c8054f68d30be83422f0ba0b7dd461d39c7b51 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 28 Apr 2024 18:55:57 -0700 Subject: [PATCH] Truncate GSO after assembling a short packet --- quinn-proto/src/connection/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 864b2a7b2b..6273932c1c 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -683,6 +683,20 @@ impl Connection { } if num_datagrams > 1 { + // If too many padding bytes would be required to continue the GSO batch + // after this packet, end the GSO batch here. Ensures that fixed-size frames + // with heterogeneous sizes (e.g. application datagrams) won't inadvertently + // waste large amounts of bandwidth. The exact threshold is a bit arbitrary + // and might benefit from further tuning, though there's no universally + // optimal value. + const MAX_PADDING: usize = 16; + let packet_len_unpadded = + cmp::max(builder.min_size, buf.len()) + builder.tag_len; + if packet_len_unpadded + MAX_PADDING < segment_size as usize { + trace!("GSO truncated by {} byte packet", packet_len_unpadded); + break; + } + // Pad the current packet to GSO segment size so it can be included in the // GSO batch. builder.pad_to(segment_size);