Changeset: 532e473a1330 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/532e473a1330
Modified Files:
        sql/backends/monet5/sql_upgrades.c
        sql/server/rel_select.c
Branch: default
Log Message:

Merge with Dec2025 branch.


diffs (truncated from 1070 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -479,7 +479,7 @@ BAT *canditer_slice(const struct candite
 BAT *canditer_slice2(const struct canditer *ci, BUN lo1, BUN hi1, BUN lo2, BUN 
hi2);
 BAT *canditer_slice2val(const struct canditer *ci, oid lo1, oid hi1, oid lo2, 
oid hi2);
 BAT *canditer_sliceval(const struct canditer *ci, oid lo, oid hi);
-allocator *create_allocator(allocator *pa, const char *, bool use_lock);
+allocator *create_allocator(const char *, bool use_lock);
 char *ctime_r(const time_t *restrict, char *restrict);
 date date_add_day(date dt, int days) __attribute__((__const__));
 date date_add_month(date dt, int months) __attribute__((__const__));
@@ -567,12 +567,11 @@ void ma_close(const allocator_state *);
 void ma_destroy(allocator *sa);
 void ma_free(allocator *sa, void *);
 exception_buffer *ma_get_eb(allocator *sa) __attribute__((__pure__));
-allocator *ma_get_parent(const allocator *sa);
-int ma_info(const allocator *sa, char *buf, size_t buflen, const char *pref);
+int ma_info(allocator *sa, char *buf, size_t buflen, const char *pref);
 const char *ma_name(allocator *sa);
 allocator_state ma_open(allocator *sa);
 void *ma_realloc(allocator *sa, void *ptr, size_t sz, size_t osz);
-allocator *ma_reset(allocator *sa);
+void ma_reset(allocator *sa);
 size_t ma_size(allocator *sa);
 char *ma_strconcat(allocator *sa, const char *s1, const char *s2);
 char *ma_strdup(allocator *sa, const char *s);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -71,7 +71,6 @@ typedef struct allocator allocator;
 typedef struct {
        size_t nr;
        size_t used;
-       size_t usedmem;  /* total used memory */
        size_t objects;
        size_t inuse;
        size_t tmp_used;
@@ -1755,10 +1754,9 @@ gdk_export ValPtr VALcopy(allocator *va,
 gdk_export ValPtr VALinit(allocator *va, ValPtr d, int tpe, const void *s)
        __attribute__((__access__(write_only, 2)));
 
-gdk_export allocator *create_allocator(allocator *pa, const char *, bool 
use_lock);
-gdk_export allocator *ma_get_parent(const allocator *sa);
+gdk_export allocator *create_allocator(const char *, bool use_lock);
 gdk_export bool ma_tmp_active(const allocator *sa);
-gdk_export allocator *ma_reset(allocator *sa);
+gdk_export void ma_reset(allocator *sa);
 gdk_export void *ma_alloc(allocator *sa,  size_t sz);
 gdk_export void *ma_zalloc(allocator *sa,  size_t sz);
 gdk_export void *ma_realloc(allocator *sa,  void *ptr, size_t sz, size_t osz);
@@ -1774,7 +1772,7 @@ gdk_export void ma_free(allocator *sa, v
 gdk_export exception_buffer *ma_get_eb(allocator *sa)
        __attribute__((__pure__));
 
-gdk_export int ma_info(const allocator *sa, char *buf, size_t buflen, const 
char *pref);
+gdk_export int ma_info(allocator *sa, char *buf, size_t buflen, const char 
*pref);
 
 #define MA_NEW( sa, type )                             ((type*)ma_alloc( sa, 
sizeof(type)))
 #define MA_ZNEW( sa, type )                            ((type*)ma_zalloc( sa, 
sizeof(type)))
@@ -1857,16 +1855,15 @@ gdk_export int ma_info(const allocator *
                          _sa, ma_name(_sa), strlen(_s1), strlen(_s2), _res); \
                _res;                                                   \
        })
