]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make nm->recvbuf larger and heap allocated, to allow uv_recvmmsg usage.
authorWitold Kręcicki <wpk@isc.org>
Wed, 29 Jan 2020 12:16:04 +0000 (13:16 +0100)
committerWitold Kręcicki <wpk@isc.org>
Tue, 18 Feb 2020 11:17:55 +0000 (12:17 +0100)
Upcoming version of libuv will suport uv_recvmmsg and uv_sendmmsg. To
use uv_recvmmsg we need to provide a larger buffer and be able to
properly free it.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c

index 653aa01cb075dd93dd7ef9c71349d692d182ab47..2c788004060fcf32fcaafebce3e5c100713b68aa 100644 (file)
 
 #define ISC_NETMGR_TID_UNKNOWN -1
 
+#if !defined(WIN32)
+/*
+ * New versions of libuv support recvmmsg on unices.
+ * Since recvbuf is only allocated per worker allocating a bigger one is not
+ * that wasteful.
+ * 20 here is UV__MMSG_MAXWIDTH taken from the current libuv source, nothing
+ * will break if the original value changes.
+ */
+#define ISC_NETMGR_RECVBUF_SIZE (20 * 65536)
+#else
+#define ISC_NETMGR_RECVBUF_SIZE (65536)
+#endif
+
 /*
  * Single network event loop worker.
  */
@@ -56,7 +69,7 @@ typedef struct isc__networker {
                                    * worker is paused */
        isc_refcount_t references;
        atomic_int_fast64_t pktcount;
-       char recvbuf[65536];
+       char *recvbuf;
        bool recvbuf_inuse;
 } isc__networker_t;
 
index d4a4730eb6a46305e3fd0ba68ff7c16e3e0bd714..ca0b1850076f2f67e9dc929d193b5af0221ad942 100644 (file)
@@ -196,6 +196,7 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers) {
 
                worker->ievents = isc_queue_new(mgr->mctx, 128);
                worker->ievents_prio = isc_queue_new(mgr->mctx, 128);
+               worker->recvbuf = isc_mem_get(mctx, ISC_NETMGR_RECVBUF_SIZE);
 
                /*
                 * We need to do this here and not in nm_thread to avoid a
@@ -268,6 +269,8 @@ nm_destroy(isc_nm_t **mgr0) {
 
                isc_queue_destroy(worker->ievents);
                isc_queue_destroy(worker->ievents_prio);
+               isc_mem_put(mgr->mctx, worker->recvbuf,
+                           ISC_NETMGR_RECVBUF_SIZE);
                isc_thread_join(worker->thread, NULL);
        }
 
@@ -960,14 +963,14 @@ isc__nm_alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
 
        REQUIRE(VALID_NMSOCK(sock));
        REQUIRE(isc__nm_in_netthread());
-       REQUIRE(size <= 65536);
+       REQUIRE(size <= ISC_NETMGR_RECVBUF_SIZE);
 
        worker = &sock->mgr->workers[sock->tid];
        INSIST(!worker->recvbuf_inuse);
 
        buf->base = worker->recvbuf;
        worker->recvbuf_inuse = true;
-       buf->len = size;
+       buf->len = ISC_NETMGR_RECVBUF_SIZE;
 }
 
 void
@@ -982,8 +985,13 @@ isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf) {
        worker = &sock->mgr->workers[sock->tid];
 
        REQUIRE(worker->recvbuf_inuse);
+       if (buf->base > worker->recvbuf &&
+           buf->base <= worker->recvbuf + ISC_NETMGR_RECVBUF_SIZE)
+       {
+               /* Can happen in case of recvmmsg */
+               return;
+       }
        REQUIRE(buf->base == worker->recvbuf);
-
        worker->recvbuf_inuse = false;
 }