diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2022-02-20 03:52:44 +0100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-02-21 13:41:13 +0100 |
commit | 6c931118643c8fa35935ddbd920cb669dec10021 (patch) | |
tree | c06030d619a7532bea73237713cf03868c039785 /tcp.c | |
parent | 9afd87b7334d8ea9cd7ca35b9f838a21ef093eaa (diff) | |
download | passt-6c931118643c8fa35935ddbd920cb669dec10021.tar passt-6c931118643c8fa35935ddbd920cb669dec10021.tar.gz passt-6c931118643c8fa35935ddbd920cb669dec10021.tar.bz2 passt-6c931118643c8fa35935ddbd920cb669dec10021.tar.lz passt-6c931118643c8fa35935ddbd920cb669dec10021.tar.xz passt-6c931118643c8fa35935ddbd920cb669dec10021.tar.zst passt-6c931118643c8fa35935ddbd920cb669dec10021.zip |
tcp, udp: Receive batching doesn't pay off when writing single frames to tap
In pasta mode, when we get data from sockets and write it as single
frames to the tap device, we batch receive operations considerably,
and then (conceptually) split the data in many smaller writes.
It looked like an obvious choice, but performance is actually better
if we receive data in many small frame-sized recvmsg()/recvmmsg().
The syscall overhead with the previous behaviour, observed by perf,
comes predominantly from write operations, but receiving data in
shorter chunks probably improves cache locality by a considerable
amount.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r-- | tcp.c | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -343,7 +343,9 @@ #define MAX_TAP_CONNS (128 * 1024) #define MAX_SPLICE_CONNS (128 * 1024) -#define TCP_TAP_FRAMES 256 +#define TCP_TAP_FRAMES_MEM 256 +#define TCP_TAP_FRAMES \ + (c->mode == MODE_PASST ? TCP_TAP_FRAMES_MEM : 1) #define MAX_PIPE_SIZE (2UL * 1024 * 1024) @@ -609,7 +611,7 @@ static struct tcp4_l2_buf_t { #else } __attribute__ ((packed, aligned(__alignof__(unsigned int)))) #endif -tcp4_l2_buf[TCP_TAP_FRAMES]; +tcp4_l2_buf[TCP_TAP_FRAMES_MEM]; static unsigned int tcp4_l2_buf_used; static size_t tcp4_l2_buf_bytes; @@ -640,21 +642,21 @@ struct tcp6_l2_buf_t { #else } __attribute__ ((packed, aligned(__alignof__(unsigned int)))) #endif -tcp6_l2_buf[TCP_TAP_FRAMES]; +tcp6_l2_buf[TCP_TAP_FRAMES_MEM]; static unsigned int tcp6_l2_buf_used; static size_t tcp6_l2_buf_bytes; /* recvmsg()/sendmsg() data for tap */ static char tcp_buf_discard [MAX_WINDOW]; -static struct iovec iov_sock [TCP_TAP_FRAMES + 1]; +static struct iovec iov_sock [TCP_TAP_FRAMES_MEM + 1]; -static struct iovec tcp4_l2_iov_tap [TCP_TAP_FRAMES]; -static struct iovec tcp6_l2_iov_tap [TCP_TAP_FRAMES]; -static struct iovec tcp4_l2_flags_iov_tap [TCP_TAP_FRAMES]; -static struct iovec tcp6_l2_flags_iov_tap [TCP_TAP_FRAMES]; +static struct iovec tcp4_l2_iov_tap [TCP_TAP_FRAMES_MEM]; +static struct iovec tcp6_l2_iov_tap [TCP_TAP_FRAMES_MEM]; +static struct iovec tcp4_l2_flags_iov_tap [TCP_TAP_FRAMES_MEM]; +static struct iovec tcp6_l2_flags_iov_tap [TCP_TAP_FRAMES_MEM]; -static struct mmsghdr tcp_l2_mh_tap [TCP_TAP_FRAMES]; +static struct mmsghdr tcp_l2_mh_tap [TCP_TAP_FRAMES_MEM]; /* sendmsg() to socket */ static struct iovec tcp_tap_iov [UIO_MAXIOV]; @@ -688,7 +690,7 @@ static struct tcp4_l2_flags_buf_t { #else } __attribute__ ((packed, aligned(__alignof__(unsigned int)))) #endif -tcp4_l2_flags_buf[TCP_TAP_FRAMES]; +tcp4_l2_flags_buf[TCP_TAP_FRAMES_MEM]; static int tcp4_l2_flags_buf_used; @@ -717,7 +719,7 @@ static struct tcp6_l2_flags_buf_t { #else } __attribute__ ((packed, aligned(__alignof__(unsigned int)))) #endif -tcp6_l2_flags_buf[TCP_TAP_FRAMES]; +tcp6_l2_flags_buf[TCP_TAP_FRAMES_MEM]; static int tcp6_l2_flags_buf_used; @@ -916,7 +918,7 @@ void tcp_update_l2_buf(unsigned char *eth_d, unsigned char *eth_s, { int i; - for (i = 0; i < TCP_TAP_FRAMES; i++) { + for (i = 0; i < TCP_TAP_FRAMES_MEM; i++) { struct tcp4_l2_flags_buf_t *b4f = &tcp4_l2_flags_buf[i]; struct tcp6_l2_flags_buf_t *b6f = &tcp6_l2_flags_buf[i]; struct tcp4_l2_buf_t *b4 = &tcp4_l2_buf[i]; @@ -982,12 +984,13 @@ static void tcp_sock4_iov_init(void) }; } - for (i = 0, iov = tcp4_l2_iov_tap; i < TCP_TAP_FRAMES; i++, iov++) { + for (i = 0, iov = tcp4_l2_iov_tap; i < TCP_TAP_FRAMES_MEM; i++, iov++) { iov->iov_base = &tcp4_l2_buf[i].vnet_len; iov->iov_len = MSS_DEFAULT; } - for (i = 0, iov = tcp4_l2_flags_iov_tap; i < TCP_TAP_FRAMES; i++, iov++) + for (i = 0, iov = tcp4_l2_flags_iov_tap; i < TCP_TAP_FRAMES_MEM; + i++, iov++) iov->iov_base = &tcp4_l2_flags_buf[i].vnet_len; } @@ -1015,12 +1018,13 @@ static void tcp_sock6_iov_init(void) }; } - for (i = 0, iov = tcp6_l2_iov_tap; i < TCP_TAP_FRAMES; i++, iov++) { + for (i = 0, iov = tcp6_l2_iov_tap; i < TCP_TAP_FRAMES_MEM; i++, iov++) { iov->iov_base = &tcp6_l2_buf[i].vnet_len; iov->iov_len = MSS_DEFAULT; } - for (i = 0, iov = tcp6_l2_flags_iov_tap; i < TCP_TAP_FRAMES; i++, iov++) + for (i = 0, iov = tcp6_l2_flags_iov_tap; i < TCP_TAP_FRAMES_MEM; + i++, iov++) iov->iov_base = &tcp6_l2_flags_buf[i].vnet_len; } |