]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Limit the number of inactive handles kept for reuse
authorOndřej Surý <ondrej@isc.org>
Wed, 16 Aug 2023 14:30:53 +0000 (16:30 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 21 Aug 2023 14:34:30 +0000 (16:34 +0200)
Instead of growing and never shrinking the list of the inactive
handles (to be reused mostly on the UDP connections), limit the number
of maximum number of inactive handles kept to 64.  Instead of caching
the inactive handles for all listening sockets, enable the caching on on
UDP listening sockets.  For TCP, the handles were cached for each
accepted socket thus reusing the handles only for long-standing TCP
connections, but not reusing the handles across different TCP streams.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/udp.c

index e3931d71fb27b55bdacb6136aa06ac457953e411..e525814f3de3a6d86cbb5b73307e9e1c3a210144 100644 (file)
@@ -104,6 +104,13 @@ STATIC_ASSERT(ISC_NETMGR_TCP_RECVBUF_SIZE <= ISC_NETMGR_RECVBUF_SIZE,
  */
 #define NM_MAXSEG (1280 - 20 - 40)
 
+/*%
+ * How many isc_nmhandles and isc_nm_uvreqs will we be
+ * caching for reuse in a socket.
+ */
+#define ISC_NM_NMHANDLES_MAX 64
+#define ISC_NM_UVREQS_MAX    64
+
 /*
  * Define ISC_NETMGR_TRACE to activate tracing of handles and sockets.
  * This will impair performance but enables us to quickly determine,
@@ -245,6 +252,7 @@ struct isc_nmhandle {
 #endif
        LINK(isc_nmhandle_t) active_link;
        LINK(isc_nmhandle_t) inactive_link;
+
        void *opaque;
 
        isc_job_t job;
@@ -624,6 +632,9 @@ struct isc_nmsocket {
         */
        ISC_LIST(isc_nmhandle_t) inactive_handles;
 
+       size_t inactive_handles_cur;
+       size_t inactive_handles_max;
+
        /*%
         * 'active' handles and uvreqs, mostly for debugging purposes.
         */
index 0f1ab466a78ecdc9b08527d9e0218893d7d2a9db..d4f2c2c7222738ac88a83b1f7d04c6a765e1508b 100644 (file)
@@ -806,6 +806,8 @@ dequeue_handle(isc_nmsocket_t *sock) {
        if (handle != NULL) {
                ISC_LIST_DEQUEUE(sock->inactive_handles, handle, inactive_link);
 
+               sock->inactive_handles_cur--;
+
                isc_refcount_init(&handle->references, 1);
                INSIST(VALID_NMHANDLE(handle));
                return (handle);
@@ -913,7 +915,10 @@ nmhandle__destroy(isc_nmhandle_t *handle) {
 #if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
        nmhandle_free(sock, handle);
 #else
-       if (sock->active) {
+       if (sock->active &&
+           sock->inactive_handles_cur < sock->inactive_handles_max)
+       {
+               sock->inactive_handles_cur++;
                ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
        } else {
                nmhandle_free(sock, handle);
index 14558900f44cf8729c1701f0c9ac0cc702167cd0..56ea1e5fa8c5ed932f21330fad5fccfb7358eb8f 100644 (file)
@@ -188,6 +188,7 @@ start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
        isc__nmsocket_init(csock, worker, isc_nm_udpsocket, iface, sock);
        csock->recv_cb = sock->recv_cb;
        csock->recv_cbarg = sock->recv_cbarg;
+       csock->inactive_handles_max = ISC_NM_NMHANDLES_MAX;
 
        if (mgr->load_balance_sockets) {
                csock->fd = isc__nm_udp_lb_socket(mgr,