Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport gso mitigations #1638

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quinn-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quinn-proto"
version = "0.10.1"
version = "0.10.2"
edition = "2021"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
Expand Down
19 changes: 19 additions & 0 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct TransportConfig {
pub(crate) datagram_send_buffer_size: usize,

pub(crate) congestion_controller_factory: Box<dyn congestion::ControllerFactory + Send + Sync>,

pub(crate) enable_segmentation_offload: bool,
}

impl TransportConfig {
Expand Down Expand Up @@ -291,6 +293,21 @@ impl TransportConfig {
self.congestion_controller_factory = Box::new(factory);
self
}

/// Whether to use "Generic Segmentation Offload" to accelerate transmits, when supported by the
/// environment
///
/// Defaults to `true`.
///
/// GSO dramatically reduces CPU consumption when sending large numbers of packets with the same
/// headers, such as when transmitting bulk data on a connection. However, it is not supported
/// by all network interface drivers or packet inspection tools. `quinn-udp` will attempt to
/// disable GSO automatically when unavailable, but this can lead to spurious packet loss at
/// startup, temporarily degrading performance.
pub fn enable_segmentation_offload(&mut self, enabled: bool) -> &mut Self {
self.enable_segmentation_offload = enabled;
self
}
}

impl Default for TransportConfig {
Expand Down Expand Up @@ -325,6 +342,8 @@ impl Default for TransportConfig {
datagram_send_buffer_size: 1024 * 1024,

congestion_controller_factory: Box::new(Arc::new(congestion::CubicConfig::default())),

enable_segmentation_offload: true,
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ impl Connection {
#[must_use]
pub fn poll_transmit(&mut self, now: Instant, max_datagrams: usize) -> Option<Transmit> {
assert!(max_datagrams != 0);
let max_datagrams = max_datagrams.min(MAX_TRANSMIT_SEGMENTS);
let max_datagrams = match self.config.enable_segmentation_offload {
false => 1,
true => max_datagrams.min(MAX_TRANSMIT_SEGMENTS),
};

let mut num_datagrams = 0;

Expand Down
2 changes: 1 addition & 1 deletion quinn-udp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quinn-udp"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
Expand Down
10 changes: 5 additions & 5 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ fn send(
}
io::ErrorKind::WouldBlock => return Err(e),
_ => {
// Some network adapters do not support GSO. Unfortunately, Linux offers no easy way
// for us to detect this short of an I/O error when we try to actually send
// datagrams using it.
// Some network adapters and drivers do not support GSO. Unfortunately, Linux
// offers no easy way for us to detect this short of an EIO or sometimes EINVAL
// when we try to actually send datagrams using it.
#[cfg(target_os = "linux")]
if e.raw_os_error() == Some(libc::EIO) {
if let Some(libc::EIO) | Some(libc::EINVAL) = e.raw_os_error() {
// Prevent new transmits from being scheduled using GSO. Existing GSO transmits
// may already be in the pipeline, so we need to tolerate additional failures.
if state.max_gso_segments() > 1 {
tracing::error!("got EIO, halting segmentation offload");
tracing::error!("got transmit error, halting segmentation offload");
state
.max_gso_segments
.store(1, std::sync::atomic::Ordering::Relaxed);
Expand Down