]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use isc_mem_reget() to handle the internal active handle cache
authorOndřej Surý <ondrej@isc.org>
Wed, 22 Sep 2021 18:03:43 +0000 (20:03 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 23 Sep 2021 20:17:15 +0000 (22:17 +0200)
The netmgr, has an internal cache for freed active handles.  This cache
was allocated using isc_mem_allocate()/isc_mem_free() API because it was
simpler to reallocate the cache when we needed to grow it.  The new
isc_mem_reget() function could be used here reducing the need to use
isc_mem_allocate() API which is tad bit slower than isc_mem_get() API.

lib/isc/netmgr/netmgr.c

index cd051ee5173d3042fc55b379928df2760492cc4e..5b1ff7cdb85b8f9067118c91b794873c90700cbf 100644 (file)
@@ -1258,8 +1258,10 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
        isc_astack_destroy(sock->inactivereqs);
        sock->magic = 0;
 
-       isc_mem_free(sock->mgr->mctx, sock->ah_frees);
-       isc_mem_free(sock->mgr->mctx, sock->ah_handles);
+       isc_mem_put(sock->mgr->mctx, sock->ah_frees,
+                   sock->ah_size * sizeof(sock->ah_frees[0]));
+       isc_mem_put(sock->mgr->mctx, sock->ah_handles,
+                   sock->ah_size * sizeof(sock->ah_handles[0]));
        isc_mutex_destroy(&sock->lock);
        isc_condition_destroy(&sock->scond);
 #if HAVE_LIBNGHTTP2
@@ -1471,9 +1473,9 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
        isc_nm_attach(mgr, &sock->mgr);
        sock->uv_handle.handle.data = sock;
 
-       sock->ah_frees = isc_mem_allocate(
-               mgr->mctx, sock->ah_size * sizeof(sock->ah_frees[0]));
-       sock->ah_handles = isc_mem_allocate(
+       sock->ah_frees = isc_mem_get(mgr->mctx,
+                                    sock->ah_size * sizeof(sock->ah_frees[0]));
+       sock->ah_handles = isc_mem_get(
                mgr->mctx, sock->ah_size * sizeof(sock->ah_handles[0]));
        ISC_LINK_INIT(&sock->quotacb, link);
        for (size_t i = 0; i < 32; i++) {
@@ -1638,12 +1640,14 @@ isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
        LOCK(&sock->lock);
        /* We need to add this handle to the list of active handles */
        if ((size_t)atomic_load(&sock->ah) == sock->ah_size) {
-               sock->ah_frees =
-                       isc_mem_reallocate(sock->mgr->mctx, sock->ah_frees,
-                                          sock->ah_size * 2 * sizeof(size_t));
-               sock->ah_handles = isc_mem_reallocate(
+               sock->ah_frees = isc_mem_reget(
+                       sock->mgr->mctx, sock->ah_frees,
+                       sock->ah_size * sizeof(sock->ah_frees[0]),
+                       sock->ah_size * 2 * sizeof(sock->ah_frees[0]));
+               sock->ah_handles = isc_mem_reget(
                        sock->mgr->mctx, sock->ah_handles,
-                       sock->ah_size * 2 * sizeof(isc_nmhandle_t *));
+                       sock->ah_size * sizeof(sock->ah_handles[0]),
+                       sock->ah_size * 2 * sizeof(sock->ah_handles[0]));
 
                for (size_t i = sock->ah_size; i < sock->ah_size * 2; i++) {
                        sock->ah_frees[i] = i;