]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Replace locked mempools with memory contexts
authorOndřej Surý <ondrej@sury.org>
Wed, 12 May 2021 19:16:17 +0000 (21:16 +0200)
committerOndřej Surý <ondrej@sury.org>
Wed, 15 Dec 2021 12:29:19 +0000 (13:29 +0100)
Current mempools are kind of hybrid structures - they serve two
purposes:

 1. mempool with a lock is basically static sized allocator with
    pre-allocated free items

 2. mempool without a lock is a doubly-linked list of preallocated items

The first kind of usage could be easily replaced with jemalloc small
sized arena objects and thread-local caches.

The second usage not-so-much and we need to keep this (in
libdns:message.c) for performance reasons.

bin/dig/dighost.c
bin/plugins/filter-aaaa.c
lib/dns/adb.c
lib/dns/dispatch.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c

index 7e88b6b63c81f1eaae72728271d8037212cc3011..1a362d21a17401c9bd0d1c179beb400bcea8da49 100644 (file)
@@ -170,7 +170,6 @@ unsigned int digestbits = 0;
 isc_buffer_t *namebuf = NULL;
 dns_tsigkey_t *tsigkey = NULL;
 bool validated = true;
-isc_mempool_t *commctx = NULL;
 bool debugging = false;
 bool debugtiming = false;
 bool memdebugging = false;
@@ -1426,15 +1425,6 @@ setup_libs(void) {
        check_result(result, "dst_lib_init");
        is_dst_up = true;
 
-       isc_mempool_create(mctx, COMMSIZE, &commctx);
-       isc_mempool_setname(commctx, "COMMPOOL");
-       /*
-        * 6 and 2 set as reasonable parameters for 3 or 4 nameserver
-        * systems.
-        */
-       isc_mempool_setfreemax(commctx, 6);
-       isc_mempool_setfillcount(commctx, 2);
-
        isc_mutex_init(&lookup_lock);
 }
 
@@ -1611,8 +1601,8 @@ clear_query(dig_query_t *query) {
                sockcount--;
                debug("sockcount=%d", sockcount);
        }
-       isc_mempool_put(commctx, query->recvspace);
-       isc_mempool_put(commctx, query->tmpsendspace);
+       isc_mem_put(mctx, query->recvspace, COMMSIZE);
+       isc_mem_put(mctx, query->tmpsendspace, COMMSIZE);
        isc_buffer_invalidate(&query->recvbuf);
        isc_buffer_invalidate(&query->lengthbuf);
 
@@ -1688,7 +1678,7 @@ destroy_lookup(dig_lookup_t *lookup) {
                isc_buffer_free(&lookup->querysig);
        }
        if (lookup->sendspace != NULL) {
-               isc_mempool_put(commctx, lookup->sendspace);
+               isc_mem_put(mctx, lookup->sendspace, COMMSIZE);
        }
 
        if (lookup->tsigctx != NULL) {
@@ -2339,10 +2329,7 @@ setup_lookup(dig_lookup_t *lookup) {
                check_result(result, "dns_message_settsigkey");
        }
 
-       lookup->sendspace = isc_mempool_get(commctx);
-       if (lookup->sendspace == NULL) {
-               fatal("memory allocation failure");
-       }
+       lookup->sendspace = isc_mem_get(mctx, COMMSIZE);
 
        result = dns_compress_init(&cctx, -1, mctx);
        check_result(result, "dns_compress_init");
@@ -2578,8 +2565,8 @@ setup_lookup(dig_lookup_t *lookup) {
                query->byte_count = 0;
                query->ixfr_axfr = false;
                query->sock = NULL;
-               query->recvspace = isc_mempool_get(commctx);
-               query->tmpsendspace = isc_mempool_get(commctx);
+               query->recvspace = isc_mem_get(mctx, COMMSIZE);
+               query->tmpsendspace = isc_mem_get(mctx, COMMSIZE);
                if (query->recvspace == NULL) {
                        fatal("memory allocation failure");
                }
@@ -4378,10 +4365,6 @@ destroy_libs(void) {
        check_result(result, "dns_name_settotextfilter");
 #endif /* HAVE_LIBIDN2 */
 
-       if (commctx != NULL) {
-               debug("freeing commctx");
-               isc_mempool_destroy(&commctx);
-       }
        if (socketmgr != NULL) {
                debug("freeing socketmgr");
                isc_socketmgr_destroy(&socketmgr);
index 1db3ca20bb6377739c093aa29133a8ba96f95832..018ca2bf1388eaf9526766569069d95cbc258a1d 100644 (file)
@@ -75,12 +75,6 @@ typedef struct filter_instance {
        ns_plugin_t *module;
        isc_mem_t *mctx;
 
-       /*
-        * Memory pool for use with persistent data.
-        */
-       isc_mempool_t *datapool;
-       isc_mutex_t plock;
-
        /*
         * Hash table associating a client object with its persistent data.
         */
@@ -354,25 +348,9 @@ plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
                                       cfg_line, mctx, lctx, actx));
        }
 
-       isc_mempool_create(mctx, sizeof(filter_data_t), &inst->datapool);
        CHECK(isc_ht_init(&inst->ht, mctx, 16));
        isc_mutex_init(&inst->hlock);
 
-       /*
-        * Fill the mempool with 1K filter_aaaa state objects at
-        * a time; ideally after a single allocation, the mempool will
-        * have enough to handle all the simultaneous queries the system
-        * requires and it won't be necessary to allocate more.
-        *
-        * We don't set any limit on the number of free state objects
-        * so that they'll always be returned to the pool and not
-        * freed until the pool is destroyed on shutdown.
-        */
-       isc_mempool_setfillcount(inst->datapool, 1024);
-       isc_mempool_setfreemax(inst->datapool, UINT_MAX);
-       isc_mutex_init(&inst->plock);
-       isc_mempool_associatelock(inst->datapool, &inst->plock);
-
        /*
         * Set hook points in the view's hooktable.
         */
@@ -428,10 +406,6 @@ plugin_destroy(void **instp) {
                isc_ht_destroy(&inst->ht);
                isc_mutex_destroy(&inst->hlock);
        }
-       if (inst->datapool != NULL) {
-               isc_mempool_destroy(&inst->datapool);
-               isc_mutex_destroy(&inst->plock);
-       }
        if (inst->aaaa_acl != NULL) {
                dns_acl_detach(&inst->aaaa_acl);
        }
@@ -513,10 +487,7 @@ client_state_create(const query_ctx_t *qctx, filter_instance_t *inst) {
        filter_data_t *client_state;
        isc_result_t result;
 
-       client_state = isc_mempool_get(inst->datapool);
-       if (client_state == NULL) {
-               return;
-       }
+       client_state = isc_mem_get(inst->mctx, sizeof(*client_state));
 
        client_state->mode = NONE;
        client_state->flags = 0;
@@ -543,7 +514,7 @@ client_state_destroy(const query_ctx_t *qctx, filter_instance_t *inst) {
        UNLOCK(&inst->hlock);
        RUNTIME_CHECK(result == ISC_R_SUCCESS);
 
-       isc_mempool_put(inst->datapool, client_state);
+       isc_mem_put(inst->mctx, client_state, sizeof(*client_state));
 }
 
 /*%
index 74fdc72851c33de2848b2862ed74525740558fc6..975d1714e7d6bbb8932de501c9b17916cc0ffba3 100644 (file)
@@ -112,14 +112,8 @@ struct dns_adb {
        unsigned int irefcnt;
        unsigned int erefcnt;
 
-       isc_mutex_t mplock;
-       isc_mempool_t *nmp;  /*%< dns_adbname_t */
-       isc_mempool_t *nhmp; /*%< dns_adbnamehook_t */
-       isc_mempool_t *limp; /*%< dns_adblameinfo_t */
-       isc_mempool_t *emp;  /*%< dns_adbentry_t */
-       isc_mempool_t *ahmp; /*%< dns_adbfind_t */
-       isc_mempool_t *aimp; /*%< dns_adbaddrinfo_t */
-       isc_mempool_t *afmp; /*%< dns_adbfetch_t */
+       isc_refcount_t ahrefcnt;
+       isc_refcount_t nhrefcnt;
 
        /*!
         * Bucketized locks and lists for names.
@@ -631,12 +625,6 @@ grow_entries(isc_task_t *task, isc_event_t *ev) {
        newentrylocks = isc_mem_get(adb->mctx, sizeof(*newentrylocks) * n);
        newentry_sd = isc_mem_get(adb->mctx, sizeof(*newentry_sd) * n);
        newentry_refcnt = isc_mem_get(adb->mctx, sizeof(*newentry_refcnt) * n);
-       if (newentries == NULL || newdeadentries == NULL ||
-           newentrylocks == NULL || newentry_sd == NULL ||
-           newentry_refcnt == NULL)
-       {
-               goto cleanup;
-       }
 
        /*
         * Initialise the new resources.
@@ -802,11 +790,6 @@ grow_names(isc_task_t *task, isc_event_t *ev) {
        newnamelocks = isc_mem_get(adb->mctx, sizeof(*newnamelocks) * n);
        newname_sd = isc_mem_get(adb->mctx, sizeof(*newname_sd) * n);
        newname_refcnt = isc_mem_get(adb->mctx, sizeof(*newname_refcnt) * n);
-       if (newnames == NULL || newdeadnames == NULL || newnamelocks == NULL ||
-           newname_sd == NULL || newname_refcnt == NULL)
-       {
-               goto cleanup;
-       }
 
        /*
         * Initialise the new resources.
@@ -1741,10 +1724,7 @@ static inline dns_adbname_t *
 new_adbname(dns_adb_t *adb, const dns_name_t *dnsname) {
        dns_adbname_t *name;
 
-       name = isc_mempool_get(adb->nmp);
-       if (name == NULL) {
-               return (NULL);
-       }
+       name = isc_mem_get(adb->mctx, sizeof(*name));
 
        dns_name_init(&name->name, NULL);
        dns_name_dup(dnsname, adb->mctx, &name->name);
@@ -1802,7 +1782,7 @@ free_adbname(dns_adb_t *adb, dns_adbname_t **name) {
        n->magic = 0;
        dns_name_free(&n->name, adb->mctx);
 
-       isc_mempool_put(adb->nmp, n);
+       isc_mem_put(adb->mctx, n, sizeof(*n));
        LOCK(&adb->namescntlock);
        adb->namescnt--;
        dec_adbstats(adb, dns_adbstats_namescnt);
@@ -1813,10 +1793,8 @@ static inline dns_adbnamehook_t *
 new_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) {
        dns_adbnamehook_t *nh;
 
-       nh = isc_mempool_get(adb->nhmp);
-       if (nh == NULL) {
-               return (NULL);
-       }
+       nh = isc_mem_get(adb->mctx, sizeof(*nh));
+       isc_refcount_increment0(&adb->nhrefcnt);
 
        nh->magic = DNS_ADBNAMEHOOK_MAGIC;
        nh->entry = entry;
@@ -1837,7 +1815,9 @@ free_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehook) {
        INSIST(!ISC_LINK_LINKED(nh, plink));
 
        nh->magic = 0;
-       isc_mempool_put(adb->nhmp, nh);
+
+       isc_refcount_decrement(&adb->nhrefcnt);
+       isc_mem_put(adb->mctx, nh, sizeof(*nh));
 }
 
 static inline dns_adblameinfo_t *
@@ -1845,10 +1825,7 @@ new_adblameinfo(dns_adb_t *adb, const dns_name_t *qname,
                dns_rdatatype_t qtype) {
        dns_adblameinfo_t *li;
 
-       li = isc_mempool_get(adb->limp);
-       if (li == NULL) {
-               return (NULL);
-       }
+       li = isc_mem_get(adb->mctx, sizeof(*li));
 
        dns_name_init(&li->qname, NULL);
        dns_name_dup(qname, adb->mctx, &li->qname);
@@ -1874,17 +1851,14 @@ free_adblameinfo(dns_adb_t *adb, dns_adblameinfo_t **lameinfo) {
 
        li->magic = 0;
 
-       isc_mempool_put(adb->limp, li);
+       isc_mem_put(adb->mctx, li, sizeof(*li));
 }
 
 static inline dns_adbentry_t *
 new_adbentry(dns_adb_t *adb) {
        dns_adbentry_t *e;
 
-       e = isc_mempool_get(adb->emp);
-       if (e == NULL) {
-               return (NULL);
-       }
+       e = isc_mem_get(adb->mctx, sizeof(*e));
 
        e->magic = DNS_ADBENTRY_MAGIC;
        e->lock_bucket = DNS_ADB_INVALIDBUCKET;
@@ -1954,7 +1928,7 @@ free_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) {
                li = ISC_LIST_HEAD(e->lameinfo);
        }
 
-       isc_mempool_put(adb->emp, e);
+       isc_mem_put(adb->mctx, e, sizeof(*e));
        LOCK(&adb->entriescntlock);
        adb->entriescnt--;
        dec_adbstats(adb, dns_adbstats_entriescnt);
@@ -1965,10 +1939,8 @@ static inline dns_adbfind_t *
 new_adbfind(dns_adb_t *adb) {
        dns_adbfind_t *h;
 
-       h = isc_mempool_get(adb->ahmp);
-       if (h == NULL) {
-               return (NULL);
-       }
+       h = isc_mem_get(adb->mctx, sizeof(*h));
+       isc_refcount_increment0(&adb->ahrefcnt);
 
        /*
         * Public members.
@@ -2003,10 +1975,7 @@ static inline dns_adbfetch_t *
 new_adbfetch(dns_adb_t *adb) {
        dns_adbfetch_t *f;
 
-       f = isc_mempool_get(adb->afmp);
-       if (f == NULL) {
-               return (NULL);
-       }
+       f = isc_mem_get(adb->mctx, sizeof(*f));
 
        f->magic = 0;
        f->fetch = NULL;
@@ -2032,7 +2001,7 @@ free_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetch) {
                dns_rdataset_disassociate(&f->rdataset);
        }
 
-       isc_mempool_put(adb->afmp, f);
+       isc_mem_put(adb->mctx, f, sizeof(*f));
 }
 
 static inline bool
@@ -2052,7 +2021,9 @@ free_adbfind(dns_adb_t *adb, dns_adbfind_t **findp) {
        find->magic = 0;
 
        isc_mutex_destroy(&find->lock);
-       isc_mempool_put(adb->ahmp, find);
+
+       isc_refcount_decrement(&adb->ahrefcnt);
+       isc_mem_put(adb->mctx, find, sizeof(*find));
        return (dec_adb_irefcnt(adb));
 }
 
@@ -2065,10 +2036,7 @@ static inline dns_adbaddrinfo_t *
 new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) {
        dns_adbaddrinfo_t *ai;
 
-       ai = isc_mempool_get(adb->aimp);
-       if (ai == NULL) {
-               return (NULL);
-       }
+       ai = isc_mem_get(adb->mctx, sizeof(*ai));
 
        ai->magic = DNS_ADBADDRINFO_MAGIC;
        ai->sockaddr = entry->sockaddr;
@@ -2095,7 +2063,7 @@ free_adbaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **ainfo) {
 
        ai->magic = 0;
 
-       isc_mempool_put(adb->aimp, ai);
+       isc_mem_put(adb->mctx, ai, sizeof(*ai));
 }
 
 /*
@@ -2549,14 +2517,6 @@ destroy(dns_adb_t *adb) {
                isc_task_detach(&adb->excl);
        }
 
-       isc_mempool_destroy(&adb->nmp);
-       isc_mempool_destroy(&adb->nhmp);
-       isc_mempool_destroy(&adb->limp);
-       isc_mempool_destroy(&adb->emp);
-       isc_mempool_destroy(&adb->ahmp);
-       isc_mempool_destroy(&adb->aimp);
-       isc_mempool_destroy(&adb->afmp);
-
        isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
        isc_mem_put(adb->mctx, adb->entries,
                    sizeof(*adb->entries) * adb->nentries);
@@ -2582,7 +2542,6 @@ destroy(dns_adb_t *adb) {
 
        isc_mutex_destroy(&adb->reflock);
        isc_mutex_destroy(&adb->lock);
-       isc_mutex_destroy(&adb->mplock);
        isc_mutex_destroy(&adb->overmemlock);
        isc_mutex_destroy(&adb->entriescntlock);
        isc_mutex_destroy(&adb->namescntlock);
@@ -2618,13 +2577,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
        adb->magic = 0;
        adb->erefcnt = 1;
        adb->irefcnt = 0;
-       adb->nmp = NULL;
-       adb->nhmp = NULL;
-       adb->limp = NULL;
-       adb->emp = NULL;
-       adb->ahmp = NULL;
-       adb->aimp = NULL;
-       adb->afmp = NULL;
        adb->task = NULL;
        adb->excl = NULL;
        adb->mctx = NULL;
@@ -2680,7 +2632,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
        isc_mem_attach(mem, &adb->mctx);
 
        isc_mutex_init(&adb->lock);
-       isc_mutex_init(&adb->mplock);
        isc_mutex_init(&adb->reflock);
        isc_mutex_init(&adb->overmemlock);
        isc_mutex_init(&adb->entriescntlock);
@@ -2690,10 +2641,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
        do {                                                                   \
                (adb)->el = isc_mem_get((adb)->mctx,                           \
                                        sizeof(*(adb)->el) * (adb)->nentries); \
-               if ((adb)->el == NULL) {                                       \
-                       result = ISC_R_NOMEMORY;                               \
-                       goto fail1;                                            \
-               }                                                              \
        } while (0)
        ALLOCENTRY(adb, entries);
        ALLOCENTRY(adb, deadentries);
@@ -2706,10 +2653,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
        do {                                                                 \
                (adb)->el = isc_mem_get((adb)->mctx,                         \
                                        sizeof(*(adb)->el) * (adb)->nnames); \
-               if ((adb)->el == NULL) {                                     \
-                       result = ISC_R_NOMEMORY;                             \
-                       goto fail1;                                          \
-               }                                                            \
        } while (0)
        ALLOCNAME(adb, names);
        ALLOCNAME(adb, deadnames);
@@ -2740,27 +2683,8 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
        }
        isc_mutexblock_init(adb->entrylocks, adb->nentries);
 
-       /*
-        * Memory pools
-        */
-#define MPINIT(t, p, n)                                       \
-       do {                                                  \
-               isc_mempool_create(mem, sizeof(t), &(p));     \
-               isc_mempool_setfreemax((p), FREE_ITEMS);      \
-               isc_mempool_setfillcount((p), FILL_COUNT);    \
-               isc_mempool_setname((p), n);                  \
-               isc_mempool_associatelock((p), &adb->mplock); \
-       } while (0)
-
-       MPINIT(dns_adbname_t, adb->nmp, "adbname");
-       MPINIT(dns_adbnamehook_t, adb->nhmp, "adbnamehook");
-       MPINIT(dns_adblameinfo_t, adb->limp, "adblameinfo");
-       MPINIT(dns_adbentry_t, adb->emp, "adbentry");
-       MPINIT(dns_adbfind_t, adb->ahmp, "adbfind");
-       MPINIT(dns_adbaddrinfo_t, adb->aimp, "adbaddrinfo");
-       MPINIT(dns_adbfetch_t, adb->afmp, "adbfetch");
-
-#undef MPINIT
+       isc_refcount_init(&adb->ahrefcnt, 0);
+       isc_refcount_init(&adb->nhrefcnt, 0);
 
        /*
         * Allocate an internal task.
@@ -2796,7 +2720,6 @@ fail2:
        isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
        isc_mutexblock_destroy(adb->namelocks, adb->nnames);
 
-fail1: /* clean up only allocated memory */
        if (adb->entries != NULL) {
                isc_mem_put(adb->mctx, adb->entries,
                            sizeof(*adb->entries) * adb->nentries);
@@ -2837,33 +2760,11 @@ fail1: /* clean up only allocated memory */
                isc_mem_put(adb->mctx, adb->name_refcnt,
                            sizeof(*adb->name_refcnt) * adb->nnames);
        }
-       if (adb->nmp != NULL) {
-               isc_mempool_destroy(&adb->nmp);
-       }
-       if (adb->nhmp != NULL) {
-               isc_mempool_destroy(&adb->nhmp);
-       }
-       if (adb->limp != NULL) {
-               isc_mempool_destroy(&adb->limp);
-       }
-       if (adb->emp != NULL) {
-               isc_mempool_destroy(&adb->emp);
-       }
-       if (adb->ahmp != NULL) {
-               isc_mempool_destroy(&adb->ahmp);
-       }
-       if (adb->aimp != NULL) {
-               isc_mempool_destroy(&adb->aimp);
-       }
-       if (adb->afmp != NULL) {
-               isc_mempool_destroy(&adb->afmp);
-       }
 
        isc_mutex_destroy(&adb->namescntlock);
        isc_mutex_destroy(&adb->entriescntlock);
        isc_mutex_destroy(&adb->overmemlock);
        isc_mutex_destroy(&adb->reflock);
-       isc_mutex_destroy(&adb->mplock);
        isc_mutex_destroy(&adb->lock);
        if (adb->excl != NULL) {
                isc_task_detach(&adb->excl);
@@ -2928,7 +2829,7 @@ dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
        zeroirefcnt = (adb->irefcnt == 0);
 
        if (adb->shutting_down && zeroirefcnt &&
-           isc_mempool_getallocated(adb->ahmp) == 0)
+           isc_refcount_current(&adb->ahrefcnt) == 0)
        {
                /*
                 * We're already shutdown.  Send the event.
@@ -3534,9 +3435,11 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) {
        fprintf(f, "; [plain success/timeout]\n;\n");
        if (debug) {
                LOCK(&adb->reflock);
-               fprintf(f, "; addr %p, erefcnt %u, irefcnt %u, finds out %u\n",
+               fprintf(f,
+                       "; addr %p, erefcnt %u, irefcnt %u, finds out "
+                       "%" PRIuFAST32 "\n",
                        adb, adb->erefcnt, adb->irefcnt,
-                       isc_mempool_getallocated(adb->nhmp));
+                       isc_refcount_current(&adb->nhrefcnt));
                UNLOCK(&adb->reflock);
        }
 
index bab7cd3a68777bb3912c2231e5fb82adbde95630..b986f07a4ddfab13b6d626e4e45e6639724b283b 100644 (file)
@@ -76,17 +76,7 @@ struct dns_dispatchmgr {
        unsigned int buffersize; /*%< size of each buffer */
        unsigned int maxbuffers; /*%< max buffers */
 
-       /* Locked internally. */
-       isc_mutex_t depool_lock;
-       isc_mempool_t *depool; /*%< pool for dispatch events */
-       isc_mutex_t rpool_lock;
-       isc_mempool_t *rpool; /*%< pool for replies */
-       isc_mutex_t dpool_lock;
-       isc_mempool_t *dpool; /*%< dispatch allocations */
-       isc_mutex_t bpool_lock;
-       isc_mempool_t *bpool; /*%< pool for buffers */
-       isc_mutex_t spool_lock;
-       isc_mempool_t *spool; /*%< pool for dispsocks */
+       isc_refcount_t irefs;
 
        /*%
         * Locked by qid->lock if qid exists; otherwise, can be used without
@@ -208,8 +198,7 @@ struct dns_dispatch {
        unsigned int maxrequests; /*%< max requests */
        isc_event_t *ctlevent;
 
-       isc_mutex_t sepool_lock;
-       isc_mempool_t *sepool; /*%< pool for socket events */
+       isc_mem_t *sepool; /*%< pool for socket events */
 
        /*% Locked by mgr->lock. */
        ISC_LINK(dns_dispatch_t) link;
@@ -234,7 +223,6 @@ struct dns_dispatch {
        dns_tcpmsg_t tcpmsg;     /*%< for tcp streams */
        dns_qid_t *qid;
        dispportlist_t *port_table; /*%< hold ports 'owned' by us */
-       isc_mempool_t *portpool;    /*%< port table entries  */
 };
 
 #define QID_MAGIC    ISC_MAGIC('Q', 'i', 'd', ' ')
@@ -549,8 +537,7 @@ destroy_disp(isc_task_t *task, isc_event_t *event) {
                     disp->socket, disp->task[0]); /* XXXX */
 
        if (disp->sepool != NULL) {
-               isc_mempool_destroy(&disp->sepool);
-               isc_mutex_destroy(&disp->sepool_lock);
+               isc_mem_destroy(&disp->sepool);
        }
 
        if (disp->socket != NULL) {
@@ -603,10 +590,7 @@ new_portentry(dns_dispatch_t *disp, in_port_t port) {
 
        REQUIRE(disp->port_table != NULL);
 
-       portentry = isc_mempool_get(disp->portpool);
-       if (portentry == NULL) {
-               return (portentry);
-       }
+       portentry = isc_mem_get(disp->mgr->mctx, sizeof(*portentry));
 
        portentry->port = port;
        isc_refcount_init(&portentry->refs, 1);
@@ -635,7 +619,7 @@ deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
                ISC_LIST_UNLINK(disp->port_table[portentry->port %
                                                 DNS_DISPATCH_PORTTABLESIZE],
                                portentry, link);
-               isc_mempool_put(disp->portpool, portentry);
+               isc_mem_put(disp->mgr->mctx, portentry, sizeof(*portentry));
        }
 }
 
@@ -705,10 +689,7 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest,
                sock = dispsock->socket;
                dispsock->socket = NULL;
        } else {
-               dispsock = isc_mempool_get(mgr->spool);
-               if (dispsock == NULL) {
-                       return (ISC_R_NOMEMORY);
-               }
+               dispsock = isc_mem_get(mgr->mctx, sizeof(*dispsock));
 
                disp->nsockets++;
                dispsock->socket = NULL;
@@ -834,7 +815,7 @@ destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) {
        if (dispsock->task != NULL) {
                isc_task_detach(&dispsock->task);
        }
-       isc_mempool_put(disp->mgr->spool, dispsock);
+       isc_mem_put(disp->mgr->mctx, dispsock, sizeof(*dispsock));
 }
 
 /*%
@@ -913,7 +894,7 @@ entry_search(dns_qid_t *qid, const isc_sockaddr_t *dest, dns_messageid_t id,
 
 static void
 free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len) {
-       isc_mempool_t *bpool;
+       unsigned int buffersize;
        INSIST(buf != NULL && len != 0);
 
        switch (disp->socktype) {
@@ -927,9 +908,9 @@ free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len) {
                INSIST(disp->mgr->buffers > 0);
                INSIST(len == disp->mgr->buffersize);
                disp->mgr->buffers--;
-               bpool = disp->mgr->bpool;
+               buffersize = disp->mgr->buffersize;
                UNLOCK(&disp->mgr->buffer_lock);
-               isc_mempool_put(bpool, buf);
+               isc_mem_put(disp->mgr->mctx, buf, buffersize);
                break;
        default:
                INSIST(0);
@@ -939,34 +920,25 @@ free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len) {
 
 static void *
 allocate_udp_buffer(dns_dispatch_t *disp) {
-       isc_mempool_t *bpool;
-       void *temp;
+       unsigned int buffersize;
 
        LOCK(&disp->mgr->buffer_lock);
        if (disp->mgr->buffers >= disp->mgr->maxbuffers) {
                UNLOCK(&disp->mgr->buffer_lock);
                return (NULL);
        }
-       bpool = disp->mgr->bpool;
+       buffersize = disp->mgr->buffersize;
        disp->mgr->buffers++;
        UNLOCK(&disp->mgr->buffer_lock);
 
-       temp = isc_mempool_get(bpool);
-
-       if (temp == NULL) {
-               LOCK(&disp->mgr->buffer_lock);
-               disp->mgr->buffers--;
-               UNLOCK(&disp->mgr->buffer_lock);
-       }
-
-       return (temp);
+       return (isc_mem_get(disp->mgr->mctx, buffersize));
 }
 
 static inline void
 free_sevent(isc_event_t *ev) {
-       isc_mempool_t *pool = ev->ev_destroy_arg;
+       isc_mem_t *pool = ev->ev_destroy_arg;
        isc_socketevent_t *sev = (isc_socketevent_t *)ev;
-       isc_mempool_put(pool, sev);
+       isc_mem_put(pool, sev, sizeof(*sev));
 }
 
 static inline isc_socketevent_t *
@@ -975,10 +947,7 @@ allocate_sevent(dns_dispatch_t *disp, isc_socket_t *sock, isc_eventtype_t type,
        isc_socketevent_t *ev;
        void *deconst_arg;
 
-       ev = isc_mempool_get(disp->sepool);
-       if (ev == NULL) {
-               return (NULL);
-       }
+       ev = isc_mem_get(disp->sepool, sizeof(*ev));
        DE_CONST(arg, deconst_arg);
        ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, type, action, deconst_arg,
                       sock, free_sevent, disp->sepool);
@@ -1001,17 +970,16 @@ free_devent(dns_dispatch_t *disp, dns_dispatchevent_t *ev) {
                return;
        }
 
-       isc_mempool_put(disp->mgr->depool, ev);
+       isc_refcount_decrement(&disp->mgr->irefs);
+       isc_mem_put(disp->mgr->mctx, ev, sizeof(*ev));
 }
 
 static inline dns_dispatchevent_t *
 allocate_devent(dns_dispatch_t *disp) {
        dns_dispatchevent_t *ev;
 
-       ev = isc_mempool_get(disp->mgr->depool);
-       if (ev == NULL) {
-               return (NULL);
-       }
+       ev = isc_mem_get(disp->mgr->mctx, sizeof(*ev));
+       isc_refcount_increment0(&disp->mgr->irefs);
        ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, 0, NULL, NULL, NULL, NULL,
                       NULL);
 
@@ -1629,25 +1597,15 @@ startrecv(dns_dispatch_t *disp, dispsocket_t *dispsock) {
 static bool
 destroy_mgr_ok(dns_dispatchmgr_t *mgr) {
        mgr_log(mgr, LVL(90),
-               "destroy_mgr_ok: shuttingdown=%d, listnonempty=%d, "
-               "depool=%d, rpool=%d, dpool=%d",
-               MGR_IS_SHUTTINGDOWN(mgr), !ISC_LIST_EMPTY(mgr->list),
-               isc_mempool_getallocated(mgr->depool),
-               isc_mempool_getallocated(mgr->rpool),
-               isc_mempool_getallocated(mgr->dpool));
+               "destroy_mgr_ok: shuttingdown=%d, listnonempty=%d, ",
+               MGR_IS_SHUTTINGDOWN(mgr), !ISC_LIST_EMPTY(mgr->list));
        if (!MGR_IS_SHUTTINGDOWN(mgr)) {
                return (false);
        }
        if (!ISC_LIST_EMPTY(mgr->list)) {
                return (false);
        }
-       if (isc_mempool_getallocated(mgr->depool) != 0) {
-               return (false);
-       }
-       if (isc_mempool_getallocated(mgr->rpool) != 0) {
-               return (false);
-       }
-       if (isc_mempool_getallocated(mgr->dpool) != 0) {
+       if (isc_refcount_current(&mgr->irefs) != 0) {
                return (false);
        }
 
@@ -1668,22 +1626,6 @@ destroy_mgr(dns_dispatchmgr_t **mgrp) {
        isc_mutex_destroy(&mgr->lock);
        mgr->state = 0;
 
-       isc_mempool_destroy(&mgr->depool);
-       isc_mempool_destroy(&mgr->rpool);
-       isc_mempool_destroy(&mgr->dpool);
-       if (mgr->bpool != NULL) {
-               isc_mempool_destroy(&mgr->bpool);
-       }
-       if (mgr->spool != NULL) {
-               isc_mempool_destroy(&mgr->spool);
-       }
-
-       isc_mutex_destroy(&mgr->spool_lock);
-       isc_mutex_destroy(&mgr->bpool_lock);
-       isc_mutex_destroy(&mgr->dpool_lock);
-       isc_mutex_destroy(&mgr->rpool_lock);
-       isc_mutex_destroy(&mgr->depool_lock);
-
        if (mgr->qid != NULL) {
                qid_destroy(mgr->mctx, &mgr->qid);
        }
@@ -1793,61 +1735,17 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) {
        REQUIRE(mgrp != NULL && *mgrp == NULL);
 
        mgr = isc_mem_get(mctx, sizeof(dns_dispatchmgr_t));
+       *mgr = (dns_dispatchmgr_t){ 0 };
 
-       mgr->mctx = NULL;
        isc_mem_attach(mctx, &mgr->mctx);
 
-       mgr->blackhole = NULL;
-       mgr->stats = NULL;
-
        isc_mutex_init(&mgr->lock);
        isc_mutex_init(&mgr->buffer_lock);
-       isc_mutex_init(&mgr->depool_lock);
-       isc_mutex_init(&mgr->rpool_lock);
-       isc_mutex_init(&mgr->dpool_lock);
-       isc_mutex_init(&mgr->bpool_lock);
-       isc_mutex_init(&mgr->spool_lock);
-
-       mgr->depool = NULL;
-       isc_mempool_create(mgr->mctx, sizeof(dns_dispatchevent_t),
-                          &mgr->depool);
-
-       mgr->rpool = NULL;
-       isc_mempool_create(mgr->mctx, sizeof(dns_dispentry_t), &mgr->rpool);
-
-       mgr->dpool = NULL;
-       isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t), &mgr->dpool);
-
-       isc_mempool_setname(mgr->depool, "dispmgr_depool");
-       isc_mempool_setmaxalloc(mgr->depool, 32768);
-       isc_mempool_setfreemax(mgr->depool, 32768);
-       isc_mempool_associatelock(mgr->depool, &mgr->depool_lock);
-       isc_mempool_setfillcount(mgr->depool, 32);
-
-       isc_mempool_setname(mgr->rpool, "dispmgr_rpool");
-       isc_mempool_setmaxalloc(mgr->rpool, 32768);
-       isc_mempool_setfreemax(mgr->rpool, 32768);
-       isc_mempool_associatelock(mgr->rpool, &mgr->rpool_lock);
-       isc_mempool_setfillcount(mgr->rpool, 32);
-
-       isc_mempool_setname(mgr->dpool, "dispmgr_dpool");
-       isc_mempool_setmaxalloc(mgr->dpool, 32768);
-       isc_mempool_setfreemax(mgr->dpool, 32768);
-       isc_mempool_associatelock(mgr->dpool, &mgr->dpool_lock);
-       isc_mempool_setfillcount(mgr->dpool, 32);
-
-       mgr->buffers = 0;
-       mgr->buffersize = 0;
-       mgr->maxbuffers = 0;
-       mgr->bpool = NULL;
-       mgr->spool = NULL;
-       mgr->qid = NULL;
-       mgr->state = 0;
+
+       isc_refcount_init(&mgr->irefs, 0);
+
        ISC_LIST_INIT(mgr->list);
-       mgr->v4ports = NULL;
-       mgr->v6ports = NULL;
-       mgr->nv4ports = 0;
-       mgr->nv6ports = 0;
+
        mgr->magic = DNS_DISPATCHMGR_MAGIC;
 
        result = create_default_portset(mctx, &v4portset);
@@ -1872,14 +1770,6 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) {
        return (ISC_R_SUCCESS);
 
 kill_dpool:
-       isc_mempool_destroy(&mgr->dpool);
-       isc_mempool_destroy(&mgr->rpool);
-       isc_mempool_destroy(&mgr->depool);
-       isc_mutex_destroy(&mgr->spool_lock);
-       isc_mutex_destroy(&mgr->bpool_lock);
-       isc_mutex_destroy(&mgr->dpool_lock);
-       isc_mutex_destroy(&mgr->rpool_lock);
-       isc_mutex_destroy(&mgr->depool_lock);
        isc_mutex_destroy(&mgr->buffer_lock);
        isc_mutex_destroy(&mgr->lock);
        isc_mem_putanddetach(&mctx, mgr, sizeof(dns_dispatchmgr_t));
@@ -1983,6 +1873,7 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize,
        REQUIRE(maxbuffers > 0);
        REQUIRE(buckets < 2097169); /* next prime > 65536 * 32 */
        REQUIRE(increment > buckets);
+       UNUSED(maxrequests);
 
        /*
         * Keep some number of items around.  This should be a config
@@ -2003,48 +1894,15 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize,
 
        LOCK(&mgr->buffer_lock);
 
-       /* Create or adjust buffer pool */
-       if (mgr->bpool != NULL) {
-               /*
-                * We only increase the maxbuffers to avoid accidental buffer
-                * shortage.  Ideally we'd separate the manager-wide maximum
-                * from per-dispatch limits and respect the latter within the
-                * global limit.  But at this moment that's deemed to be
-                * overkilling and isn't worth additional implementation
-                * complexity.
-                */
-               if (maxbuffers > mgr->maxbuffers) {
-                       isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
-                       isc_mempool_setfreemax(mgr->bpool, maxbuffers);
-                       mgr->maxbuffers = maxbuffers;
-               }
-       } else {
-               isc_mempool_create(mgr->mctx, buffersize, &mgr->bpool);
-               isc_mempool_setname(mgr->bpool, "dispmgr_bpool");
-               isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
-               isc_mempool_setfreemax(mgr->bpool, maxbuffers);
-               isc_mempool_associatelock(mgr->bpool, &mgr->bpool_lock);
-               isc_mempool_setfillcount(mgr->bpool, 32);
+       if (maxbuffers > mgr->maxbuffers) {
+               mgr->maxbuffers = maxbuffers;
        }
 
        /* Create or adjust socket pool */
-       if (mgr->spool != NULL) {
-               if (maxrequests < DNS_DISPATCH_POOLSOCKS * 2) {
-                       isc_mempool_setmaxalloc(mgr->spool,
-                                               DNS_DISPATCH_POOLSOCKS * 2);
-                       isc_mempool_setfreemax(mgr->spool,
-                                              DNS_DISPATCH_POOLSOCKS * 2);
-               }
+       if (mgr->qid != NULL) {
                UNLOCK(&mgr->buffer_lock);
                return (ISC_R_SUCCESS);
        }
-       isc_mempool_create(mgr->mctx, sizeof(dispsocket_t), &mgr->spool);
-
-       isc_mempool_setname(mgr->spool, "dispmgr_spool");
-       isc_mempool_setmaxalloc(mgr->spool, maxrequests);
-       isc_mempool_setfreemax(mgr->spool, maxrequests);
-       isc_mempool_associatelock(mgr->spool, &mgr->spool_lock);
-       isc_mempool_setfillcount(mgr->spool, 32);
 
        result = qid_allocate(mgr, buckets, increment, &mgr->qid, true);
        if (result != ISC_R_SUCCESS) {
@@ -2057,10 +1915,6 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize,
        return (ISC_R_SUCCESS);
 
 cleanup:
-       isc_mempool_destroy(&mgr->bpool);
-       if (mgr->spool != NULL) {
-               isc_mempool_destroy(&mgr->spool);
-       }
        UNLOCK(&mgr->buffer_lock);
        return (result);
 }
@@ -2326,10 +2180,8 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
         * the options that are controlled by tcp vs. udp, etc.
         */
 
-       disp = isc_mempool_get(mgr->dpool);
-       if (disp == NULL) {
-               return (ISC_R_NOMEMORY);
-       }
+       disp = isc_mem_get(mgr->mctx, sizeof(*disp));
+       isc_refcount_increment0(&mgr->irefs);
 
        disp->magic = 0;
        disp->mgr = mgr;
@@ -2353,7 +2205,6 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
        ISC_LIST_INIT(disp->inactivesockets);
        disp->nsockets = 0;
        disp->port_table = NULL;
-       disp->portpool = NULL;
        disp->dscp = -1;
 
        isc_mutex_init(&disp->lock);
@@ -2374,7 +2225,8 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
         */
 kill_lock:
        isc_mutex_destroy(&disp->lock);
-       isc_mempool_put(mgr->dpool, disp);
+       isc_refcount_decrement(&mgr->irefs);
+       isc_mem_put(mgr->mctx, disp, sizeof(*disp));
 
        return (result);
 }
@@ -2405,7 +2257,8 @@ dispatch_free(dns_dispatch_t **dispp) {
        INSIST(ISC_LIST_EMPTY(disp->activesockets));
        INSIST(ISC_LIST_EMPTY(disp->inactivesockets));
 
-       isc_mempool_put(mgr->depool, disp->failsafe_ev);
+       isc_refcount_decrement(&mgr->irefs);
+       isc_mem_put(mgr->mctx, disp->failsafe_ev, sizeof(*disp->failsafe_ev));
        disp->failsafe_ev = NULL;
 
        if (disp->qid != NULL) {
@@ -2421,14 +2274,11 @@ dispatch_free(dns_dispatch_t **dispp) {
                                    DNS_DISPATCH_PORTTABLESIZE);
        }
 
-       if (disp->portpool != NULL) {
-               isc_mempool_destroy(&disp->portpool);
-       }
-
        disp->mgr = NULL;
        isc_mutex_destroy(&disp->lock);
        disp->magic = 0;
-       isc_mempool_put(mgr->dpool, disp);
+       isc_refcount_decrement(&mgr->irefs);
+       isc_mem_put(mgr->mctx, disp, sizeof(*disp));
 }
 
 isc_result_t
@@ -2904,11 +2754,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
                for (i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++) {
                        ISC_LIST_INIT(disp->port_table[i]);
                }
-
-               isc_mempool_create(mgr->mctx, sizeof(dispportentry_t),
-                                  &disp->portpool);
-               isc_mempool_setname(disp->portpool, "disp_portpool");
-               isc_mempool_setfreemax(disp->portpool, 128);
        }
        disp->socket = sock;
        disp->local = *localaddr;
@@ -2936,15 +2781,8 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
                                   destroy_disp, disp, sizeof(isc_event_t));
 
        disp->sepool = NULL;
-       isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t), &disp->sepool);
-
-       isc_mutex_init(&disp->sepool_lock);
-
-       isc_mempool_setname(disp->sepool, "disp_sepool");
-       isc_mempool_setmaxalloc(disp->sepool, 32768);
-       isc_mempool_setfreemax(disp->sepool, 32768);
-       isc_mempool_associatelock(disp->sepool, &disp->sepool_lock);
-       isc_mempool_setfillcount(disp->sepool, 16);
+       isc_mem_create(&disp->sepool);
+       isc_mem_setname(disp->sepool, "disp_sepool", NULL);
 
        attributes &= ~DNS_DISPATCHATTR_TCP;
        attributes |= DNS_DISPATCHATTR_UDP;
