]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Don't use mem freelists for isc_mempools
authorOndřej Surý <ondrej@sury.org>
Tue, 14 Dec 2021 09:40:47 +0000 (10:40 +0100)
committerOndřej Surý <ondrej@sury.org>
Wed, 15 Dec 2021 12:29:19 +0000 (13:29 +0100)
Previously, with BIND 9 internal allocator, when isc_mempool_put() would
return memory to the allocator, it would not be freed, but it would be
returned to the "freelists" and the memory would not be released to the
operating system.

Change the isc_mempool_get() and isc_mempool_put() to avoid the internal
allocator (mem_getunlocked() and mem_putunlocked()).

lib/isc/mem.c

index e51b281458c311337b6bc471bd7f027305db0d48..564d0eacfe30d5e98cea584c0b4d48f4fad27cb2 100644 (file)
@@ -1817,17 +1817,8 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
                 */
                MCTXLOCK(mctx);
                for (i = 0; i < mpctx->fillcount; i++) {
-                       if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
-                               item = mem_getunlocked(mctx, mpctx->size);
-                       } else {
-                               item = mem_get(mctx, mpctx->size);
-                               if (item != NULL) {
-                                       mem_getstats(mctx, mpctx->size);
-                               }
-                       }
-                       if (ISC_UNLIKELY(item == NULL)) {
-                               break;
-                       }
+                       item = mem_get(mctx, mpctx->size);
+                       mem_getstats(mctx, mpctx->size);
                        item->next = mpctx->items;
                        mpctx->items = item;
                        mpctx->freecount++;
@@ -1888,12 +1879,8 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) {
         */
        if (mpctx->freecount >= mpctx->freemax) {
                MCTXLOCK(mctx);
-               if ((mctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
-                       mem_putunlocked(mctx, mem, mpctx->size);
-               } else {
-                       mem_putstats(mctx, mem, mpctx->size);
-                       mem_put(mctx, mem, mpctx->size);
-               }
+               mem_putstats(mctx, mem, mpctx->size);
+               mem_put(mctx, mem, mpctx->size);
                MCTXUNLOCK(mctx);
                return;
        }