From 8edbd0929fa4e28139798a50950efc2dac491d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 22 Sep 2021 20:03:43 +0200 Subject: [PATCH] Use isc_mem_reget() to handle the internal active handle cache 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 | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index cd051ee517..5b1ff7cdb8 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -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;