Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 5bbba0d

Browse files
committed
Simplify tracing the reference counting in isc_netmgr
Always track the per-worker sockets in the .active_sockets field in the isc__networker_t struct and always track the per-socket handles in the .active_handles field ian the isc_nmsocket_t struct.
1 parent 56d7e01 commit 5bbba0d

File tree

8 files changed

+94
-122
lines changed

8 files changed

+94
-122
lines changed

lib/isc/include/isc/netmgr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <sys/socket.h>
2525
#include <sys/types.h>
2626

27+
#undef ISC_NETMGR_TRACE
28+
2729
#if defined(SO_REUSEPORT_LB) || (defined(SO_REUSEPORT) && defined(__linux__))
2830
#define HAVE_SO_REUSEPORT_LB 1
2931
#endif
@@ -146,7 +148,7 @@ isc_nmsocket_set_max_streams(isc_nmsocket_t *listener,
146148
* \li 'listener' is a pointer to a valid network manager listener socket.
147149
*/
148150

149-
#ifdef NETMGR_TRACE
151+
#ifdef ISC_NETMGR_TRACE
150152
#define isc_nmhandle_attach(handle, dest) \
151153
isc__nmhandle_attach(handle, dest, __FILE__, __LINE__, __func__)
152154
#define isc_nmhandle_detach(handlep) \

lib/isc/netmgr/http.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ isc_nm_httpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
14701470
}
14711471

14721472
sock = isc_mem_get(worker->mctx, sizeof(*sock));
1473-
isc__nmsocket_init(sock, worker, isc_nm_httpsocket, local);
1473+
isc__nmsocket_init(sock, worker, isc_nm_httpsocket, local, NULL);
14741474

14751475
sock->connect_timeout = timeout;
14761476
sock->connect_cb = cb;
@@ -1655,7 +1655,8 @@ server_on_begin_headers_callback(nghttp2_session *ngsession,
16551655
worker = session->handle->sock->worker;
16561656
socket = isc_mem_get(worker->mctx, sizeof(isc_nmsocket_t));
16571657
isc__nmsocket_init(socket, worker, isc_nm_httpsocket,
1658-
(isc_sockaddr_t *)&session->handle->sock->iface);
1658+
(isc_sockaddr_t *)&session->handle->sock->iface,
1659+
NULL);
16591660
socket->peer = session->handle->sock->peer;
16601661
socket->h2 = (isc_nmsocket_h2_t){
16611662
.psock = socket,
@@ -2501,7 +2502,7 @@ isc_nm_listenhttp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
25012502
REQUIRE(isc_tid() == 0);
25022503

25032504
sock = isc_mem_get(worker->mctx, sizeof(*sock));
2504-
isc__nmsocket_init(sock, worker, isc_nm_httplistener, iface);
2505+
isc__nmsocket_init(sock, worker, isc_nm_httplistener, iface, NULL);
25052506
atomic_init(&sock->h2.max_concurrent_streams,
25062507
NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS);
25072508

lib/isc/netmgr/netmgr-int.h

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,34 +111,24 @@ STATIC_ASSERT(ISC_NETMGR_TCP_RECVBUF_SIZE <= ISC_NETMGR_RECVBUF_SIZE,
111111
#define NM_MAXSEG (1280 - 20 - 40)
112112

113113
/*
114-
* Define NETMGR_TRACE to activate tracing of handles and sockets.
114+
* Define ISC_NETMGR_TRACE to activate tracing of handles and sockets.
115115
* This will impair performance but enables us to quickly determine,
116116
* if netmgr resources haven't been cleaned up on shutdown, which ones
117117
* are still in use.
118118
*/
119-
#ifdef NETMGR_TRACE
119+
#if ISC_NETMGR_TRACE
120120
#define TRACE_SIZE 8
121121

122-
void
123-
isc__nm_dump_active(isc_nm_t *nm);
124-
125122
#if defined(__linux__)
126123
#include <syscall.h>
127124
#define gettid() (uint32_t) syscall(SYS_gettid)
128125
#else
129126
#define gettid() (uint32_t) pthread_self()
130127
#endif
131128

132-
#ifdef NETMGR_TRACE_VERBOSE
133129
#define NETMGR_TRACE_LOG(format, ...) \
134130
fprintf(stderr, "%" PRIu32 ":%d:%s:%u:%s:" format, gettid(), \
135131
isc_tid(), file, line, func, __VA_ARGS__)
136-
#else
137-
#define NETMGR_TRACE_LOG(format, ...) \
138-
(void)file; \
139-
(void)line; \
140-
(void)func;
141-
#endif
142132

143133
#define FLARG_PASS , file, line, func
144134
#define FLARG \
@@ -157,9 +147,9 @@ isc__nm_dump_active(isc_nm_t *nm);
157147
isc___nm_uvreq_get(req, sock, __FILE__, __LINE__, __func__)
158148
#define isc__nm_uvreq_put(req, sock) \
159149
isc___nm_uvreq_put(req, sock, __FILE__, __LINE__, __func__)
160-
#define isc__nmsocket_init(sock, mgr, type, iface) \
161-
isc___nmsocket_init(sock, mgr, type, iface, __FILE__, __LINE__, \
162-
__func__)
150+
#define isc__nmsocket_init(sock, mgr, type, iface, parent) \
151+
isc___nmsocket_init(sock, mgr, type, iface, parent, __FILE__, \
152+
__LINE__, __func__)
163153
#define isc__nmsocket_put(sockp) \
164154
isc___nmsocket_put(sockp, __FILE__, __LINE__, __func__)
165155
#define isc__nmsocket_attach(sock, target) \
@@ -181,8 +171,8 @@ isc__nm_dump_active(isc_nm_t *nm);
181171
#define FLARG_IEVENT_PASS(ievent)
182172
#define isc__nm_uvreq_get(req, sock) isc___nm_uvreq_get(req, sock)
183173
#define isc__nm_uvreq_put(req, sock) isc___nm_uvreq_put(req, sock)
184-
#define isc__nmsocket_init(sock, mgr, type, iface) \
185-
isc___nmsocket_init(sock, mgr, type, iface)
174+
#define isc__nmsocket_init(sock, mgr, type, iface, parent) \
175+
isc___nmsocket_init(sock, mgr, type, iface, parent)
186176
#define isc__nmsocket_put(sockp) isc___nmsocket_put(sockp)
187177
#define isc__nmsocket_attach(sock, target) isc___nmsocket_attach(sock, target)
188178
#define isc__nmsocket_detach(socketp) isc___nmsocket_detach(socketp)
@@ -208,10 +198,16 @@ typedef struct isc__networker {
208198
char *recvbuf;
209199
char *sendbuf;
210200
bool recvbuf_inuse;
201+
202+
ISC_LIST(isc_nmsocket_t) active_sockets;
203+
211204
} isc__networker_t;
212205

213206
ISC_REFCOUNT_DECL(isc__networker);
214207

208+
void
209+
isc__nm_dump_active(isc__networker_t *worker);
210+
215211
/*
216212
* A general handle for a connection bound to a networker. For UDP
217213
* connections we have peer address here, so both TCP and UDP can be
@@ -244,11 +240,11 @@ struct isc_nmhandle {
244240
isc_sockaddr_t local;
245241
isc_nm_opaquecb_t doreset; /* reset extra callback, external */
246242
isc_nm_opaquecb_t dofree; /* free extra callback, external */
247-
#ifdef NETMGR_TRACE
243+
#if ISC_NETMGR_TRACE
248244
void *backtrace[TRACE_SIZE];
249245
int backtrace_size;
250-
LINK(isc_nmhandle_t) active_link;
251246
#endif
247+
LINK(isc_nmhandle_t) active_link;
252248
void *opaque;
253249
};
254250

@@ -700,10 +696,6 @@ struct isc_nm {
700696
atomic_int_fast32_t send_udp_buffer_size;
701697
atomic_int_fast32_t recv_tcp_buffer_size;
702698
atomic_int_fast32_t send_tcp_buffer_size;
703-
704-
#ifdef NETMGR_TRACE
705-
ISC_LIST(isc_nmsocket_t) active_sockets;
706-
#endif
707699
};
708700

709701
/*%
@@ -1030,13 +1022,12 @@ struct isc_nmsocket {
10301022

10311023
bool barriers_initialised;
10321024
bool manual_read_timer;
1033-
#ifdef NETMGR_TRACE
1025+
#if ISC_NETMGR_TRACE
10341026
void *backtrace[TRACE_SIZE];
10351027
int backtrace_size;
1028+
#endif
10361029
LINK(isc_nmsocket_t) active_link;
10371030
ISC_LIST(isc_nmhandle_t) active_handles;
1038-
isc_mutex_t tracelock;
1039-
#endif
10401031
};
10411032

10421033
void
@@ -1070,8 +1061,8 @@ isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf);
10701061
*/
10711062

10721063
isc_nmhandle_t *
1073-
isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
1074-
isc_sockaddr_t *local FLARG);
1064+
isc___nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t const *peer,
1065+
isc_sockaddr_t const *local FLARG);
10751066
/*%<
10761067
* Get a handle for the socket 'sock', allocating a new one
10771068
* if there isn't one available in 'sock->inactivehandles'.
@@ -1104,7 +1095,8 @@ isc___nm_uvreq_put(isc__nm_uvreq_t **req, isc_nmsocket_t *sock FLARG);
11041095

11051096
void
11061097
isc___nmsocket_init(isc_nmsocket_t *sock, isc__networker_t *worker,
1107-
isc_nmsocket_type type, isc_sockaddr_t *iface FLARG);
1098+
isc_nmsocket_type type, isc_sockaddr_t *iface,
1099+
isc_nmsocket_t *parent FLARG);
11081100
/*%<
11091101
* Initialize socket 'sock', attach it to 'mgr', and set it to type 'type'
11101102
* and its interface to 'iface'.

0 commit comments

Comments
 (0)