Skip to content

Feat/mrg rxbuf offload - #6

Merged
joaopeixoto13 merged 2 commits into
bao-project:mainfrom
kdamaski:feat/mrg-rxbuf-offload
Jun 23, 2026
Merged

Feat/mrg rxbuf offload#6
joaopeixoto13 merged 2 commits into
bao-project:mainfrom
kdamaski:feat/mrg-rxbuf-offload

Conversation

@kdamaski

Copy link
Copy Markdown
Contributor

Improve the virtio-net (non-vhost) data plane that serves the frontend NIC.

RX (download):

  • Advertise VIRTIO_NET_F_MRG_RXBUF and the guest offload features
    (GUEST_TSO4/6, GUEST_UFO, GUEST_CSUM) so a Linux frontend can receive
    large/GSO frames. Without mergeable buffers these were dropped and
    downloads stalled. Tap offload flags are derived from the features the
    driver actually negotiated, so a guest that declines offload still works
    via the single-buffer fallback.
  • Rewrite write_frame_to_guest to span one frame across several guest
    buffers and set num_buffers, in a single pass using fixed stack scratch
    instead of per-packet heap allocations. Draining the tap faster cut
    download retransmits and ~doubled throughput
    (iperf3: ~150 -> ~360 Mbit/s, retransmits ~1200 -> ~200).

TX (upload):

  • Stop cloning the guest memory map per packet, drain the queue with a
    single iterator per batch instead of one per packet, and signal the
    driver once per drain instead of per packet. Cuts per-packet CPU and
    syscall overhead on the transmit path.

@kdamaski
kdamaski requested a review from joaopeixoto13 as a code owner June 19, 2026 11:20
@joaopeixoto13

Copy link
Copy Markdown
Member

Hi @kdamaski

Thank you very much for your PR!

Overall, the approach is correct and the performance rationale is well-founded.

Before merging, please remove both Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> entries from the commit history (use interactive rebase on both commits). AI tool attribution should not be part of the project’s permanent commit history.

@joaopeixoto13

Copy link
Copy Markdown
Member

Also @kdamaski , please refactor the two commit messages to align with the previous commit message guidelines.

@kdamaski
kdamaski force-pushed the feat/mrg-rxbuf-offload branch from 2a98d7d to 179a42c Compare June 22, 2026 13:36
kdamaski added 2 commits June 22, 2026 16:49
…io-net

1) Downloads stalled completely (RX correctness). With large-frame offload on, the
frontend silently dropped big frames. Cause: the device didn't offer mergeable
RX buffers (MRG_RXBUF), which forced Linux into a fragile receive mode where it
couldn't validate the checksum of a big frame → drop.
Fix: Advertise MRG_RXBUF (+ the guest offload features) so big frames are delivered properly.
2) The downloads were lossy and slow (RX performance).
Cause: the RX code allocated memory (Vecs) for every single packet, which slowed the DM down.
Fix: rewrite the RX path to do its work in one pass with a fixed stack scratch
buffer — zero allocation per packet. Result: 151→363 Mbit/s, retransmits 1239→197.
3) rebuilds its ring iterator and clones the memory handle on every packet, and signals the guest per-packet instead of in batches)
Improve the virtio-net (non-vhost) data plane that serves the frontend NIC.

RX (download):
- Advertise VIRTIO_NET_F_MRG_RXBUF and the guest offload features
  (GUEST_TSO4/6, GUEST_UFO, GUEST_CSUM) so a Linux frontend can receive
  large/GSO frames. Without mergeable buffers these were dropped and
  downloads stalled. Tap offload flags are derived from the features the
  driver actually negotiated, so a guest that declines offload still works
  via the single-buffer fallback.
- Rewrite write_frame_to_guest to span one frame across several guest
  buffers and set num_buffers, in a single pass using fixed stack scratch
  instead of per-packet heap allocations. Draining the tap faster cut
  download retransmits and ~doubled throughput
  (iperf3: ~150 -> ~360 Mbit/s, retransmits ~1200 -> ~200).

TX (upload):
- Stop cloning the guest memory map per packet, drain the queue with a
  single iterator per batch instead of one per packet, and signal the
  driver once per drain instead of per packet. Cuts per-packet CPU and
  syscall overhead on the transmit path.
@kdamaski
kdamaski force-pushed the feat/mrg-rxbuf-offload branch from 179a42c to c14296a Compare June 22, 2026 13:54
@kdamaski

Copy link
Copy Markdown
Contributor Author

Done - Removed AI tool attribution mention in both commits and reworded the two commit messages to align with the previous commit message guidelines. Ready for re-review, thanks!

@joaopeixoto13
joaopeixoto13 merged commit fb860d8 into bao-project:main Jun 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants