]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Mangle fdlocks a bit.
authorWitold Kręcicki <wpk@isc.org>
Wed, 3 Oct 2018 22:11:52 +0000 (22:11 +0000)
committerWitold Kręcicki <wpk@isc.org>
Thu, 15 Nov 2018 08:21:17 +0000 (08:21 +0000)
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.

lib/isc/unix/socket.c
lib/isc/win32/socket.c

index aa8554e07fc13801e8da3b80766f1d1996ba631f..84f14c610ac68e6927e3ed04610bc1200dbf923a 100644 (file)
@@ -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)
+#define FDLOCK_ID(fd)          (((fd)%(FDLOCK_COUNT)>>(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;
        }
index 1a63ff4f4f62d4ceb1e62bab477c8385f145bf33..32b7ca70dca19368bda534771ec0530e4cdac4e1 100644 (file)
@@ -3693,7 +3693,7 @@ isc_socket_socketevent(isc_mem_t *mctx, void *sender,
 
 bool
 isc_socket_hasreuseport() {
-        return (false);
+       return (false);
 }
 
 #ifdef HAVE_LIBXML2