Changeset: 1622cced8c5d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1622cced8c5d
Modified Files:
        gdk/gdk_bbp.c
Branch: default
Log Message:

Merge with Jun2023 branch.


diffs (269 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -332,7 +332,7 @@ BBPselectfarm(role_t role, int type, enu
 static gdk_return
 BBPextend(bat newsize)
 {
-       if (newsize >= N_BBPINIT * BBPINIT) {
+       if (newsize > N_BBPINIT * BBPINIT) {
                GDKerror("trying to extend BAT pool beyond the "
                         "limit (%d)\n", N_BBPINIT * BBPINIT);
                return GDK_FAIL;
@@ -1700,6 +1700,15 @@ BBPinit(void)
                fclose(fp);
        }
 
+       /* add free bats to free list in such a way that low numbered
+        * ones are at the head of the list */
+       for (bat i = (bat) ATOMIC_GET(&BBPsize) - 1; i > 0; i--) {
+               if (BBP_desc(i) == NULL) {
+                       BBP_next(i) = BBP_free;
+                       BBP_free = i;
+               }
+       }
+
        /* will call BBPrecover if needed */
        if (!GDKinmemory(0)) {
                BBPtmlock();
@@ -2375,14 +2384,15 @@ maybeextend(void)
            BBPextend(size + BBP_FREE_LOWATER) != GDK_SUCCEED) {
                /* nothing available */
                return GDK_FAIL;
-       } else {
-               ATOMIC_SET(&BBPsize, size + BBP_FREE_LOWATER);
-               for (int i = 0; i < BBP_FREE_LOWATER; i++) {
-                       BBP_next(size) = BBP_free;
-                       BBP_free = size;
-                       size++;
-               }
        }
+       ATOMIC_SET(&BBPsize, size + BBP_FREE_LOWATER);
+       assert(BBP_free == 0);
+       BBP_free = size;
+       for (int i = 1; i < BBP_FREE_LOWATER; i++) {
+               bat sz = size;
+               BBP_next(sz) = ++size;
+       }
+       BBP_next(size) = 0;
        return GDK_SUCCEED;
 }
 
@@ -2399,6 +2409,7 @@ BBPinsert(BAT *bn)
 
        if (t->freebats == 0) {
                /* critical section: get a new BBP entry */
+               assert(t->nfreebats == 0);
                if (lock) {
                        MT_lock_set(&GDKcacheLock);
                }
@@ -2416,16 +2427,16 @@ BBPinsert(BAT *bn)
                                return 0;
                        }
                }
-               for (int x = 0; x < BBP_FREE_LOWATER; x++) {
-                       i = BBP_free;
-                       if (i == 0)
-                               break;
-                       assert(i > 0);
-                       BBP_free = BBP_next(i);
-                       BBP_next(i) = t->freebats;
-                       t->freebats = i;
+               t->freebats = i = BBP_free;
+               bat l = 0;
+               for (int x = 0; x < BBP_FREE_LOWATER && i; x++) {
+                       assert(BBP_next(i) == 0 || BBP_next(i) > i);
                        t->nfreebats++;
+                       l = i;
+                       i = BBP_next(i);
                }
+               BBP_next(l) = 0;
+               BBP_free = i;
 
                if (lock) {
                        MT_lock_unset(&GDKcacheLock);
@@ -2436,6 +2447,7 @@ BBPinsert(BAT *bn)
                assert(t->freebats > 0);
                i = t->freebats;
                t->freebats = BBP_next(i);
+               assert(t->freebats == 0 || t->freebats > i);
                BBP_next(i) = 0;
                t->nfreebats--;
        } else {
@@ -2555,8 +2567,11 @@ BBPhandover(Thread t)
        bat i = t->freebats;
        t->freebats = BBP_next(i);
        t->nfreebats--;
-       BBP_next(i) = BBP_free;
-       BBP_free = i;
+       bat *p;
+       for (p = &BBP_free; *p && *p < i; p = &BBP_next(*p))
+               ;
+       BBP_next(i) = *p;
+       *p = i;
 }
 
 static inline void
@@ -2585,8 +2600,11 @@ bbpclear(bat i, bool lock)
                GDKfree(BBP_logical(i));
        BBP_status_set(i, 0);
        BBP_logical(i) = NULL;
-       BBP_next(i) = t->freebats;
-       t->freebats = i;
+       bat *p;
+       for (p = &t->freebats; *p && *p < i; p = &BBP_next(*p))
+               ;
+       BBP_next(i) = *p;
+       *p = i;
        t->nfreebats++;
        BBP_pid(i) = ~(MT_Id)0; /* not zero, not a valid thread id */
        if (t->nfreebats > BBP_FREE_HIWATER) {
@@ -3271,13 +3289,6 @@ dirty_bat(bat *i, bool subcommit)
                                return b;       /* the bat is loaded, 
persistent and dirty */
                        }
                        MT_lock_unset(&b->theaplock);
-               } else if (BBP_status(*i) & BBPSWAPPED) {
-                       b = (BAT *) BBPquickdesc(*i);
-                       if (b) {
-                               if (subcommit) {
-                                       return b;       /* only the desc is 
loaded */
-                               }
-                       }
                }
        }
        return NULL;
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -468,17 +468,17 @@ typedef struct MT_Lock {
 #define MT_lock_try(l)         (pthread_mutex_trylock(&(l)->lock) == 0 && 
(_DBG_LOCK_LOCKER(l), true))
 
 #ifdef LOCK_STATS
-#define MT_lock_set(l)                                 \
-       do {                                            \
-               _DBG_LOCK_COUNT_0(l);                   \
-               if (pthread_mutex_trylock(&(l)->lock) { \
-                       _DBG_LOCK_CONTENTION(l);        \
-                       MT_thread_setlockwait(l);       \
-                       pthread_mutex_lock(&(l)->lock); \
-                       MT_thread_setlockwait(NULL);    \
-               }                                       \
-               _DBG_LOCK_LOCKER(l);                    \
-               _DBG_LOCK_COUNT_2(l);                   \
+#define MT_lock_set(l)                                         \
+       do {                                                    \
+               _DBG_LOCK_COUNT_0(l);                           \
+               if (pthread_mutex_trylock(&(l)->lock)) {        \
+                       _DBG_LOCK_CONTENTION(l);                \
+                       MT_thread_setlockwait(l);               \
+                       pthread_mutex_lock(&(l)->lock);         \
+                       MT_thread_setlockwait(NULL);            \
+               }                                               \
+               _DBG_LOCK_LOCKER(l);                            \
+               _DBG_LOCK_COUNT_2(l);                           \
        } while (0)
 #else
 #define MT_lock_set(l)                         \
diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c
--- a/gdk/gdk_tracer.c
+++ b/gdk/gdk_tracer.c
@@ -114,6 +114,8 @@ GDKtracer_init_trace_file(const char *db
 
        /* we use malloc/free instead of GDKmalloc/GDKfree to avoid
         * possible recursion */
+#undef malloc
+#undef free
        if (dbtrace == NULL) {
                write_to_tracer = false;
                if (dbpath == NULL) {
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2032,11 +2032,8 @@ GDKfree(void *s)
 #if !defined(NDEBUG) && !defined(SANITIZER)
        assert((asize & 2) == 0);   /* check against duplicate free */
        /* check for out-of-bounds writes */
-       {
-               size_t i = ((size_t *) s)[-2]; /* how much asked for last */
-               for (; i < asize - MALLOC_EXTRA_SPACE; i++)
-                       assert(((char *) s)[i] == '\xBD');
-       }
+       for (size_t i = ((size_t *) s)[-2]; i < asize - MALLOC_EXTRA_SPACE; i++)
+               assert(((char *) s)[i] == '\xBD');
        ((size_t *) s)[-1] |= 2; /* indicate area is freed */
 
        /* overwrite memory that is to be freed with a pattern that
@@ -2056,8 +2053,8 @@ GDKrealloc(void *s, size_t size)
        size_t nsize, asize;
 #if !defined(NDEBUG) && !defined(SANITIZER)
        size_t osize;
-       size_t *os;
 #endif
+       size_t *os = s;
 
        assert(size != 0);
 
@@ -2065,7 +2062,7 @@ GDKrealloc(void *s, size_t size)
                return GDKmalloc(size);
 
        nsize = (size + 7) & ~7;
-       asize = ((size_t *) s)[-1]; /* how much allocated last */
+       asize = os[-1];         /* how much allocated last */
 
        if (size > SMALL_MALLOC &&
            nsize > asize &&
@@ -2077,16 +2074,12 @@ GDKrealloc(void *s, size_t size)
 #if !defined(NDEBUG) && !defined(SANITIZER)
        assert((asize & 2) == 0);   /* check against duplicate free */
        /* check for out-of-bounds writes */
-       osize = ((size_t *) s)[-2]; /* how much asked for last */
-       {
-               size_t i;
-               for (i = osize; i < asize - MALLOC_EXTRA_SPACE; i++)
-                       assert(((char *) s)[i] == '\xBD');
-       }
+       osize = os[-2]; /* how much asked for last */
+       for (size_t i = osize; i < asize - MALLOC_EXTRA_SPACE; i++)
+               assert(((char *) s)[i] == '\xBD');
        /* if shrinking, write debug pattern into to-be-freed memory */
        DEADBEEFCHK if (size < osize)
                memset((char *) s + size, '\xDB', osize - size);
-       os = s;
        os[-1] |= 2;            /* indicate area is freed */
 #endif
        s = realloc((char *) s - MALLOC_EXTRA_SPACE,
diff --git a/gdk/gdk_utils.h b/gdk/gdk_utils.h
--- a/gdk/gdk_utils.h
+++ b/gdk/gdk_utils.h
@@ -168,7 +168,7 @@ gdk_export int GDKms(void);
        ({                                                      \
                void *_ptr = (p);                               \
                size_t _size = (s);                             \
-               char _buf[12];                                  \
+               char _buf[2*sizeof(void*)+3];                   \
                snprintf(_buf, sizeof(_buf), "%p", _ptr);       \
                void *_res = GDKrealloc(_ptr, _size);           \
                TRC_DEBUG(ALLOC, "GDKrealloc(%s,%zu) -> %p\n",  \
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -251,7 +251,6 @@ getIntConstant(MalBlkPtr mb, int val)
        _t= fndConstant(mb, &cst, MAL_VAR_WINDOW);
        if( _t < 0)
                _t = defConstant(mb, TYPE_int, &cst);
-       assert(_t >= 0);
        return _t;
 }
 
diff --git a/sql/storage/objlist.c b/sql/storage/objlist.c
--- a/sql/storage/objlist.c
+++ b/sql/storage/objlist.c
@@ -58,6 +58,8 @@ ol_add(objlist *ol, sql_base *data)
        if (ol->h->size <= sz) {
                hash_destroy(ol->h);
                ol->h = hash_new(ol->l->sa, 4*sz, (fkeyvalue)&node_key);
+               if (ol->h == NULL)
+                       return -1;
                for (node *n = ol->l->h; n; n = n->next) {
                        if (hash_add(ol->h, base_key(n->data), n) == NULL)
                                /* No need to clean, ie expect a full 
transaction rollback */
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to