From: Witold Kręcicki Date: Wed, 3 Oct 2018 22:11:52 +0000 (+0000) Subject: Mangle fdlocks a bit. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07ef9e92a2b698e299b20a587ed28b97780bdc1b;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 8cda44f583c..08fdad747c0 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 @@ -3752,7 +3754,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) @@ -5465,11 +5467,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 026b4da765b..55c9cbb45e6 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