Skip to content

consomme: autotune per-connection TCP ring buffers#3597

Open
benhillis wants to merge 1 commit into
microsoft:mainfrom
benhillis:user/benhillis/consomme-tcp-buffer-autotune
Open

consomme: autotune per-connection TCP ring buffers#3597
benhillis wants to merge 1 commit into
microsoft:mainfrom
benhillis:user/benhillis/consomme-tcp-buffer-autotune

Conversation

@benhillis

@benhillis benhillis commented May 29, 2026

Copy link
Copy Markdown
Member

Grows per-connection TCP rings in place from initial up to max (TcpBufferBounds) based on pressure, instead of a fixed size. The default now autotunes (16 KiB → 4 MiB), so idle/short connections start cheaper than the old fixed 256 KiB while bulk flows can ramp to a few MiB.

What changed

  • ConsommeParams exposes per-connection tcp_rx_buffer/tcp_tx_buffer as TcpBufferBounds { initial, max } so embedders can pick bounds for their workload.
  • Ring::resize: grow a power-of-two ring in place, preserving the [head, tail) view. rx grow is gated on the assembler + rx buffer being empty.
  • rx window scale derived from rx.max so the advertised window can grow without re-negotiating at SYN.
  • poll_socket_backend: double the tx ring when it fills the host read loop; double the rx ring + window when it hit ≥75% then drained (forcing an ACK so the peer picks up the larger window). Capped at max. New tx_buffer_grows/rx_buffer_grows counters.
  • DEFAULT_TCP_BUFFER_BOUNDS now 16 KiB → 4 MiB (was fixed 256 KiB).

Testing

cargo nextest run -p consomme passes (incl. new ring::resize tests); cargo clippy --release -p consomme --all-targets clean.

burette network benchmark (--backend consomme --nic vmbus, N=5, warm VM), old fixed 256 KiB vs autotune 64 KiB → 4 MiB:

Baseline Autotune Δ
TCP tx 5.40 9.94 Gbps +84%
TCP rx 3.86 5.21 Gbps +35%

A fixed-4 MiB control matches autotune (9.34 / 5.27), so the win is from raising the 256 KiB ceiling — autotune gets it while still starting small.

@benhillis benhillis requested a review from a team as a code owner May 29, 2026 20:47
Copilot AI review requested due to automatic review settings May 29, 2026 20:47
@github-actions github-actions Bot added the unsafe Related to unsafe code label May 29, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

@benhillis

Copy link
Copy Markdown
Member Author

Oops this was supposed to be an RFC / draft.

@benhillis benhillis marked this pull request as draft May 29, 2026 20:50
@benhillis benhillis changed the title consomme: autotune per-connection TCP ring buffers RFC: consomme: autotune per-connection TCP ring buffers May 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Linux-style TCP autotuning to the Consomme user-mode TCP stack by replacing fixed per-connection TX/RX ring sizes with bounded growth (initialmax) and resizing rings in-place based on observed buffer pressure, while keeping the default behavior equivalent to the prior fixed 256 KiB buffers.

Changes:

  • Introduces TcpBufferBounds { initial, max } on ConsommeParams and wires those bounds into TCP connection initialization.
  • Adds Ring::resize() to grow ring buffers while preserving the in-order [head, tail) byte range, plus unit tests for resize behavior.
  • Implements per-connection autotune in the socket backend poll loop and adds inspect counters for TX/RX buffer growth.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
vm/devices/net/net_consomme/consomme/src/tcp/ring.rs Adds Ring::resize() and new unit tests covering resize across wrap/no-wrap scenarios.
vm/devices/net/net_consomme/consomme/src/tcp/assembler.rs Makes Assembler::is_empty() available outside tests to gate safe RX ring growth.
vm/devices/net/net_consomme/consomme/src/tcp.rs Plumbs buffer bounds into connection creation, derives window scale from RX max, and grows TX/RX rings opportunistically with new inspect counters.
vm/devices/net/net_consomme/consomme/src/lib.rs Exposes TCP RX/TX buffer bounds on ConsommeParams with defaults preserving prior fixed sizing.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp/ring.rs
Comment thread vm/devices/net/net_consomme/consomme/src/tcp/ring.rs Outdated
@benhillis benhillis changed the title RFC: consomme: autotune per-connection TCP ring buffers consomme: autotune per-connection TCP ring buffers May 29, 2026
@benhillis benhillis marked this pull request as ready for review May 29, 2026 22:10
Copilot AI review requested due to automatic review settings May 29, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp/ring.rs
Comment thread vm/devices/net/net_consomme/consomme/src/tcp.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp.rs Outdated
Comment thread vm/devices/net/net_consomme/consomme/src/tcp.rs Outdated
Comment thread vm/devices/net/net_consomme/consomme/src/lib.rs
Comment thread vm/devices/net/net_consomme/consomme/src/tcp.rs
benhillis added a commit to benhillis/openvmm that referenced this pull request Jun 3, 2026
Address review feedback on microsoft#3597:
- Clarify that the rx ring can round above rx_buffer_max (power-of-two)
  and that TcpBufferBounds is capped by u16::MAX without window scaling.
