2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 15:45:25 +00:00

Run closehandle_cb on run queue instead of async queue

Instead of using isc_async_run() when closing StreamDNS handle, add
isc_job_t member to the isc_nmhandle_t structure and use isc_job_run()
to avoid allocation/deallocation on the StreamDNS hot-path.
This commit is contained in:
Ondřej Surý
2023-04-09 06:48:46 +02:00
parent d27f6f2d68
commit 74cbf523b3
3 changed files with 35 additions and 23 deletions

View File

@@ -245,6 +245,8 @@ struct isc_nmhandle {
LINK(isc_nmhandle_t) active_link; LINK(isc_nmhandle_t) active_link;
LINK(isc_nmhandle_t) inactive_link; LINK(isc_nmhandle_t) inactive_link;
void *opaque; void *opaque;
isc_job_t job;
}; };
typedef union { typedef union {

View File

@@ -817,6 +817,7 @@ alloc_handle(isc_nmsocket_t *sock) {
.magic = NMHANDLE_MAGIC, .magic = NMHANDLE_MAGIC,
.active_link = ISC_LINK_INITIALIZER, .active_link = ISC_LINK_INITIALIZER,
.inactive_link = ISC_LINK_INITIALIZER, .inactive_link = ISC_LINK_INITIALIZER,
.job = ISC_JOB_INITIALIZER,
}; };
isc_refcount_init(&handle->references, 1); isc_refcount_init(&handle->references, 1);
@@ -943,19 +944,36 @@ nmhandle_free(isc_nmsocket_t *sock, isc_nmhandle_t *handle) {
} }
static void static void
isc__nm_closehandle_job(void *arg) { nmhandle__destroy(isc_nmhandle_t *handle) {
isc_nmsocket_t *sock = arg; isc_nmsocket_t *sock = handle->sock;
handle->sock = NULL;
sock->closehandle_cb(sock); #if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
nmhandle_free(sock, handle);
#else
if (sock->active) {
ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
} else {
nmhandle_free(sock, handle);
}
#endif
isc__nmsocket_detach(&sock); isc__nmsocket_detach(&sock);
} }
static void static void
nmhandle_destroy(isc_nmhandle_t *handle) { isc__nm_closehandle_job(void *arg) {
isc_nmhandle_t *handle = arg;
isc_nmsocket_t *sock = handle->sock; isc_nmsocket_t *sock = handle->sock;
handle->sock = NULL; sock->closehandle_cb(sock);
nmhandle__destroy(handle);
}
static void
nmhandle_destroy(isc_nmhandle_t *handle) {
isc_nmsocket_t *sock = handle->sock;
if (handle->doreset != NULL) { if (handle->doreset != NULL) {
handle->doreset(handle->opaque); handle->doreset(handle->opaque);
@@ -974,27 +992,18 @@ nmhandle_destroy(isc_nmhandle_t *handle) {
ISC_LIST_UNLINK(sock->active_handles, handle, active_link); ISC_LIST_UNLINK(sock->active_handles, handle, active_link);
#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__) if (sock->closehandle_cb == NULL) {
nmhandle_free(sock, handle); nmhandle__destroy(handle);
#else return;
if (sock->active) {
ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
} else {
nmhandle_free(sock, handle);
} }
#endif
/* /*
* The handle is gone now. If the socket has a callback configured * If the socket has a callback configured for that (e.g.,
* for that (e.g., to perform cleanup after request processing), * to perform cleanup after request processing), call it
* call it now asynchronously. * now asynchronously.
*/ */
if (sock->closehandle_cb != NULL) { isc_job_run(sock->worker->loop, &handle->job, isc__nm_closehandle_job,
isc_async_run(sock->worker->loop, isc__nm_closehandle_job, handle);
sock);
} else {
isc___nmsocket_detach(&sock FLARG_PASS);
}
} }
void void

View File

@@ -235,7 +235,8 @@ tls_failed_read_cb(isc_nmsocket_t *sock, const isc_result_t result) {
tls_call_connect_cb(sock, handle, result); tls_call_connect_cb(sock, handle, result);
isc__nmsocket_clearcb(sock); isc__nmsocket_clearcb(sock);
isc_nmhandle_detach(&handle); isc_nmhandle_detach(&handle);
} else if (sock->recv_cb != NULL && sock->statichandle != NULL && } else if (sock->reading && sock->recv_cb != NULL &&
sock->statichandle != NULL &&
(sock->recv_read || result == ISC_R_TIMEDOUT)) (sock->recv_read || result == ISC_R_TIMEDOUT))
{ {
sock->recv_read = false; sock->recv_read = false;