@@ -3160,14 +2998,8 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options,
                return (ISC_R_NOMORE);
        }
 
-       res = isc_mempool_get(disp->mgr->rpool);
-       if (res == NULL) {
-               if (dispsocket != NULL) {
-                       destroy_dispsocket(disp, &dispsocket);
-               }
-               UNLOCK(&disp->lock);
-               return (ISC_R_NOMEMORY);
-       }
+       res = isc_mem_get(disp->mgr->mctx, sizeof(*res));
+       isc_refcount_increment0(&disp->mgr->irefs);
 
        disp->refcount++;
        disp->requests++;
@@ -3222,7 +3054,8 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options,
 
                        UNLOCK(&disp->lock);
                        isc_task_detach(&res->task);
-                       isc_mempool_put(disp->mgr->rpool, res);
+                       isc_refcount_decrement(&disp->mgr->irefs);
+                       isc_mem_put(disp->mgr->mctx, res, sizeof(*res));
                        return (result);
                }
        }
@@ -3410,7 +3243,8 @@ dns_dispatch_removeresponse(dns_dispentry_t **resp,
                ev = ISC_LIST_HEAD(res->items);
        }
        res->magic = 0;
-       isc_mempool_put(disp->mgr->rpool, res);
+       isc_refcount_decrement(&disp->mgr->irefs);
+       isc_mem_put(disp->mgr->mctx, res, sizeof(*res));
        if (disp->shutting_down == 1) {
                do_cancel(disp);
        } else {
index b4299d512ea2565937a3774195a9c1794c2b38a1..6924ee7723db5a2fcde886f5fe098b3036e6a675 100644 (file)
@@ -629,12 +629,6 @@ struct isc_nm {
 
        isc_stats_t *stats;
 
-       isc_mempool_t *reqpool;
-       isc_mutex_t reqlock;
-
-       isc_mempool_t *evpool;
-       isc_mutex_t evlock;
-
        uint_fast32_t workers_running;
        atomic_uint_fast32_t workers_paused;
        atomic_uint_fast32_t maxudp;
index e81ad4673e72231452855a5cfd8198e22ee0bba7..7b85f174b2a38815204c7ff282d7c6c2c288ad52 100644 (file)
@@ -319,21 +319,6 @@ isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) {
        atomic_init(&mgr->keepalive, 30000);
        atomic_init(&mgr->advertised, 30000);
 
-       isc_mutex_init(&mgr->reqlock);
-       isc_mempool_create(mgr->mctx, sizeof(isc__nm_uvreq_t), &mgr->reqpool);
-       isc_mempool_setname(mgr->reqpool, "nm_reqpool");
-       isc_mempool_setfreemax(mgr->reqpool, 4096);
-       isc_mempool_associatelock(mgr->reqpool, &mgr->reqlock);
-       isc_mempool_setfillcount(mgr->reqpool, 32);
-
-       isc_mutex_init(&mgr->evlock);
-       isc_mempool_create(mgr->mctx, sizeof(isc__netievent_storage_t),
-                          &mgr->evpool);
-       isc_mempool_setname(mgr->evpool, "nm_evpool");
-       isc_mempool_setfreemax(mgr->evpool, 4096);
-       isc_mempool_associatelock(mgr->evpool, &mgr->evlock);
-       isc_mempool_setfillcount(mgr->evpool, 32);
-
        isc_barrier_init(&mgr->pausing, workers);
        isc_barrier_init(&mgr->resuming, workers);
 
@@ -415,14 +400,14 @@ nm_destroy(isc_nm_t **mgr0) {
 
                /* Empty the async event queues */
                while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
-                       isc_mempool_put(mgr->evpool, ievent);
+                       isc_mem_put(mgr->mctx, ievent, sizeof(*ievent));
                }
 
                INSIST(DEQUEUE_PRIVILEGED_NETIEVENT(worker) == NULL);
                INSIST(DEQUEUE_TASK_NETIEVENT(worker) == NULL);
 
                while ((ievent = DEQUEUE_PRIORITY_NETIEVENT(worker)) != NULL) {
-                       isc_mempool_put(mgr->evpool, ievent);
+                       isc_mem_put(mgr->mctx, ievent, sizeof(*ievent));
                }
                isc_condition_destroy(&worker->cond_prio);
                isc_mutex_destroy(&worker->lock);
@@ -452,12 +437,6 @@ nm_destroy(isc_nm_t **mgr0) {
        isc_condition_destroy(&mgr->wkpausecond);
        isc_mutex_destroy(&mgr->lock);
 
-       isc_mempool_destroy(&mgr->evpool);
-       isc_mutex_destroy(&mgr->evlock);
-
-       isc_mempool_destroy(&mgr->reqpool);
-       isc_mutex_destroy(&mgr->reqlock);
-
        isc_mem_put(mgr->mctx, mgr->workers,
                    mgr->nworkers * sizeof(isc__networker_t));
        isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(*mgr));
@@ -1046,7 +1025,8 @@ process_queue(isc__networker_t *worker, netievent_type_t type) {
 
 void *
 isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type) {
-       isc__netievent_storage_t *event = isc_mempool_get(mgr->evpool);
+       isc__netievent_storage_t *event = isc_mem_get(mgr->mctx,
+                                                     sizeof(*event));
 
        *event = (isc__netievent_storage_t){ .ni.type = type };
        return (event);
@@ -1054,7 +1034,7 @@ isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type) {
 
 void
 isc__nm_put_netievent(isc_nm_t *mgr, void *ievent) {
-       isc_mempool_put(mgr->evpool, ievent);
+       isc_mem_put(mgr->mctx, ievent, sizeof(isc__netievent_storage_t));
 }
 
 NETIEVENT_SOCKET_DEF(tcpclose);
@@ -1260,7 +1240,7 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
        isc_astack_destroy(sock->inactivehandles);
 
        while ((uvreq = isc_astack_pop(sock->inactivereqs)) != NULL) {
-               isc_mempool_put(sock->mgr->reqpool, uvreq);
+               isc_mem_put(sock->mgr->mctx, uvreq, sizeof(*uvreq));
        }
 
        isc_astack_destroy(sock->inactivereqs);
@@ -2379,7 +2359,7 @@ isc___nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock FLARG) {
        }
 
        if (req == NULL) {
-               req = isc_mempool_get(mgr->reqpool);
+               req = isc_mem_get(mgr->mctx, sizeof(*req));
        }
 
        *req = (isc__nm_uvreq_t){ .magic = 0 };
@@ -2415,7 +2395,7 @@ isc___nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock FLARG) {
 
        if (!isc__nmsocket_active(sock) ||
            !isc_astack_trypush(sock->inactivereqs, req)) {
-               isc_mempool_put(sock->mgr->reqpool, req);
+               isc_mem_put(sock->mgr->mctx, req, sizeof(*req));
        }
 
        if (handle != NULL) {