mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-07 07:42:50 +09:00
Three changes to the data path, from profiling bulk TCP in the lean harness: Encryption. Upstream encrypts each packet in place, which first means making it linear and writable (skb_cow_data, usually a copy), and the previous commit then chained the encrypted packets as a GSO frag_list, which segmentation copied again (skb_segment must unshare each clone's head to write its headers). Now the encrypt worker copies each inner packet (finishing its checksum on the way, if needed) into pages of its own, encrypts it there, and gathers each run of equal-size messages into a UDP GSO packet whose payload is those pages. Segmenting that needs only page references, and a device with UDP segmentation offload takes it whole: virtio with USO now sends 64KB superpackets. Sender CPU at the same throughput went from about 65% to 43% per vCPU. Worker kicks. Instead of kicking a crypt worker per packet (or per 16), kick only when no worker is draining the ring, or when the backlog shows the busy ones aren't keeping up, and prefer other CPUs than the one taking packets from the NIC. A tswg_busy flag, paired with the ring under full barriers, closes the race with a worker going idle. Queue length. The peer's in-order queue overflowed at 1024 packets (1.5ms at 7 Gbps) whenever a decrypt worker was held up, and TCP took those silent drops (0.2% of packets) as congestion. Allow 4096 entries, and count drops in rx_dropped and rx_fifo_errors, which upstream doesn't. The receiver is now the bottleneck (about 6.5 Gbps): UDP packets arriving coalesced are segmented back, with software checksums, before reaching encap_rcv. That's next. Updates #426 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: Ib8d9cf9e5541b665e06d57a16b46f653d49bc3ea
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef _WG_DEVICE_H
|
|
#define _WG_DEVICE_H
|
|
|
|
#include "noise.h"
|
|
#include "allowedips.h"
|
|
#include "peerlookup.h"
|
|
#include "cookie.h"
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/workqueue.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/net.h>
|
|
#include <linux/ptr_ring.h>
|
|
|
|
struct wg_device;
|
|
|
|
struct multicore_worker {
|
|
void *ptr;
|
|
struct work_struct work;
|
|
bool tswg_busy; /* TSWG: worker is draining the ring; see tswg_crypt_kick */
|
|
struct page_frag tswg_frag; /* TSWG: encrypt worker's output pages */
|
|
};
|
|
|
|
struct crypt_queue {
|
|
struct ptr_ring ring;
|
|
struct multicore_worker __percpu *worker;
|
|
int last_cpu;
|
|
};
|
|
|
|
struct prev_queue {
|
|
struct sk_buff *head, *tail, *peeked;
|
|
struct { struct sk_buff *next, *prev; } empty; // Match first 2 members of struct sk_buff.
|
|
atomic_t count;
|
|
};
|
|
|
|
struct wg_device {
|
|
struct net_device *dev;
|
|
struct crypt_queue encrypt_queue, decrypt_queue, handshake_queue;
|
|
struct sock __rcu *sock4, *sock6;
|
|
struct net __rcu *creating_net;
|
|
struct noise_static_identity static_identity;
|
|
struct workqueue_struct *packet_crypt_wq,*handshake_receive_wq, *handshake_send_wq;
|
|
struct cookie_checker cookie_checker;
|
|
struct pubkey_hashtable *peer_hashtable;
|
|
struct index_hashtable *index_hashtable;
|
|
struct allowedips peer_allowedips;
|
|
struct mutex device_update_lock, socket_update_lock;
|
|
struct list_head device_list, peer_list;
|
|
atomic_t handshake_queue_len;
|
|
unsigned int num_peers, device_update_gen;
|
|
u32 fwmark;
|
|
u16 incoming_port;
|
|
|
|
/* TSWG: user-supplied sockets, protected by tswg_user_sock_lock. */
|
|
struct sock *tswg_user_sock4, *tswg_user_sock6;
|
|
};
|
|
|
|
int wg_device_init(void);
|
|
void wg_device_uninit(void);
|
|
|
|
#endif /* _WG_DEVICE_H */
|