]> git.ipfire.org Git - thirdparty/wireguard-go.git/commit
device: change Peer.endpoint locking to reduce contention
authorJordan Whited <jordan@tailscale.com>
Tue, 21 Nov 2023 00:49:06 +0000 (16:49 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 11 Dec 2023 15:34:09 +0000 (16:34 +0100)
commit4ffa9c20327b9471c3eeb142347f679b69f84648
tree23055247e732f1bcfe4fa047cdd1577cd68dddc9
parentd0bc03c707974a84a672716c718f99fab49e7eb8
device: change Peer.endpoint locking to reduce contention

Access to Peer.endpoint was previously synchronized by Peer.RWMutex.
This has now moved to Peer.endpoint.Mutex. Peer.SendBuffers() is now the
sole caller of Endpoint.ClearSrc(), which is signaled via a new bool,
Peer.endpoint.clearSrcOnTx. Previous Callers of Endpoint.ClearSrc() now
set this bool, primarily via peer.markEndpointSrcForClearing().
Peer.SetEndpointFromPacket() clears Peer.endpoint.clearSrcOnTx when an
updated conn.Endpoint is stored. This maintains the same event order as
before, i.e. a conn.Endpoint received after peer.endpoint.clearSrcOnTx
is set, but before the next Peer.SendBuffers() call results in the
latest conn.Endpoint source being used for the next packet transmission.

These changes result in throughput improvements for single flow,
parallel (-P n) flow, and bidirectional (--bidir) flow iperf3 TCP/UDP
tests as measured on both Linux and Windows. Latency under load improves
especially for high throughput Linux scenarios. These improvements are
likely realized on all platforms to some degree, as the changes are not
platform-specific.

Co-authored-by: James Tucker <james@tailscale.com>
Signed-off-by: James Tucker <james@tailscale.com>
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/device.go
device/mobilequirks.go
device/peer.go
device/sticky_linux.go
device/timers.go
device/uapi.go