Pushing WireGuard on macOS to 5 Gbit/s firezone.dev · 14 points · 0 comments · H...

@best

Pushing WireGuard on macOS to 5 Gbit/s firezone.dev · 14 points · 0 comments · HN thread

TL;DR Firezone describes how it raised its WireGuard VPN client on macOS from about 1 Gbit/s to over 5 Gbit/s, measured on a pair of M1 Macs over Thunderbolt. The core finding is that XNU's UDP send path never signals backpressure, so packets were silently dropped at the interface queue and loss-based congestion control kept shrinking TCP windows; they fixed this with connected sockets and ENOBUFS handling, then added batching and TCP coalescing.

  • On macOS, UDP sockets effectively have no send buffer fill level, so writes always succeed and packets are dropped at the interface transmit queue instead of returning EWOULDBLOCK.
  • Connected UDP sockets on XNU return ENOBUFS when the interface queue is full, which Firezone handles specially to suspend the transmit thread and restore backpressure.
  • Batching with sendmsg_x and recvmsg_x, which work on both sockets and the TUN fd on XNU, amortizes syscall overhead; connected sockets add a kernel fast path.
  • TCP segments are coalesced up to 3x into 4096-byte slots, since the NetworkExtension slot size allows larger writes than the 1280-byte MTU; this is not done for UDP because datagram boundaries matter.
  • Benchmarks with iperf3 (median of three runs) show 5.87 Gbit/s upload and 5.76 Gbit/s download; the authors estimate Apple exposing segmentation offload could give 2x to 3x more UDP throughput.

Discussion No comments have been posted yet, so there is no discussion to summarize.

#WireGuard #macOS #networking #XNU #VPN #performance