-#define create_allocator(sa, nm, lk)                                   \
-       ({                                                              \
-               allocator *_sa = (sa);                                  \
-               const char *_nm = (nm);                                 \
-               bool _lk = (lk);                                        \
-               allocator *_res = create_allocator(_sa, _nm, _lk);      \
-               TRC_DEBUG(ALLOC,                                        \
-                         "create_allocator(%p(%s)) -> %p(%s)\n",       \
-                         _sa, ma_name(_sa), _res, ma_name(_res));      \
-               _res;                                                   \
+#define create_allocator(nm, lk)                               \
+       ({                                                      \
+               const char *_nm = (nm);                         \
+               bool _lk = (lk);                                \
+               allocator *_res = create_allocator(_nm, _lk);   \
+               TRC_DEBUG(ALLOC,                                \
+                         "create_allocator() -> %p(%s)\n",     \
+                         _res, ma_name(_res));                 \
+               _res;                                           \
        })
 #define ma_open(sa)                                                    \
        ({                                                              \
@@ -1888,19 +1885,16 @@ gdk_export int ma_info(const allocator *
 #define ma_reset(sa)                                                   \
        ({                                                              \
                allocator *_sa = (sa);                                  \
-               allocator *_sa2 = ma_reset(_sa);                        \
+               ma_reset(_sa);                                          \
                TRC_DEBUG(ALLOC,                                        \
-                         "ma_reset(%p(%s)) -> %p\n",                   \
-                         _sa, ma_name(_sa), _sa2);                     \
-               _sa2;                                                   \
+                         "ma_reset(%p(%s))\n", _sa, ma_name(_sa));     \
        })
-#define ma_destroy(sa)                                 \
-       ({                                              \
-               allocator *_sa = (sa);                  \
-               TRC_DEBUG(ALLOC,                        \
-                         "ma_destroy(%p(%s))\n",       \
-                         _sa, ma_name(_sa));           \
-               ma_destroy(_sa);                        \
+#define ma_destroy(sa)                                                 \
+       ({                                                              \
+               allocator *_sa = (sa);                                  \
+               TRC_DEBUG(ALLOC,                                        \
+                         "ma_destroy(%p(%s))\n", _sa, ma_name(_sa));   \
+               ma_destroy(_sa);                                        \
        })
 #endif
 
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -418,7 +418,7 @@ MT_thread_init(void)
        }
        InitializeCriticalSection(&winthread_cs);
 #endif
-       mainthread.ma = create_allocator(NULL, mainthread.threadname, false);
+       mainthread.ma = create_allocator(mainthread.threadname, false);
        if (mainthread.ma == NULL) {
                GDKerror("Creating thread-local allocator failed");
                return false;
@@ -462,7 +462,7 @@ MT_thread_register(void)
                .semawait = ATOMIC_PTR_VAR_INIT(NULL),
        };
        snprintf(self->threadname, sizeof(self->threadname), "foreign %zu", 
self->tid);
-       self->ma = create_allocator(NULL, self->threadname, false);
+       self->ma = create_allocator(self->threadname, false);
        if (self->ma == NULL) {
                free(self);
                return false;
@@ -971,13 +971,16 @@ MT_create_thread(MT_Id *t, void (*f) (vo
                .exited = ATOMIC_VAR_INIT(0),
                .working = ATOMIC_PTR_VAR_INIT(NULL),
                .semawait = ATOMIC_PTR_VAR_INIT(NULL),
-               .ma = create_allocator(NULL, threadname, false),
+               .ma = create_allocator(threadname, false),
        };
        if (self->ma == NULL) {
                free(self);
                GDKerror("Creating thread allocator failed\n");
                return -1;
        }
+#ifndef NDEBUG
+       self->ma->self = self->tid;
+#endif
        MT_lock_set(&thread_init_lock);
        /* remember the list of callback functions we need to call for
         * this thread (i.e. anything registered so far) */
diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h
--- a/gdk/gdk_system_private.h
+++ b/gdk/gdk_system_private.h
@@ -49,7 +49,6 @@ struct freebats *MT_thread_getfreebats(v
        __attribute__((__visibility__("hidden")));
 
 struct allocator {
-       struct allocator *pa;
        size_t size;     /* size of the allocator in terms of blocks */
        size_t nr;       /* number of blocks allocated */
        void **blks;
@@ -58,16 +57,16 @@ struct allocator {
        size_t usedmem;  /* total used memory */
        size_t objects;  /* number of objects */
        size_t inuse;    /* number of objects in use*/
-       size_t free_obj_hits; /* number of object reuse*/
        void *freelist; /* first free object */
-       void *freelist_blks;    /* first free blk */
-       size_t frees;
-       size_t free_blk_hits;
        size_t tmp_used; /* counter for temp usage */
 
-       int refcount;
        exception_buffer eb;
        MT_Lock lock;    /* lock for thread-safe allocations */
        bool use_lock;
+#ifndef NDEBUG
+       MT_Id self;
+       size_t free_obj_hits; /* number of objects reused */
+       size_t frees;         /* number of objects freed */
+#endif
        char name[MT_NAME_LEN]; /* Name (only for display!) */
 };
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2014,7 +2014,7 @@ GDKmremap(const char *path, int mode, vo
        if ((a)->use_lock) {                    \
                MT_lock_set(&(a)->lock);        \
                __alloc_locked = true;          \
-       }
+       } else assert((a)->self == MT_getpid());
 
 #define COND_UNLOCK_ALLOCATOR(a)               \
        if (__alloc_locked) {                   \
@@ -2067,27 +2067,15 @@ ma_free_obj(allocator *sa, void *obj, si
                sa->inuse -= 1;
 }
 
-/*
- * Put regular blks of size MA_BLOCK_SIZE on freelist_blks
- * all others are GDKfree
- */
+
 static void
 ma_free_blk_memory(allocator *sa, void *blk)
 {
-       if (!sa->pa) {
-               // all blks are GDKmalloc
-               size_t sz = GDKmallocated(blk) - (MALLOC_EXTRA_SPACE + 
DEBUG_SPACE);
-               assert(sz > 0);
-               if (sz == MA_BLOCK_SIZE) {
-                       freed_t *f = blk;
-                       f->sz = sz;
-                       f->n = sa->freelist_blks;
-                       sa->freelist_blks = f;
-               } else {
-                       GDKfree(blk);
-                       sa->usedmem -= sz;
-               }
-       }
+       // all blks are GDKmalloc
+       size_t sz = GDKmallocated(blk) - (MALLOC_EXTRA_SPACE + DEBUG_SPACE);
+       assert(sz > 0);
+       GDKfree(blk);
+       sa->usedmem -= sz;
 }
 
 
@@ -2096,10 +2084,7 @@ ma_free_blk(allocator *sa, void *blk)
 {
        size_t i = ma_get_blk_idx(sa, blk, 0);
        if (i < sa->nr) {
-               if (sa->pa)
-                       ma_free_blk(sa->pa, blk);
-               else
-                       ma_free_blk_memory(sa, blk);
+               ma_free_blk_memory(sa, blk);
                // compact
                for (; i < sa->nr-1; i++)
                        sa->blks[i] = sa->blks[i+1];
@@ -2119,14 +2104,16 @@ ma_use_freed_obj(allocator *sa, size_t s
        int MAX_ITERATIONS = 100;
        COND_LOCK_ALLOCATOR(sa);
        freed_t *curr = sa->freelist;
-       while(curr && (cntr < MAX_ITERATIONS)) {
+       while (curr && (cntr < MAX_ITERATIONS)) {
                if (sz <= curr->sz) {
                        if (prev) {
                                prev->n = curr->n;
                        } else {
                                sa->freelist = curr->n;
                        }
+#ifndef NDEBUG
                        sa->free_obj_hits += 1;
+#endif
                        sa->inuse += 1;
                        COND_UNLOCK_ALLOCATOR(sa);
                        return curr;
@@ -2147,41 +2134,11 @@ static int ma_double_num_blks(allocator 
  * Free blocks are maintained at top level
  */
 static void *
-ma_use_freed_blk(allocator *sa, size_t sz)
-{
-       if (sa->pa)
-               return ma_use_freed_blk(sa->pa, sz);
-       COND_LOCK_ALLOCATOR(sa);
-       if (sa->freelist_blks && (sz == MA_BLOCK_SIZE)) {
-               if (sa->nr >= sa->size && ma_double_num_blks(sa) < 0) {
-                       COND_UNLOCK_ALLOCATOR(sa);
-                       if (sa->eb.enabled)
-                               eb_error(&sa->eb, "out of memory", 1000);
-                       return NULL;
-               }
-               freed_t *f = sa->freelist_blks;
-               sa->freelist_blks = f->n;
-               sa->used = MA_BLOCK_SIZE;
-               sa->blks[sa->nr] = (void *) f;
-               sa->nr ++;
-               sa->free_blk_hits += 1;
-               COND_UNLOCK_ALLOCATOR(sa);
-               return f;
-       }
-       COND_UNLOCK_ALLOCATOR(sa);
-       return NULL;
-}
-
-
-static void *
 ma_use_freed(allocator *sa, size_t sz)
 {
        if (sz < MA_BLOCK_SIZE) {
                return ma_use_freed_obj(sa, sz);
        }
-       if (sz == MA_BLOCK_SIZE) {
-               return ma_use_freed_blk(sa, sz);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to