Changeset: de411981870d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/de411981870d
Branch: distinct_from
Log Message:

merge with default


diffs (truncated from 2516 to 300 lines):

diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -1,6 +1,14 @@
 # ChangeLog file for GDK
 # This file is updated with Maddlog
 
+* Tue Mar 26 2024 Sjoerd Mullender <sjo...@acm.org>
+- Made some changes to how BAT descriptors are allocated.  They are now
+  allocated in bulk, meaning fewer malloc/free calls during processing.
+- Removed macro BBP_cache and its associated code.  Checking whether a
+  BAT is cached (loaded in memory) can be done by checking the BBPLOADED
+  bit in the BBP_status value.  Getting a pointer to the BAT descriptor
+  can be done by using BBP_desc.
+
 * Tue Feb  6 2024 Sjoerd Mullender <sjo...@acm.org>
 - The SQL transaction ID is no longer saved in the BBP.dir file.
 
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -956,10 +956,9 @@ gdk_export void HEAPincref(Heap *h);
  * field.
  */
 typedef struct {
-       BAT *cache;             /* if loaded: BAT* handle */
        char *logical;          /* logical name (may point at bak) */
        char bak[16];           /* logical name backup (tmp_%o) */
-       BAT *desc;              /* the BAT descriptor */
+       BAT descr;              /* the BAT descriptor */
        char *options;          /* A string list of options */
 #if SIZEOF_VOID_P == 4
        char physical[20];      /* dir + basename for storage */
@@ -993,19 +992,18 @@ gdk_export BBPrec *BBP[N_BBPINIT];
 
 /* fast defines without checks; internal use only  */
 #define BBP_record(i)  BBP[(i)>>BBPINITLOG][(i)&(BBPINIT-1)]
-#define BBP_cache(i)   BBP_record(i).cache
 #define BBP_logical(i) BBP_record(i).logical
 #define BBP_bak(i)     BBP_record(i).bak
 #define BBP_next(i)    BBP_record(i).next
 #define BBP_physical(i)        BBP_record(i).physical
 #define BBP_options(i) BBP_record(i).options
-#define BBP_desc(i)    BBP_record(i).desc
+#define BBP_desc(i)    (&BBP_record(i).descr)
 #define BBP_refs(i)    BBP_record(i).refs
 #define BBP_lrefs(i)   BBP_record(i).lrefs
 #define BBP_status(i)  ((unsigned) ATOMIC_GET(&BBP_record(i).status))
 #define BBP_pid(i)     BBP_record(i).pid
 #define BATgetId(b)    BBP_logical((b)->batCacheid)
-#define BBPvalid(i)    (BBP_logical(i) != NULL && *BBP_logical(i) != '.')
+#define BBPvalid(i)    (BBP_logical(i) != NULL)
 
 #define BBPRENAME_ALREADY      (-1)
 #define BBPRENAME_ILLEGAL      (-2)
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -3675,7 +3675,6 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
                                if ((pb == NULL || bi.count == BATcount(pb)) &&
                                    BATcheckimprints(b)) {
                                        if (pb != NULL) {
-                                               BAT *pb = 
BBP_cache(VIEWtparent(b));
                                                MT_lock_set(&pb->batIdxLock);
                                                imprints = pb->timprints;
                                                if (imprints != NULL)
@@ -3842,7 +3841,6 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
                                if ((pb == NULL || BATcount(b) == BATcount(pb)) 
&&
                                    BATcheckimprints(b)) {
                                        if (pb != NULL) {
-                                               BAT *pb = 
BBP_cache(VIEWtparent(b));
                                                MT_lock_set(&pb->batIdxLock);
                                                imprints = pb->timprints;
                                                if (imprints != NULL)
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -58,22 +58,49 @@
 BAT *
 BATcreatedesc(oid hseq, int tt, bool heapnames, role_t role, uint16_t width)
 {
+       bat bid;
        BAT *bn;
+       Heap *h = NULL, *vh = NULL;
 
        /*
         * Alloc space for the BAT and its dependent records.
         */
        assert(tt >= 0);
 
-       bn = GDKmalloc(sizeof(BAT));
+       if (heapnames) {
+               if ((h = GDKmalloc(sizeof(Heap))) == NULL) {
+                       return NULL;
+               }
+               *h = (Heap) {
+                       .farmid = BBPselectfarm(role, tt, offheap),
+                       .dirty = true,
+               };
 
-       if (bn == NULL)
+               if (ATOMneedheap(tt)) {
+                       if ((vh = GDKmalloc(sizeof(Heap))) == NULL) {
+                               GDKfree(h);
+                               return NULL;
+                       }
+                       *vh = (Heap) {
+                               .farmid = BBPselectfarm(role, tt, varheap),
+                               .dirty = true,
+                       };
+               }
+       }
+
+       bid = BBPallocbat(tt);
+       if (bid == 0) {
+               GDKfree(h);
+               GDKfree(vh);
                return NULL;
+       }
+       bn = BBP_desc(bid);
 
        /*
         * Fill in basic column info
         */
        *bn = (BAT) {
+               .batCacheid = bid,
                .hseqbase = hseq,
 
                .ttype = tt,
@@ -90,39 +117,11 @@ BATcreatedesc(oid hseq, int tt, bool hea
                .batRole = role,
                .batTransient = true,
                .batRestricted = BAT_WRITE,
+               .theap = h,
+               .tvheap = vh,
+               .creator_tid = MT_getpid(),
        };
 
-       if (heapnames) {
-               if ((bn->theap = GDKmalloc(sizeof(Heap))) == NULL) {
-                       GDKfree(bn);
-                       return NULL;
-               }
-               *bn->theap = (Heap) {
-                       .farmid = BBPselectfarm(role, bn->ttype, offheap),
-                       .dirty = true,
-               };
-
-               if (ATOMneedheap(tt)) {
-                       if ((bn->tvheap = GDKmalloc(sizeof(Heap))) == NULL) {
-                               GDKfree(bn->theap);
-                               GDKfree(bn);
-                               return NULL;
-                       }
-                       *bn->tvheap = (Heap) {
-                               .farmid = BBPselectfarm(role, bn->ttype, 
varheap),
-                               .dirty = true,
-                       };
-               }
-       }
-       /*
-        * add to BBP
-        */
-       if (BBPinsert(bn) == 0) {
-               GDKfree(bn->tvheap);
-               GDKfree(bn->theap);
-               GDKfree(bn);
-               return NULL;
-       }
        if (bn->theap) {
                bn->theap->parentid = bn->batCacheid;
                ATOMIC_INIT(&bn->theap->refs, 1);
@@ -729,7 +728,9 @@ BATdestroy(BAT *b)
                HEAPdecref(b->oldtail, false);
                b->oldtail = NULL;
        }
-       GDKfree(b);
+       *b = (BAT) {
+               .batCacheid = 0,
+       };
 }
 
 /*
@@ -2686,7 +2687,7 @@ BATassertProps(BAT *b)
        assert(b != NULL);
        assert(b->batCacheid > 0);
        assert(b->batCacheid < getBBPsize());
-       assert(b == BBP_cache(b->batCacheid));
+       assert(b == BBP_desc(b->batCacheid));
        assert(b->batCount >= b->batInserted);
 
        /* headless */
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -2154,7 +2154,7 @@ BATordered(BAT *b)
        bat pbid = VIEWtparent(b);
        MT_lock_unset(&b->theaplock);
        if (pbid) {
-               BAT *pb = BBP_cache(pbid);
+               BAT *pb = BBP_desc(pbid);
                MT_lock_set(&pb->theaplock);
                if (bi.count == BATcount(pb) &&
                    bi.h == pb->theap &&
@@ -2273,7 +2273,7 @@ BATordered_rev(BAT *b)
        bat pbid = VIEWtparent(b);
        MT_lock_unset(&b->theaplock);
        if (pbid) {
-               BAT *pb = BBP_cache(pbid);
+               BAT *pb = BBP_desc(pbid);
                MT_lock_set(&pb->theaplock);
                if (bi.count == BATcount(pb) &&
                    bi.h == pb->theap &&
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -101,8 +101,9 @@
  * are found in O(1) by keeping a freelist that uses the 'next' field
  * in the BBPrec records.
  */
-BBPrec *BBP[N_BBPINIT];                /* fixed base VM address of BBP array */
-bat BBPlimit = 0;              /* current committed VM BBP array */
+static BBPrec BBP0[BBPINIT];
+BBPrec *BBP[N_BBPINIT] = {[0] = BBP0}; /* fixed base VM address of BBP array */
+bat BBPlimit = BBPINIT;                /* current committed VM BBP array */
 static ATOMIC_TYPE BBPsize = ATOMIC_VAR_INIT(0); /* current used size of BBP 
array */
 
 struct BBPfarm_t BBPfarms[MAXFARMS];
@@ -796,7 +797,8 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                        }
                        ATOMIC_SET(&BBPsize, b.batCacheid + 1);
                }
-               if (BBP_desc(b.batCacheid) != NULL) {
+               BAT *bn = BBP_desc(b.batCacheid);
+               if (bn->batCacheid != 0) {
                        GDKfree(options);
                        TRC_CRITICAL(GDK, "duplicate entry in BBP.dir (ID = "
                                     "%d) on line %d.", b.batCacheid, lineno);
@@ -816,11 +818,8 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                }
 #endif
 
-               BAT *bn;
                Heap *hn;
-               if ((bn = GDKmalloc(sizeof(BAT))) == NULL ||
-                   (hn = GDKmalloc(sizeof(Heap))) == NULL) {
-                       GDKfree(bn);
+               if ((hn = GDKmalloc(sizeof(Heap))) == NULL) {
                        GDKfree(options);
                        TRC_CRITICAL(GDK, "cannot allocate memory for BAT.");
                        goto bailout;
@@ -833,7 +832,6 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                        assert(b.tvheap == &vh);
                        if ((vhn = GDKmalloc(sizeof(Heap))) == NULL) {
                                GDKfree(hn);
-                               GDKfree(bn);
                                GDKfree(options);
                                TRC_CRITICAL(GDK, "cannot allocate memory for 
BAT.");
                                goto bailout;
@@ -887,7 +885,6 @@ BBPreadEntries(FILE *fp, unsigned bbpver
                BBP_options(b.batCacheid) = options;
                BBP_refs(b.batCacheid) = 0;
                BBP_lrefs(b.batCacheid) = 1;    /* any BAT we encounter here is 
persistent, so has a logical reference */
-               BBP_desc(b.batCacheid) = bn;
                BBP_pid(b.batCacheid) = 0;
                BBP_status_set(b.batCacheid, BBPEXISTING);
                if (BBPnamecheck(BBP_logical(b.batCacheid)) == 0)
@@ -914,11 +911,8 @@ BBPcheckbats(unsigned bbpversion)
                BAT *b;
                char *path;
 
-               if ((b = BBP_desc(bid)) == NULL) {
-                       /* not a valid BAT */
-                       continue;
-               }
-               if (b->ttype == TYPE_void) {
+               b = BBP_desc(bid);
+               if (b->batCacheid == 0 || b->ttype == TYPE_void) {
                        /* no files needed */
                        continue;
                }
@@ -1441,8 +1435,8 @@ fixhashash(bat *hashbats, bat nhashbats)
 {
        for (bat i = 0; i < nhashbats; i++) {
                bat bid = hashbats[i];
-               BAT *b;
-               if ((b = BBP_desc(bid)) == NULL) {
+               BAT *b = BBP_desc(bid);
+               if (b->batCacheid == 0) {
                        /* not a valid BAT (shouldn't happen) */
                        continue;
                }
@@ -1459,7 +1453,7 @@ movestrbats(void)
 {
        for (bat bid = 1, nbat = (bat) ATOMIC_GET(&BBPsize); bid < nbat; bid++) 
{
                BAT *b = BBP_desc(bid);
-               if (b == NULL) {
+               if (b->batCacheid == 0) {
                        /* not a valid BAT */
                        continue;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to