]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
WIP: Remove freemax from mempool
authorOndřej Surý <ondrej@sury.org>
Thu, 25 Feb 2021 14:40:24 +0000 (15:40 +0100)
committerOndřej Surý <ondrej@sury.org>
Wed, 3 Mar 2021 14:32:01 +0000 (15:32 +0100)
bin/dig/dighost.c
bin/plugins/filter-aaaa.c
lib/dns/adb.c
lib/dns/dispatch.c
lib/dns/message.c
lib/isc/include/isc/mem.h
lib/isc/mem.c
lib/isc/netmgr/netmgr.c
lib/isc/tests/mem_test.c
lib/isc/win32/libisc.def.in

index 22f5097175d0146573b195b68a287d71a633dfde..1ac27d1702d4814ac4df5269ef29c770cd40a478 100644 (file)
@@ -1428,11 +1428,6 @@ setup_libs(void) {
 
        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_mutex_init(&lookup_lock);
 }
index 3b3e7f626e1d27f6ae084b310d9bab41d8d62e71..ee53cc198815e42609f1b7fac67bed632d61e596 100644 (file)
@@ -360,12 +360,6 @@ plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
        CHECK(isc_ht_init(&inst->ht, mctx, 16));
        isc_mutex_init(&inst->hlock);
 
-       /*
-        * 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_setfreemax(inst->datapool, UINT_MAX);
        isc_mutex_init(&inst->plock);
        isc_mempool_associatelock(inst->datapool, &inst->plock);
 
index ab8d293f70e853aebc8ebf893a04047ef16c1733..5e8fb278b7cad82b5cf95272ade000f631ef794c 100644 (file)
@@ -77,9 +77,6 @@
 #define ADB_STALE_MARGIN 1800
 #endif /* ifndef ADB_STALE_MARGIN */
 
-#define FREE_ITEMS 64 /*%< free count for memory pools */
-#define FILL_COUNT 16 /*%< fill count for memory pools */
-
 #define DNS_ADB_INVALIDBUCKET (-1) /*%< invalid bucket address */
 
 #define DNS_ADB_MINADBSIZE (1024U * 1024U) /*%< 1 Megabyte */
@@ -2715,7 +2712,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
 #define MPINIT(t, p, n)                                       \
        do {                                                  \
                isc_mempool_create(mem, sizeof(t), &(p));     \
-               isc_mempool_setfreemax((p), FREE_ITEMS);      \
                isc_mempool_setname((p), n);                  \
                isc_mempool_associatelock((p), &adb->mplock); \
        } while (0)
index b82580d9fa6ca3003181c5f84458a7fc1b532c7c..54d60781c814a8545166ee0238787d0bd1bc2424 100644 (file)
@@ -1808,15 +1808,12 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) {
        isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t), &mgr->dpool);
 
        isc_mempool_setname(mgr->depool, "dispmgr_depool");
-       isc_mempool_setfreemax(mgr->depool, 32768);
        isc_mempool_associatelock(mgr->depool, &mgr->depool_lock);
 
        isc_mempool_setname(mgr->rpool, "dispmgr_rpool");
-       isc_mempool_setfreemax(mgr->rpool, 32768);
        isc_mempool_associatelock(mgr->rpool, &mgr->rpool_lock);
 
        isc_mempool_setname(mgr->dpool, "dispmgr_dpool");
-       isc_mempool_setfreemax(mgr->dpool, 32768);
        isc_mempool_associatelock(mgr->dpool, &mgr->dpool_lock);
 
        mgr->buffers = 0;
@@ -1951,6 +1948,8 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize,
        REQUIRE(buckets < 2097169); /* next prime > 65536 * 32 */
        REQUIRE(increment > buckets);
 
+       UNUSED(maxrequests);
+
        /*
         * Keep some number of items around.  This should be a config
         * option.  For now, keep 8, but later keep at least two even
@@ -1981,29 +1980,22 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize,
                 * complexity.
                 */
                if (maxbuffers > mgr->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_setfreemax(mgr->bpool, maxbuffers);
                isc_mempool_associatelock(mgr->bpool, &mgr->bpool_lock);
        }
 
        /* Create or adjust socket pool */
        if (mgr->spool != NULL) {
-               if (maxrequests < DNS_DISPATCH_POOLSOCKS * 2) {
-                       isc_mempool_setfreemax(mgr->spool,
-                                              DNS_DISPATCH_POOLSOCKS * 2);
-               }
                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_setfreemax(mgr->spool, maxrequests);
        isc_mempool_associatelock(mgr->spool, &mgr->spool_lock);
 
        result = qid_allocate(mgr, buckets, increment, &mgr->qid, true);
@@ -2868,7 +2860,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
                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;
@@ -2901,7 +2892,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
        isc_mutex_init(&disp->sepool_lock);
 
        isc_mempool_setname(disp->sepool, "disp_sepool");
-       isc_mempool_setfreemax(disp->sepool, 32768);
        isc_mempool_associatelock(disp->sepool, &disp->sepool_lock);
 
        attributes &= ~DNS_DISPATCHATTR_TCP;
index 1d3b006acd738ee2e1c8e82d9e616064fcddc4a2..818274fc0506cff874bcd09f064903f8e1e9a55e 100644 (file)
@@ -750,11 +750,9 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) {
        ISC_LIST_INIT(m->freerdatalist);
 
        isc_mempool_create(m->mctx, sizeof(dns_name_t), &m->namepool);
-       isc_mempool_setfreemax(m->namepool, NAME_COUNT);
        isc_mempool_setname(m->namepool, "msg:names");
 
        isc_mempool_create(m->mctx, sizeof(dns_rdataset_t), &m->rdspool);
-       isc_mempool_setfreemax(m->rdspool, RDATASET_COUNT);
        isc_mempool_setname(m->rdspool, "msg:rdataset");
 
        dynbuf = NULL;
index 48d0dbda803b1cce89c0390e45a4f8d16b08a594..b70feed51febbd17e5ce68ff63a66395eb6218f7 100644 (file)
@@ -382,7 +382,6 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
  *\li  mpctxp != NULL and *mpctxp == NULL
  *
  * Defaults:
- *\li  freemax = 1
  *
  * Returns:
  *\li  #ISC_R_NOMEMORY         -- not enough memory to create pool
@@ -442,25 +441,10 @@ isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
  * the unlocked nature of pools these are potentially random values
  * unless the imposed externally provided locking protocols are followed.
  *
- * Also note that the quota limits will not always take immediate
- * effect.
- *
  * All functions require (in addition to other requirements):
  *     mpctx is a valid memory pool
  */
 
-unsigned int
-isc_mempool_getfreemax(isc_mempool_t *mpctx);
-/*%<
- * Returns the maximum allowed size of the free list.
- */
-
-void
-isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);
-/*%<
- * Sets the maximum allowed size of the free list.
- */
-
 unsigned int
 isc_mempool_getfreecount(isc_mempool_t *mpctx);
 /*%<
index b47b5578056578006579bb4e0f151f95a858e3d8..aebcf3422a37df5c1d113def9296478c183e57d5 100644 (file)
@@ -172,7 +172,6 @@ struct isc_mempool {
        size_t size;             /*%< size of each item on this pool */
        atomic_size_t allocated; /*%< # of items currently given out */
        atomic_size_t freecount; /*%< # of items on reserved list */
-       atomic_size_t freemax;   /*%< # of items allowed on free list */
        /*%< Stats only. */
        atomic_size_t gets; /*%< # of requests to this pool */
                            /*%< Debugging only. */
