Files
tailscale/kernel/linux
Brad Fitzpatrick b9a0f5d572 kernel/linux/src: batch crypt worker kicks, and send with outer UDP GSO
Profiling bulk TCP in the lean harness (tailscale.com's tstest/tswgbench)
showed kernel WireGuard serializing on two per-packet costs:

On receive, the single softirq CPU spent half its time in queue_work_on:
upstream kicks the next CPU's crypt worker for every packet, round robin,
which usually means waking it with an IPI (a VM exit in a VM). All the
workers drain the same ring, so instead stay on one CPU for 16 packets at
a time, and skip queue_work_on when the work is already pending (a read,
rather than queue_work_on's atomic test-and-set on a cache line the
worker writes). The same pending check applies to the per-peer transmit
work.

On send, the per-peer transmit worker sent each encrypted packet through
the UDP/IP stack and the device on its own, which with virtio is a device
kick, a VM exit, per packet. Packets from one GSO packet encrypt to the
same size (WireGuard pads to 16 bytes) except perhaps the last, so chain
each such run, without copying, as the frag_list of its first packet and
send it as one UDP GSO (SKB_GSO_UDP_L4) packet, with its checksum set up
as for a UDP_SEGMENT socket. The stack (or a capable device) segments it,
and the segments go to the device in one batch.

The coalesced packets are orphaned first: segmenting a frag_list of
packets still owned by the inner TCP socket uncharged the socket more
than it was charged (refcount underflow in tcp_wfree). wireguard-go has
the same effect, since the TUN device frees the inner packet once read.

Bulk TCP over tswg goes from 3.6 to 5.8 Gbps (wireguard-go: about 10.5).

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I649a7f1790c35d1af584d2c14f588195232d5ef4
2026-11-07 12:06:16 +00:00
..