diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-09-26 23:19:40 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-09-27 01:28:02 +0200 |
commit | 2dbed699e78ed3393ac97a64b04581974070afed (patch) | |
tree | 509f88c1caf3ca359408656983201ea15eeafd37 | |
parent | cc8db1c5bcca6d84e7bd3ba7e0a5108b62937578 (diff) | |
download | passt-2dbed699e78ed3393ac97a64b04581974070afed.tar passt-2dbed699e78ed3393ac97a64b04581974070afed.tar.gz passt-2dbed699e78ed3393ac97a64b04581974070afed.tar.bz2 passt-2dbed699e78ed3393ac97a64b04581974070afed.tar.lz passt-2dbed699e78ed3393ac97a64b04581974070afed.tar.xz passt-2dbed699e78ed3393ac97a64b04581974070afed.tar.zst passt-2dbed699e78ed3393ac97a64b04581974070afed.zip |
passt: Align pkt_buf to PAGE_SIZE (start and size), try to fit in huge pages
If transparent huge pages are available, madvise() will do the trick.
While at it, decrease EPOLL_EVENTS for the main loop from 10 to 8,
for slightly better socket fairness.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | passt.c | 8 | ||||
-rw-r--r-- | passt.h | 3 | ||||
-rw-r--r-- | util.h | 1 |
4 files changed, 10 insertions, 3 deletions
@@ -1,5 +1,6 @@ CFLAGS += -Wall -Wextra -pedantic CFLAGS += -DRLIMIT_STACK_VAL=$(shell ulimit -s) +CFLAGS += -DPAGE_SIZE=$(shell getconf PAGE_SIZE) prefix ?= /usr/local @@ -28,6 +28,7 @@ #include <sys/stat.h> #include <dirent.h> #include <fcntl.h> +#include <sys/mman.h> #include <sys/resource.h> #include <sys/uio.h> #include <sys/wait.h> @@ -61,12 +62,12 @@ #include "tap.h" #include "conf.h" -#define EPOLL_EVENTS 10 +#define EPOLL_EVENTS 8 #define __TIMER_INTERVAL MIN(TCP_TIMER_INTERVAL, UDP_TIMER_INTERVAL) #define TIMER_INTERVAL MIN(__TIMER_INTERVAL, ICMP_TIMER_INTERVAL) -char pkt_buf [PKT_BUF_BYTES]; +char pkt_buf[PKT_BUF_BYTES] __attribute__ ((aligned(PAGE_SIZE))); char *ip_proto_str[IPPROTO_SCTP + 1] = { [IPPROTO_ICMP] = "ICMP", @@ -323,6 +324,9 @@ int main(int argc, char **argv) log_name = "passt"; } + if (madvise(pkt_buf, TAP_BUF_BYTES, MADV_HUGEPAGE)) + perror("madvise"); + openlog(log_name, 0, LOG_DAEMON); setlogmask(LOG_MASK(LOG_EMERG)); @@ -45,7 +45,8 @@ union epoll_ref { uint64_t u64; }; -#define TAP_BUF_BYTES ((ETH_MAX_MTU + sizeof(uint32_t)) * 256) +#define TAP_BUF_BYTES \ + ROUND_DOWN(((ETH_MAX_MTU + sizeof(uint32_t)) * 256), PAGE_SIZE) #define TAP_BUF_FILL (TAP_BUF_BYTES - ETH_MAX_MTU - sizeof(uint32_t)) #define TAP_MSGS \ DIV_ROUND_UP(TAP_BUF_BYTES, ETH_ZLEN - 2 * ETH_ALEN + sizeof(uint32_t)) @@ -25,6 +25,7 @@ void debug(const char *format, ...); #endif #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#define ROUND_DOWN(x, y) ((x) & ~((y) - 1)) #define SWAP(a, b) \ do { \ |