throughput: TUN vnet-header GSO/GRO offload (lever 4b) #56
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
femboy/yip!56
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/throughput-tun-offload-4b"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Batches yipd's own TUN device I/O via a
virtio_net_hdr(GSO/GRO offload) on the default poll path, to cut the per-packet TUN-device cost that post-4a profiling identified as the largest remaining single-core cost. Lever 4b of the throughput campaign (4a send GSO ✓ #55 → 4b TUN offload → 4c MTU).Why (post-4a re-profile)
After 4a merged,
perfon the target boxes showed the send path was no longer dominant. The new top costs were on the TUN boundary: receivertun_chr_write_iter~20% (onewrite()per decrypted packet, each re-injected through the kernel net stack) and sender TUN read ~7%. Critically,recvmmsgwas 0.03% — so the originally-planned recv-GRO was dropped (the re-profile refuted it) in favor of this.How
The coalescing is entirely local to each box's yipd↔kernel-TUN boundary — no wire-format, FEC, AEAD, or replay change (each wire datagram stays one encrypted MTU packet).
crates/yip-io/src/tun_offload.rs(new): thevirtio_net_hdrcodec, IPv4/TCP parse + checksum helpers, an RX userspace-GRO coalescer (merges consecutive same-flow TCP segments into one GSO super-frame the kernel re-segments on write), a TX splitter (software-segments kernel-GRO'd reads back into MTU packets with per-segment seq/checksum), and partial-checksum completion forF_NEEDS_CSUMreads.crates/yip-device: opens the TUN withIFF_VNET_HDR+TUNSETOFFLOAD, gated on awant_vnet_hdrintent (poll driver only;uringand QUIC keep a plain TUN, so the fd framing always matches its consumer), with feature-fallback to plain onEINVAL.crates/yip-io/src/poll.rs,bin/yipd:drain_tunsplits on read,drain_udpcoalesces on write (flushing at end-of-burst), threaded throughrun_poll; yipd passeswant_vnet_hdrand the negotiated state.Non-coalescible traffic (UDP, pings, flow changes, out-of-order) passes through as singletons at zero cost; an unsupported kernel falls back to plain per-packet TUN I/O.
unsafestays confined toyip-io/yip-device;yipdremains#![forbid(unsafe_code)].Results
Spike (gate PASSED): on the target kernel, coalesced GSO TUN writes are 13.8× cheaper per segment than per-packet writes; the write succeeded, confirming the
virtio_net_hdrconstants.Real-hardware A/B (two 1-core AMD EPYC virtio VPSes, bulk TCP
-P32,perfon the receiver):tun_chr_write_iterThe mechanism works — coalescing engages under load and cuts the targeted TUN-write cost ~23%. Honest caveat: end-to-end throughput barely moves on that 24 ms-RTT / same-core-
iperfpath because it's RTT/window/contention-capped, not TUN-CPU-bound at ~50 Mbit/s. The full win lands on low-RTT / high-throughput single flows where TUN-write is the actual bottleneck and same-flow bursts are dense. It's a safe reduction of a real cost with upside on faster paths, costing nothing where it can't coalesce. Full analysis incrates/yip-bench/RESULTS.md.Correctness
cargo test --workspace0 failures;tun_offloadhas ~14 unit tests including a byte-exact split↔coalesce round-trip.ping/ping_under_loss(10%) /arq_recovers_bulk_lossPASS under both poll and uring drivers.A bug the process caught
The netns gate found 0% bulk delivery (while pings passed — subtle). Root cause: vnet-hdr TUN reads deliver large packets with incomplete L4 checksums (
F_NEEDS_CSUM— the kernel offloads them), whichsplit_gropassed through raw, so yipd shipped bad-checksum packets the far kernel silently dropped. The Task-0 spike had only tested the write-side checksum semantics. Fixed withcomplete_partial_csum+ a regression test.Design docs
docs/superpowers/specs/2026-07-12-throughput-tun-offload-design.mddocs/superpowers/plans/2026-07-12-throughput-tun-offload.md🤖 Generated with Claude Code
https://claude.ai/code/session_01RVP6NnbDMAg1iTsMMTfL86