Changeset: 0756077e6acf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0756077e6acf
Modified Files:
        gdk/gdk_utils.c
Branch: Aug2024
Log Message:

Fix block leak in allocator

fixes #7619.

Function sa_alloc tries to satisfy requests from the "current" block
of memory.  When exhausted, the current block is retired and a newly
allocated block becomes the current block. However, when a large
request comes in, it gets its own private block and the current block
is not retired.  The cutoff point between these two behaviors was a
branch "if (sz > SA_BLOCK) do not retire". This turns out to be very
suboptimal.

The problem is that suballocators request blocks of size SA_BLOCK
from the root allocator.  This means that for every new suballocator,
the root allocator unnecessarily retired the current block.

For example, every prepared statement creates a new suballocator.
This makes the root allocator retire the current block, allocate a
new block for the suballocator and then another new block to replace
its retired block.  The block for the suballocator is eventually
reused when (if!) the suballocator is destroyed but the unnecessarily
retired blocks just accumulate.

By writing "if (sz >= SA_BLOCK)" instead, newly created suballocators
leave the current block of the root allocator in place, wasting much
less memory.


diffs (15 lines):

diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2223,7 +2223,10 @@ sa_alloc( allocator *sa, size_t sz )
                        }
                        sa->blks = tmp;
                }
-               if (sz > SA_BLOCK) {
+               if (sz >= SA_BLOCK) {
+                       // The request is large so it gets its own block.
+                       // We put it 'under' the current block because
+                       // there may still be plenty of usable space there.
                        sa->blks[sa->nr] = sa->blks[sa->nr-1];
                        sa->blks[sa->nr-1] = r;
                        sa->nr ++;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to