mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-06 08:32:21 -08:00
kernel/linux/src: recruit fewer crypt workers, and go inline for slow peers
One 7 Gbps tunnel between 128-CPU hosts had its crypt work spread over 33 CPUs, each about 15% busy, mostly waking up and going back to sleep, for up to 1.6x wireguard-go's CPU per GB: a worker was recruited whenever more than one GRO packet's worth waited, which GRO's bursts always did. Now one is recruited only when more than recruit_factor (default 16) times that waits for each worker draining, capped at a quarter of the ring, and from a compact set of CPUs after the caller's, twice as many as were draining at once in the last 10ms, rather than round robin over every CPU. And for request/response traffic, the handoff to a worker is on each response's critical path, so a local socket's bulk sends to a peer sending under tx_inline_mbps (default 2000) are encrypted inline, and rx_inline_mbps drops from 4000 to 1000, so faster peers' receives go the parallel way sooner. Between two c6in.32xlarge hosts on EC2, at EC2's per-flow limit, tswg now uses 0.52-1.02x wireguard-go's CPU per GB (was up to 1.6x), and one HTTP-like stream gets 3.0 Gbps to its 3.3 (was 2.5). Crawling 37 peers goes from 76 to 89 Gbps; routing and serving are unchanged. Updates #426 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: I777adf1eadb4f309c62111ed3b2695a816350c56
This commit is contained in:
1 parent
e7d0021cac
commit
867eaea830
7 files changed
+203
-27
No files matched your search
@@ -932,7 +932,7 @@ void wg_packet_decrypt_worker(struct work_struct *work)
|
||||
struct crypt_queue *queue = w->ptr;
|
||||
struct sk_buff *skb;
|
||||
|
||||
WRITE_ONCE(w->tswg_busy, true); /* TSWG */
|
||||
tswg_crypt_worker_start(w, queue); /* TSWG */
|
||||
again:
|
||||
while ((skb = ptr_ring_consume_bh(&queue->ring)) != NULL) {
|
||||
enum packet_state state =
|
||||
@@ -963,8 +963,11 @@ again:
|
||||
* But that's one CPU per peer, which a single fast peer outruns: one TCP
|
||||
* stream through a tunnel fell from 12.2 to 6.6 Gbps in the lab. So a peer
|
||||
* goes the parallel way while it's receiving more than rx_inline_mbps
|
||||
* (module parameter; 0 for never inline), over TSWG_RX_WINDOW (a jiffy was
|
||||
* too short: GRO's bursts put peers of a router averaging 2 Gbps over 4),
|
||||
* (module parameter, default 1000; 0 for never inline), over TSWG_RX_WINDOW
|
||||
* (a jiffy was too short: GRO's bursts put peers of a router averaging 2
|
||||
* Gbps over 4). At 4000, one HTTP-like stream between big hosts got 2.5
|
||||
* Gbps to wireguard-go's 3.3, and a crawler of 37 peers 76 Gbps; at 1000,
|
||||
* 2.9 and 89, with routers and servers unchanged.
|
||||
* and for TSWG_RX_PARALLEL_FOR after (switching back and forth often cost
|
||||
* more than either way), and back only once that way has delivered all it
|
||||
* had, so that switching doesn't reorder the peer's packets; see
|
||||
@@ -974,7 +977,7 @@ again:
|
||||
#define TSWG_RX_WINDOW max(HZ / 100, 1)
|
||||
#define TSWG_RX_PARALLEL_FOR (HZ / 10)
|
||||
|
||||
static unsigned int tswg_rx_inline_mbps = 4000;
|
||||
static unsigned int tswg_rx_inline_mbps = 1000;
|
||||
module_param_named(rx_inline_mbps, tswg_rx_inline_mbps, uint, 0644);
|
||||
MODULE_PARM_DESC(rx_inline_mbps, "receive a peer's packets where they arrive while it's below this rate (0: never)");
|
||||
|
||||
|
||||
Reference in new issue
Block a user