]> 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>
Tue, 6 Nov 2018 11:25:09 +0000 (11:25 +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 8cda44f583c684f7cbe6e9a0d8b1dae71eaa0832..08fdad747c09614510e51da95196ce7aa92e5f19 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
@@ -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;
        }
index 026b4da765bacf60757ccd6f239b4bd5bc34e684..55c9cbb45e6669e7fb82c986c31347e9ff0ee3bc 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