- Add tests covering buffer-bounds normalization, that the derived rx
  window scale reaches max, and that the tx ring autotunes (grows and
  caps at max) under host-side backpressure.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis requested a review from Copilot June 3, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp.rs Outdated
Comment thread vm/devices/net/net_consomme/consomme/src/lib.rs
benhillis added a commit to benhillis/openvmm that referenced this pull request Jun 3, 2026
Address review feedback on microsoft#3597: note the new per-connection ring
buffer autotune defaults (16 KiB initial, 4 MiB max) and how embedders
override them via tcp_rx_buffer/tcp_tx_buffer on ConsommeParams.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Guide label Jun 3, 2026
Copilot AI review requested due to automatic review settings June 3, 2026 16:47
@github-actions github-actions Bot removed the unsafe Related to unsafe code label Jun 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp/tests.rs Outdated
Comment thread vm/devices/net/net_consomme/consomme/src/tcp/tests.rs Outdated
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread vm/devices/net/net_consomme/consomme/src/tcp/tests.rs
Comment thread vm/devices/net/net_consomme/consomme/src/tcp/tests.rs
benhillis added a commit to benhillis/openvmm that referenced this pull request Jun 6, 2026
Address review feedback on microsoft#3597:
- Clarify that the rx ring can round above rx_buffer_max (power-of-two)
  and that TcpBufferBounds is capped by u16::MAX without window scaling.
- Add tests covering buffer-bounds normalization, that the derived rx
  window scale reaches max, and that the tx ring autotunes (grows and
  caps at max) under host-side backpressure.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
benhillis added a commit to benhillis/openvmm that referenced this pull request Jun 6, 2026
Address review feedback on microsoft#3597: note the new per-connection ring
buffer autotune defaults (16 KiB initial, 4 MiB max) and how embedders
override them via tcp_rx_buffer/tcp_tx_buffer on ConsommeParams.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 6, 2026 00:02
@benhillis benhillis force-pushed the user/benhillis/consomme-tcp-buffer-autotune branch from 33f6ea6 to 9ec22d5 Compare June 6, 2026 00:02
Grow per-connection TCP rings in place from `initial` up to `max`
(`TcpBufferBounds`) based on observed pressure, instead of using a fixed
size. The default now autotunes (16 KiB -> 4 MiB), so idle/short
connections start cheaper than the old fixed 256 KiB while bulk flows can
ramp to a few MiB.

What changed:
- `ConsommeParams` exposes per-connection `tcp_rx_buffer`/`tcp_tx_buffer`
  as `TcpBufferBounds { initial, max }` so embedders can pick bounds for
  their workload. `DEFAULT_TCP_BUFFER_BOUNDS` is now 16 KiB -> 4 MiB
  (was a fixed 256 KiB).
- `Ring::resize`: grow a power-of-two ring in place, preserving the
  `[head, tail)` view without staging through a temporary buffer.
  Grow-only (same-capacity resizes are a no-op). rx grow is gated on the
  assembler + rx buffer being empty.
- rx window scale is derived from `rx.max` so the advertised window can
  grow without re-negotiating at SYN. Window/ring sizing accounts for the
  power-of-two rounding and the `u16::MAX` cap when window scaling is
  unavailable.
- `poll_socket_backend`: double the tx ring when it fills the host read
  loop (re-reading the host socket into the freshly grown ring within the
  same poll), and double the rx ring + window when it hit >=75% then
  drained (forcing an ACK so the peer picks up the larger window). Both
  are capped at `max`. New `tx_buffer_grows`/`rx_buffer_grows` counters.

Tests:
- New `ring::resize` unit tests and end-to-end autotune tests covering
  tx/rx growth, capping at `max`, and the derived rx window scale.
- Test host-write helpers poll consomme concurrently so large writes
  can't deadlock when consomme is the only socket reader.

Docs:
- The Guide's consomme backend page documents the new default bounds,
  autotune behavior, and tuning knobs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the user/benhillis/consomme-tcp-buffer-autotune branch from 9ec22d5 to 200c4bc Compare June 6, 2026 00:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants