From: Witold Kręcicki Date: Wed, 3 Oct 2018 22:11:52 +0000 (+0000) Subject: Mangle fdlocks a bit. X-Git-Tag: v9.13.4~20^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c926a5d9b01c321705e01b65cc48afb6fc7f2a0;p=thirdparty%2Fbind9.git Mangle fdlocks a bit. Mutexes are slower if they're in the same cache line. Since fd's come in herds, and usually our listen sockets will have nearby fd numbers, we mangle fdlocks so that the locks are further away. --- diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index aa8554e07fc..84f14c610ac 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -184,10 +184,12 @@ typedef enum { poll_idle, poll_active, poll_checking } pollstate_t; #endif /* ISC_SOCKET_USE_POLLWATCH */ /*% - * Size of per-FD lock buckets. + * Per-FD lock buckets, we shuffle them around a bit as FDs come in herds. */ -#define FDLOCK_COUNT 1024 -#define FDLOCK_ID(fd) ((fd) % FDLOCK_COUNT) +#define FDLOCK_BITS 10 +#define FDLOCK_COUNT (1<>(FDLOCK_BITS/2)) |\ + (((fd)<<(FDLOCK_BITS/2))%(FDLOCK_COUNT))) /*% * Maximum number of events communicated with the kernel. There should normally @@ -3756,7 +3758,7 @@ setup_thread(isc__socketthread_t *thread) { if (result != ISC_R_SUCCESS) manager->open_max = 64; manager->calls = 0; - manager->events = isc_mem_get(thread->manager->mctx, + manager->events = isc_mem_get(thread->manager->mctx, sizeof(struct pollfd) * manager->nevents); if (manager->events == NULL) @@ -5469,11 +5471,11 @@ init_hasreuseport() { close(sock); return; } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, - sizeof(yes)) < 0) { + sizeof(yes)) < 0) { close(sock); return; } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&yes, - sizeof(yes)) < 0) { + sizeof(yes)) < 0) { close(sock); return; } diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 1a63ff4f4f6..32b7ca70dca 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -3693,7 +3693,7 @@ isc_socket_socketevent(isc_mem_t *mctx, void *sender, bool isc_socket_hasreuseport() { - return (false); + return (false); } #ifdef HAVE_LIBXML2