From: Ondřej Surý Date: Wed, 23 Feb 2022 07:54:49 +0000 (+0100) Subject: Remove active handles tracking from isc__nmsocket_t X-Git-Tag: v9.16.27~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7765263e68be47434b7882c83b10d806b62b8072;p=thirdparty%2Fbind9.git Remove active handles tracking from isc__nmsocket_t The isc__nmsocket_t has locked array of isc_nmhandle_t that's not used for anything. The isc__nmhandle_get() adds the isc_nmhandle_t to the locked array (and resized if necessary) and removed when isc_nmhandle_put() finally destroys the handle. That's all it does, so it serves no useful purpose. Remove the .ah_handles, .ah_size, and .ah_frees members of the isc__nmsocket_t and .ah_pos member of the isc_nmhandle_t struct. (cherry picked from commit e2555a306f1fc157e06d750158fbb47ba70bbba7) --- diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 30f47341712..4a7cb681869 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -239,7 +239,6 @@ struct isc_nmhandle { * the socket. */ isc_nmsocket_t *sock; - size_t ah_pos; /* Position in the socket's 'active handles' array */ isc_sockaddr_t peer; isc_sockaddr_t local; @@ -911,30 +910,9 @@ struct isc_nmsocket { isc_result_t result; /*% - * List of active handles. - * ah - current position in 'ah_frees'; this represents the - * current number of active handles; - * ah_size - size of the 'ah_frees' and 'ah_handles' arrays - * ah_handles - array pointers to active handles - * - * Adding a handle - * - if ah == ah_size, reallocate - * - x = ah_frees[ah] - * - ah_frees[ah++] = 0; - * - ah_handles[x] = handle - * - x must be stored with the handle! - * Removing a handle: - * - ah_frees[--ah] = x - * - ah_handles[x] = NULL; - * - * XXX: for now this is locked with socket->lock, but we - * might want to change it to something lockless in the - * future. + * Current number of active handles. */ atomic_int_fast32_t ah; - size_t ah_size; - size_t *ah_frees; - isc_nmhandle_t **ah_handles; /*% Buffer for TCPDNS processing */ size_t buf_size; diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index a8e3290f529..9cff4ee7206 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -1257,8 +1257,6 @@ 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_condition_destroy(&sock->scond); isc_condition_destroy(&sock->cond); isc_mutex_destroy(&sock->lock); @@ -1435,7 +1433,6 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type, *sock = (isc_nmsocket_t){ .type = type, .iface = *iface, .fd = -1, - .ah_size = 32, .inactivehandles = isc_astack_new( mgr->mctx, ISC_NM_HANDLES_STACK_SIZE), .inactivereqs = isc_astack_new( @@ -1453,15 +1450,7 @@ 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(size_t)); - sock->ah_handles = isc_mem_allocate( - mgr->mctx, sock->ah_size * sizeof(isc_nmhandle_t *)); ISC_LINK_INIT(&sock->quotacb, link); - for (size_t i = 0; i < 32; i++) { - sock->ah_frees[i] = i; - sock->ah_handles[i] = NULL; - } switch (type) { case isc_nm_udpsocket: @@ -1560,8 +1549,6 @@ isc_nmhandle_t * isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer, isc_sockaddr_t *local FLARG) { isc_nmhandle_t *handle = NULL; - size_t handlenum; - int pos; REQUIRE(VALID_NMSOCK(sock)); @@ -1596,34 +1583,13 @@ isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer, handle->local = sock->iface; } - 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->mgr->mctx, sock->ah_handles, - sock->ah_size * 2 * sizeof(isc_nmhandle_t *)); - - for (size_t i = sock->ah_size; i < sock->ah_size * 2; i++) { - sock->ah_frees[i] = i; - sock->ah_handles[i] = NULL; - } - - sock->ah_size *= 2; - } - - handlenum = atomic_fetch_add(&sock->ah, 1); - pos = sock->ah_frees[handlenum]; + (void)atomic_fetch_add(&sock->ah, 1); - INSIST(sock->ah_handles[pos] == NULL); - sock->ah_handles[pos] = handle; - handle->ah_pos = pos; #ifdef NETMGR_TRACE + LOCK(&sock->lock); ISC_LIST_APPEND(sock->active_handles, handle, active_link); -#endif UNLOCK(&sock->lock); +#endif switch (sock->type) { case isc_nm_udpsocket: @@ -1688,7 +1654,6 @@ nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) { static void nmhandle_deactivate(isc_nmsocket_t *sock, isc_nmhandle_t *handle) { - size_t handlenum; bool reuse = false; /* @@ -1698,18 +1663,12 @@ nmhandle_deactivate(isc_nmsocket_t *sock, isc_nmhandle_t *handle) { */ LOCK(&sock->lock); - INSIST(sock->ah_handles[handle->ah_pos] == handle); - INSIST(sock->ah_size > handle->ah_pos); - INSIST(atomic_load(&sock->ah) > 0); - #ifdef NETMGR_TRACE ISC_LIST_UNLINK(sock->active_handles, handle, active_link); #endif - sock->ah_handles[handle->ah_pos] = NULL; - handlenum = atomic_fetch_sub(&sock->ah, 1) - 1; - sock->ah_frees[handlenum] = handle->ah_pos; - handle->ah_pos = 0; + INSIST(atomic_fetch_sub(&sock->ah, 1) > 0); + if (atomic_load(&sock->active)) { reuse = isc_astack_trypush(sock->inactivehandles, handle); }