subnetbench.sh runs tailscale.com's TestLeanSubnetRouter on the EC2
instances for each router CPU count given. ec2.sh now turns off source
and destination checks on its instances, so that one can forward as a
subnet router does, and installs nftables (for the router's masquerade).
DESIGN.md records the results: with 4 clients, tswg as the subnet
router forwards 2.1x (4 CPUs) to 3.2x (8 CPUs) what wireguard-go does,
which uses about 3 CPUs however many it has, at the least CPU per byte
of any tunnel, and reaches the 25 Gbps link at 16 CPUs. Zero-copy
receive was tried there and was 7% worse, so isn't in.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I6b1da8bb8eaa17f9b20cbe36896426411b8b905f
The QEMU lab runs on a host that's itself a VM, which distorted latency
in particular. ec2.sh manages benchmark instances in the sandbox AWS
account (us-west-2; the org's SCP allows only some regions and requires
IMDSv2): a key pair, a security group open to this host and between its
members, a cluster placement group, and Ubuntu 24.04 instances with IPv6
that install the build tools for their own kernel. Everything is named
bradfitz-tswg... and tagged owner=claude-tswg. It writes the hosts file
that tailscale.com's lean harness takes in remote mode.
To keep costs down, ec2-idle-stop.sh, run every 5 minutes from a systemd
user timer on the always-on dev host, stops the instances once nothing
has touched ~/.cache/tslinux/ec2/last-used for 30 minutes. ec2.sh and the
harness touch it while in use, and "ec2.sh start" brings stopped
instances back.
First EC2 results (c7i.xlarge pair) are in DESIGN.md: throughput is
capped by EC2 at about 7.25 Gbps for both tswg and wireguard-go, with
tswg's receiver using up to 17% less CPU per byte; 1.6x the small
packets; a quarter of the RTT under load at p50; twice the idle RTT.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ibe770a30bea31cb79ac514aeb545f468576b5f05
DESIGN.md's Performance section now describes what tswg changes in the
data path and why, the results against wireguard-go (parity to 1.05x on
bulk TCP at 6-10% less CPU per byte, much better small-packet delivery,
worse idle and p99-under-load latency in VMs) and the tools for this
work. The TODO list gets the open performance items.
leancompare.sh runs the lean harness's interleaved A/B comparison for
RTT and TCP with 1 and 4 streams.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Icf8c7ca8bb3711a8172284382af9ce8c3e25ff3d
gokrazy-debug-kernel.sh builds the gokrazy kernel package's kernel again
with KASAN, lockdep, DEBUG_VM and DEBUG_NET, for tailscale.com's lean
harness to boot (TSWG_DEBUG_KERNEL=1). build-for-gokrazy.sh builds
against it when given TSWG_KDIR, since those options change kernel data
structures.
Its first find: our slab caches had upstream WireGuard's names (via
KMEM_CACHE), which clash with wireguard.ko or a built-in WireGuard, as
gokrazy has, and make slab_common warn at load. Give them tswg_ names.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I2e7d5448bcf8b2fb68810486f7e5d4bf2af4558d
leanbench.sh runs tailscale.com's new lean data plane benchmark, which
compares wireguard-go, tswg, the kernel's WireGuard and no tunnel between
two QEMU VMs on a host bridge with vhost-net, without natlab, over IPv4
and IPv6. With -smoke it runs the quick correctness test instead.
The results overturn the natlab ones, which natlab's userspace network
had capped: kernel WireGuard (and tswg, identically) gets about a third
of wireguard-go's bulk TCP throughput, at 1.5x to 2.5x the CPU per byte,
without being CPU-bound. So outer UDP GSO/GRO and finding where the
kernel serializes are now the critical performance work.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I2a24de8d82370fc8dfb6a9af0971da20831ea307
bench.sh runs tailscale.com's TestTSWGBenchmark, which compares
tailscaled in kernel mode against tailscaled in TUN mode (wireguard-go)
on the same pair of natlab gokrazy VMs, and saves the results as JSON.
Record the first results: bulk TCP throughput and CPU per byte are about
the same (natlab caps throughput, and the kernel lacks outer UDP
GSO/GRO), while the kernel receives about 1.7x the small packets per
second at about 30% less CPU per packet and roughly halves latency under
load. Also record the plan for a lean benchmark harness without natlab,
whose userspace switch is expensive, and a flake seen when both peers
restart at once.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I69e696817f98e685576a30d766c42740d4d04810
The natlab gokrazy image runs a recent upstream kernel (7.2.8 today) that
gokrazy rebuilds and tailscale.com bumps regularly, which makes it a
better primary test target than a distro kernel: it keeps us honest
against new kernel APIs, and gokrazy has no userspace tools, as in the
end state where tailscaled drives the kernel entirely.
gokrazy kernels are kernel.org releases plus the patches in
_build/series, built with an embedded config and without MODVERSIONS or
module signing. gokrazy-kdir.sh downloads the release, applies the
patches, installs the config pulled out of vmlinuz with the kernel's
extract-ikconfig (vendored), and runs modules_prepare, caching the
result by release and config hash. It takes about 20 seconds the first
time. The only config differences after olddefconfig with the host's gcc
13 (gokrazy uses Debian 12's gcc 12) are toolchain capability bits.
Factor the generic part of build-for-ubuntu.sh into build.sh, which now
copies only sources (not objects from an in-place build in src/), and
sets KBUILD_MODPOST_WARN=1 for trees without a Module.symvers. Add
build-for-gokrazy.sh.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Id28d9c013bdfaa7cec28aeff846f7f6087e25518
build-for-ubuntu.sh builds tswg.ko for a given Ubuntu kernel release in a
private copy of src/, so test builds for different guest kernels don't
share object files with each other or with a developer's in-place build.
The Makefile's SRC is now overridable to allow that.
vmtest.sh runs the tswg natlab vmtests, which live in a tailscale.com
checkout (on the bradfitz/tswg branch) because they use its natlab
framework and the Go tswg netlink client there.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I00eb5cbf8df5a203d6d39d541779060db74da9a1
The fork tracks the newest upstream WireGuard (7.4-rc1), but has to build
on distro kernels. Our first target is the natlab Ubuntu 24.04 guest
(6.8.0-106-generic) and the dev host is on 7.0.
Rather than LINUX_VERSION_CODE checks, which lie on heavily backported
kernels such as RHEL's, scripts/probe.sh compile-tests each
src/compat/probes/HAVE_*.c against the target kernel's build directory
(in parallel, about one second in total) and writes
src/compat/generated/autoconf.h. Kbuild force-includes src/compat/compat.h,
which shims whatever is missing: udp_get_len_short, the struct sock
udp_tunnel APIs, the ipcb_flags xmit arguments, the blake2s_ctx API,
WQ_PERCPU, netif_threaded_enable, rtnl_newlink_params, sockaddr_inet, the
kmalloc_obj family and timer_container_of.
Three spots in device.c can't be shimmed from a header (the lltx bit, the
old rtnl newlink signature, and pernet exit_rtnl) and get small #ifdefs
marked TSWG_COMPAT. device.c also always sets ndo_get_stats64 to
dev_get_tstats64, since older kernels don't fold tstats in
dev_get_stats(). That is equivalent on new kernels.
tswg.ko now builds against both 6.8.0-106-generic and 7.0.0-1009-aws.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0ed279318b4f623688d1f178a9b8fbcc0b585219
Copy upstream/drivers/net/wireguard into src and rename only the
user-visible identifiers: the module (and thus the rtnl link kind and
device type, which come from KBUILD_MODNAME) is now tswg, and the
genetlink family is "tswg". The uapi header moves to
src/include/uapi/linux/tswg.h so it can't collide with the kernel's.
Internal wg_ symbols keep their names to keep upstream merges easy; they
aren't exported, so tswg.ko can coexist with wireguard.ko.
Add an out-of-tree Kbuild and top-level Makefile, plus
scripts/ubuntu-headers.sh, which fetches and unpacks an Ubuntu kernel's
headers so we can build for the natlab Ubuntu guest without installing
anything.
This still only builds against 7.4-era kernels; compat shims follow.
Updates #426
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ia36ef82a53efbbcdb301ed069785162372efda55