@@ -874,16 +873,15 @@ isc_mem_stats(isc_mem_t *ctx, FILE *out) {
        pool = ISC_LIST_HEAD(ctx->pools);
        if (pool != NULL) {
                fprintf(out, "[Pool statistics]\n");
-               fprintf(out, "%15s %10s %10s %10s %10s %10s %1s\n", "name",
-                       "size", "allocated", "freecount", "freemax",
+               fprintf(out, "%15s %10s %10s %10s %10s %1s\n", "name",
+                       "size", "allocated", "freecount",
                        "gets", "L");
        }
        while (pool != NULL) {
-               fprintf(out, "%15s %10zu %10zu %10zu %10zu %10zu %s\n",
+               fprintf(out, "%15s %10zu %10zu %10zu %10zu %s\n",
                        pool->name, pool->size,
                        atomic_load_relaxed(&pool->allocated),
                        atomic_load_relaxed(&pool->freecount),
-                       atomic_load_relaxed(&pool->freemax),
                        atomic_load_relaxed(&pool->gets),
                        (pool->lock == NULL ? "N" : "Y"));
                pool = ISC_LIST_NEXT(pool, link);
@@ -1203,7 +1201,6 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) {
 
        atomic_init(&mpctx->allocated, 0);
        atomic_init(&mpctx->freecount, 0);
-       atomic_init(&mpctx->freemax, 1);
 
        *mpctxp = (isc_mempool_t *)mpctx;
 
@@ -1322,20 +1319,21 @@ isc__mempool_get(isc_mempool_t *mpctx FLARG) {
        REQUIRE(VALID_MEMPOOL(mpctx));
 
        element *item;
-       unsigned int i;
 
        MPCTXLOCK(mpctx);
        if (ISC_UNLIKELY(mpctx->items == NULL)) {
                isc_mem_t *mctx = mpctx->mctx;
                item = mem_get(mctx, mpctx->size);
                mem_getstats(mctx, mpctx->size);
-               item->next = NULL;
        } else {
                item = mpctx->items;
+               mpctx->items = item->next;
        }
+       MPCTXUNLOCK(mpctx);
+
        REQUIRE(item != NULL);
 
-       mpctx->items = item->next;
+       item->next = NULL;
 
        INSIST(atomic_fetch_sub_release(&mpctx->freecount, 1) > 0);
        atomic_fetch_add_relaxed(&mpctx->gets, 1);
@@ -1343,9 +1341,6 @@ isc__mempool_get(isc_mempool_t *mpctx FLARG) {
 
        ADD_TRACE(mpctx->mctx, item, mpctx->size, file, line);
 
-out:
-       MPCTXUNLOCK(mpctx);
-
        return (item);
 }
 
@@ -1359,16 +1354,17 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) {
 
        isc_mem_t *mctx = mpctx->mctx;
        size_t freecount = atomic_load_acquire(&mpctx->freecount);
-       size_t freemax = atomic_load_acquire(&mpctx->freemax);
+       size_t allocated = atomic_fetch_sub_release(&mpctx->allocated, 1);
 
-       INSIST(atomic_fetch_sub_release(&mpctx->allocated, 1) > 0);
+       INSIST(allocated > 0);
 
        DELETE_TRACE(mctx, mem, mpctx->size, file, line);
 
        /*
-        * If our free list is full, return this to the mctx directly.
+        * If the number of freeitems is more than number of allocated items,
+        * return the item to the allocator.
         */
-       if (freecount >= freemax) {
+       if (freecount >= allocated) {
                mem_putstats(mctx, mem, mpctx->size);
                mem_put(mctx, mem, mpctx->size);
                return;
@@ -1393,20 +1389,6 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem FLARG) {
  * Quotas
  */
 
-void
-isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) {
-       REQUIRE(VALID_MEMPOOL(mpctx));
-
-       atomic_store_release(&mpctx->freemax, limit);
-}
-
-unsigned int
-isc_mempool_getfreemax(isc_mempool_t *mpctx) {
-       REQUIRE(VALID_MEMPOOL(mpctx));
-
-       return (atomic_load_acquire(&mpctx->freemax));
-}
-
 unsigned int
 isc_mempool_getfreecount(isc_mempool_t *mpctx) {
        REQUIRE(VALID_MEMPOOL(mpctx));
index d5bb613866018135d28a7626bd0af672a77d6c74..b26ead68fbaebd77719566cbdc7f2103af15676a 100644 (file)
@@ -242,14 +242,12 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers) {
        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_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);
 
        mgr->workers = isc_mem_get(mctx, workers * sizeof(isc__networker_t));
index 9e974b7db0e5385877bef6952928c4e17166cab4..b2863a9b5aa66868740391bc935ce24ca768b4ab 100644 (file)
@@ -58,11 +58,8 @@ _teardown(void **state) {
        return (0);
 }
 
-#define MP1_FREEMAX  10
 #define MP1_MAXALLOC 30
 
-#define MP2_FREEMAX 25
-
 /* general memory system tests */
 static void
 isc_mem_test(void **state) {
@@ -78,8 +75,6 @@ isc_mem_test(void **state) {
        isc_mempool_create(test_mctx, 24, &mp1);
        isc_mempool_create(test_mctx, 31, &mp2);
 
-       isc_mempool_setfreemax(mp1, MP1_FREEMAX);
-
        /*
         * Allocate MP1_MAXALLOC items from the pool.  This is our max.
         */
@@ -110,8 +105,6 @@ isc_mem_test(void **state) {
         * them, then allocate 50 more, etc.
         */
 
-       isc_mempool_setfreemax(mp2, 25);
-
        for (j = 0; j < 500000; j++) {
                for (i = 0; i < 50; i++) {
                        items2[i] = isc_mempool_get(mp2);
@@ -452,8 +445,6 @@ isc_mempool_benchmark(void **state) {
 
        isc_mempool_associatelock(mp, &mplock);
 
-       isc_mempool_setfreemax(mp, 32768);
-
        UNUSED(state);
 
        result = isc_time_now(&ts1);
index 92c5f1e1790e7b2a26bdb894f28e50f617d121c2..b4ac96c418d6d3bcd7aab56b70d3a686c48e0c2e 100644 (file)
@@ -395,8 +395,6 @@ isc_mempool_create
 isc_mempool_destroy
 isc_mempool_getallocated
 isc_mempool_getfreecount
-isc_mempool_getfreemax
-isc_mempool_setfreemax
 isc_mempool_setname
 isc_mutexblock_destroy
 isc_mutexblock_init