]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use smaller pools of requests and handles for sockets
authorArtem Boldariev <artem@boldariev.com>
Tue, 18 Jun 2024 08:43:49 +0000 (11:43 +0300)
committerArtem Boldariev <artem@boldariev.com>
Tue, 18 Jun 2024 14:54:17 +0000 (17:54 +0300)
This commit ensures that socket objects use smaller sizes for its
internal requests and handles pools. That prevents a memory allocator
from thrashing.

lib/isc/netmgr/netmgr.c

index 23af9cdf1c1e6ae10920e822d97a9b064bdf38f6..01c770d56aa0b7cce7f9171dc719a747921d8c67 100644 (file)
  * How many isc_nmhandles and isc_nm_uvreqs will we be
  * caching for reuse in a socket.
  */
-#define ISC_NM_HANDLES_STACK_SIZE 600
-#define ISC_NM_REQS_STACK_SIZE   600
+#define ISC_NM_HANDLES_STACK_SIZE 16
+#define ISC_NM_REQS_STACK_SIZE   16
+
+/*%
+ * Same, but for UDP sockets which tend to need larger values as they
+ * process many requests per socket.
+ */
+#define ISC_NM_HANDLES_STACK_SIZE_UDP 64
+#define ISC_NM_REQS_STACK_SIZE_UDP    64
 
 /*%
  * Shortcut index arrays to get access to statistics counters.
@@ -1508,16 +1515,25 @@ void
 isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
                    isc_sockaddr_t *iface FLARG) {
        uint16_t family;
+       size_t inactive_handles_stack_size = ISC_NM_HANDLES_STACK_SIZE;
+       size_t inactive_reqs_stack_size = ISC_NM_REQS_STACK_SIZE;
 
        REQUIRE(sock != NULL);
        REQUIRE(mgr != NULL);
 
-       *sock = (isc_nmsocket_t){ .type = type,
-                                 .fd = -1,
-                                 .inactivehandles = isc_astack_new(
-                                         mgr->mctx, ISC_NM_HANDLES_STACK_SIZE),
-                                 .inactivereqs = isc_astack_new(
-                                         mgr->mctx, ISC_NM_REQS_STACK_SIZE) };
+       if (type == isc_nm_udpsocket) {
+               inactive_handles_stack_size = ISC_NM_HANDLES_STACK_SIZE_UDP;
+               inactive_reqs_stack_size = ISC_NM_REQS_STACK_SIZE_UDP;
+       }
+
+       *sock = (isc_nmsocket_t){
+               .type = type,
+               .fd = -1,
+               .inactivehandles = isc_astack_new(mgr->mctx,
+                                                 inactive_handles_stack_size),
+               .inactivereqs = isc_astack_new(mgr->mctx,
+                                              inactive_reqs_stack_size)
+       };
 
        ISC_LIST_INIT(sock->tls.sendreqs);