Changeset: 2d9c5e931356 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2d9c5e931356
Modified Files:
        gdk/gdk.h
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        gdk/gdk_group.c
        gdk/gdk_hash.c
        gdk/gdk_heap.c
        gdk/gdk_imprints.c
        gdk/gdk_orderidx.c
        gdk/gdk_project.c
        gdk/gdk_unique.c
        monetdb5/modules/kernel/bat5.c
        sql/backends/monet5/UDF/pyapi/convert_loops.h
Branch: default
Log Message:

Reduce number of mallocs by incorporating the heap filename into the heap 
structure.


diffs (truncated from 806 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -600,7 +600,7 @@ typedef struct {
        size_t free;            /* index where free area starts. */
        size_t size;            /* size of the heap (bytes) */
        char *base;             /* base pointer in memory. */
-       str filename;           /* file containing image of the heap */
+       char filename[32];      /* file containing image of the heap */
 
        unsigned int copied:1,  /* a copy of an existing map. */
                hashash:1,      /* the string heap contains hash values */
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -236,7 +236,7 @@ BATmaterialize(BAT *b)
        IMPSdestroy(b);
        OIDXdestroy(b);
 
-       b->theap.filename = NULL;
+       snprintf(b->theap.filename, sizeof(b->theap.filename), "%s.tail", 
BBP_physical(b->batCacheid));
        if (HEAPalloc(&b->theap, cnt, sizeof(oid)) != GDK_SUCCEED) {
                b->theap = tail;
                return GDK_FAIL;
@@ -327,24 +327,19 @@ VIEWreset(BAT *b)
        if (tp || tvp) {
                BUN cnt;
                const char *nme;
-               size_t nmelen;
 
                /* alloc heaps */
                memset(&tail, 0, sizeof(Heap));
 
                cnt = BATcount(b) + 1;
                nme = BBP_physical(b->batCacheid);
-               nmelen = strlen(nme);
 
                assert(b->batCacheid > 0);
                assert(tp || tvp || !b->ttype);
 
                tail.farmid = BBPselectfarm(b->batRole, b->ttype, offheap);
                if (b->ttype) {
-                       tail.filename = (str) GDKmalloc(nmelen + 12);
-                       if (tail.filename == NULL)
-                               goto bailout;
-                       snprintf(tail.filename, nmelen + 12, "%s.tail", nme);
+                       snprintf(tail.filename, sizeof(tail.filename), 
"%s.tail", nme);
                        if (b->ttype && HEAPalloc(&tail, cnt, Tsize(b)) != 
GDK_SUCCEED)
                                goto bailout;
                }
@@ -353,10 +348,7 @@ VIEWreset(BAT *b)
                        if (th == NULL)
                                goto bailout;
                        th->farmid = BBPselectfarm(b->batRole, b->ttype, 
varheap);
-                       th->filename = (str) GDKmalloc(nmelen + 12);
-                       if (th->filename == NULL)
-                               goto bailout;
-                       snprintf(th->filename, nmelen + 12, "%s.theap", nme);
+                       snprintf(th->filename, sizeof(th->filename), 
"%s.theap", nme);
                        if (ATOMheap(b->ttype, th, cnt) != GDK_SUCCEED)
                                goto bailout;
                }
@@ -496,7 +488,7 @@ VIEWdestroy(BAT *b)
                HEAPfree(&b->theap, 0);
        } else {
                b->theap.base = NULL;
-               b->theap.filename = NULL;
+               b->theap.filename[0] = 0;
        }
        b->tvheap = NULL;
        BATfree(b);
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -114,21 +114,19 @@ BATcreatedesc(oid hseq, int tt, int heap
         * very large writes.
         */
        assert(bn->batCacheid > 0);
-       bn->theap.filename = NULL;
+       bn->theap.filename[0] = 0;
        bn->theap.farmid = BBPselectfarm(role, bn->ttype, offheap);
        if (heapnames) {
                const char *nme = BBP_physical(bn->batCacheid);
 
                if (tt) {
-                       bn->theap.filename = GDKfilepath(NOFARM, NULL, nme, 
"tail");
-                       if (bn->theap.filename == NULL)
-                               goto bailout;
+                       snprintf(bn->theap.filename, 
sizeof(bn->theap.filename), "%s.tail", nme);
                }
 
                if (ATOMneedheap(tt)) {
-                       if ((bn->tvheap = (Heap *) GDKzalloc(sizeof(Heap))) == 
NULL ||
-                           (bn->tvheap->filename = GDKfilepath(NOFARM, NULL, 
nme, "theap")) == NULL)
+                       if ((bn->tvheap = (Heap *) GDKzalloc(sizeof(Heap))) == 
NULL)
                                goto bailout;
+                       snprintf(bn->tvheap->filename, 
sizeof(bn->tvheap->filename), "%s.theap", nme);
                        bn->tvheap->parentid = bn->batCacheid;
                        bn->tvheap->farmid = BBPselectfarm(role, bn->ttype, 
varheap);
                }
@@ -631,11 +629,9 @@ BATdestroy(BAT *b)
 static gdk_return
 heapcopy(BAT *bn, char *ext, Heap *dst, Heap *src)
 {
-       if (src->filename && src->newstorage != STORE_MEM) {
-               const char *nme = BBP_physical(bn->batCacheid);
-
-               if ((dst->filename = GDKfilepath(NOFARM, NULL, nme, ext)) == 
NULL)
-                       return GDK_FAIL;
+       if (src->filename[0] && src->newstorage != STORE_MEM) {
+               snprintf(dst->filename, sizeof(dst->filename), "%s.%s",
+                        BBP_physical(bn->batCacheid), ext);
        }
        return HEAPcopy(dst, src);
 }
@@ -643,9 +639,8 @@ heapcopy(BAT *bn, char *ext, Heap *dst, 
 static void
 heapmove(Heap *dst, Heap *src)
 {
-       if (src->filename == NULL) {
-               src->filename = dst->filename;
-               dst->filename = NULL;
+       if (src->filename[0] == 0) {
+               strncpy(src->filename, dst->filename, sizeof(src->filename));
        }
        HEAPfree(dst, 0);
        *dst = *src;
@@ -2190,8 +2185,7 @@ BATassertProps(BAT *b)
                        Hash *hs = NULL;
                        BUN mask;
 
-                       if ((hp = GDKzalloc(sizeof(Heap))) == NULL ||
-                           (hp->filename = GDKmalloc(nmelen + 30)) == NULL) {
+                       if ((hp = GDKzalloc(sizeof(Heap))) == NULL) {
                                if (hp)
                                        GDKfree(hp);
                                fprintf(stderr,
@@ -2199,7 +2193,7 @@ BATassertProps(BAT *b)
                                        "hash table\n");
                                goto abort_check;
                        }
-                       snprintf(hp->filename, nmelen + 30,
+                       snprintf(hp->filename, sizeof(hp->filename),
                                 "%s.hash" SZFMT, nme, MT_getpid());
                        ext = GDKstrdup(hp->filename + nmelen + 1);
                        if (ATOMsize(b->ttype) == 1)
@@ -2213,7 +2207,6 @@ BATassertProps(BAT *b)
                            (hs = HASHnew(hp, b->ttype, BUNlast(b),
                                          mask, BUN_NONE)) == NULL) {
                                GDKfree(ext);
-                               GDKfree(hp->filename);
                                GDKfree(hp);
                                fprintf(stderr,
                                        "#BATassertProps: cannot allocate "
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -30,14 +30,7 @@ unshare_string_heap(BAT *b)
                        return GDK_FAIL;
                h->parentid = b->batCacheid;
                h->farmid = BBPselectfarm(b->batRole, TYPE_str, varheap);
-               if (b->tvheap->filename) {
-                       const char *nme = BBP_physical(b->batCacheid);
-                       h->filename = GDKfilepath(NOFARM, NULL, nme, "theap");
-                       if (h->filename == NULL) {
-                               GDKfree(h);
-                               return GDK_FAIL;
-                       }
-               }
+               snprintf(h->filename, sizeof(h->filename), "%s.theap", 
BBP_physical(b->batCacheid));
                if (HEAPcopy(h, b->tvheap) != GDK_SUCCEED) {
                        HEAPfree(h, 1);
                        GDKfree(h);
@@ -469,14 +462,7 @@ append_varsized_bat(BAT *b, BAT *n, BAT 
                        return GDK_FAIL;
                h->parentid = b->batCacheid;
                h->farmid = BBPselectfarm(b->batRole, b->ttype, varheap);
-               if (b->tvheap->filename) {
-                       const char *nme = BBP_physical(b->batCacheid);
-                       h->filename = GDKfilepath(NOFARM, NULL, nme, "theap");
-                       if (h->filename == NULL) {
-                               GDKfree(h);
-                               return GDK_FAIL;
-                       }
-               }
+               snprintf(h->filename, sizeof(h->filename), "%s.theap", 
BBP_physical(b->batCacheid));
                if (HEAPcopy(h, b->tvheap) != GDK_SUCCEED) {
                        HEAPfree(h, 1);
                        GDKfree(h);
@@ -1131,14 +1117,11 @@ BATkeyed(BAT *b)
                                        mask = (BUN) 1 << 16;
                        }
                        if ((hp = GDKzalloc(sizeof(Heap))) == NULL ||
-                           (hp->filename = GDKmalloc(nmelen + 30)) == NULL ||
-                           snprintf(hp->filename, nmelen + 30,
+                           snprintf(hp->filename, sizeof(hp->filename),
                                     "%s.hash" SZFMT, nme, MT_getpid()) < 0 ||
                            (ext = GDKstrdup(hp->filename + nmelen + 1)) == 
NULL ||
                            (hs = HASHnew(hp, b->ttype, BUNlast(b), mask, 
BUN_NONE)) == NULL) {
                                if (hp) {
-                                       if (hp->filename)
-                                               GDKfree(hp->filename);
                                        GDKfree(hp);
                                }
                                GDKfree(ext);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -567,22 +567,21 @@ fixwkbheap(void)
                GDKfree(newname);
 
                h1 = b->theap;
-               h1.filename = NULL;
                h1.base = NULL;
                h1.dirty = 0;
+               h1.filename[0] = 0;
                h2 = *b->tvheap;
-               h2.filename = NULL;
                h2.base = NULL;
                h2.dirty = 0;
+               h2.filename[0] = 0;
 
                /* load old heaps */
                if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED ||
                    HEAPload(&h2, filename, "theap", 0) != GDK_SUCCEED)
                        GDKfatal("fixwkbheap: cannot load old heaps for BAT 
%d\n", bid);
                /* create new heaps */
-               if ((b->theap.filename = GDKfilepath(NOFARM, NULL, nme, 
"tail")) == NULL ||
-                   (b->tvheap->filename = GDKfilepath(NOFARM, NULL, nme, 
"theap")) == NULL)
-                       GDKfatal("fixwkbheap: out of memory\n");
+               snprintf(b->theap.filename, sizeof(b->theap.filename), 
"%s.tail", nme);
+               snprintf(b->tvheap->filename, sizeof(b->tvheap->filename), 
"%s.theap", nme);
                if (HEAPalloc(&b->theap, b->batCapacity, SIZEOF_VAR_T) != 
GDK_SUCCEED)
                        GDKfatal("fixwkbheap: cannot allocate heap\n");
                b->theap.dirty = TRUE;
@@ -709,9 +708,7 @@ fixstroffheap(BAT *b, int *restrict offs
                h2 = *b->tvheap;
                if (GDKmove(h2.farmid, srcdir, bnme, "theap", BAKDIR, bnme, 
"theap") != GDK_SUCCEED)
                        GDKfatal("fixstroffheap: cannot make backup of 
%s.theap\n", nme);
-               h2.filename = GDKfilepath(NOFARM, NULL, nme, "theap");
-               if (h2.filename == NULL)
-                       GDKfatal("fixstroffheap: GDKmalloc failed\n");
+               snprintf(h2.filename, sizeof(h2.filename), "%s.theap", nme);
                h2.base = NULL;
                if (HEAPalloc(&h2, h2.size, 1) != GDK_SUCCEED)
                        GDKfatal("fixstroffheap: allocating new string heap "
@@ -721,7 +718,7 @@ fixstroffheap(BAT *b, int *restrict offs
                h2.free = b->tvheap->free;
                /* load old offset heap and copy contents to new heap */
                h1 = *b->tvheap;
-               h1.filename = NULL;
+               h1.filename[0] = 0;
                h1.base = NULL;
                h1.dirty = 0;
                if (HEAPload(&h1, filename, "theap", 0) != GDK_SUCCEED)
@@ -748,7 +745,7 @@ fixstroffheap(BAT *b, int *restrict offs
                GDKfatal("fixstroffheap: cannot make backup of %s.tail\n", nme);
        /* load old offset heap */
        h1 = b->theap;
-       h1.filename = NULL;
+       h1.filename[0] = 0;
        h1.base = NULL;
        h1.dirty = 0;
        if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED)
@@ -757,9 +754,7 @@ fixstroffheap(BAT *b, int *restrict offs
 
        /* create new offset heap */
        h3 = b->theap;
-       h3.filename = GDKfilepath(NOFARM, NULL, nme, "tail");
-       if (h3.filename == NULL)
-               GDKfatal("fixstroffheap: GDKmalloc failed\n");
+       snprintf(h3.filename, sizeof(h3.filename), "%s.tail", nme);
        if (HEAPalloc(&h3, b->batCapacity, width) != GDK_SUCCEED)
                GDKfatal("fixstroffheap: allocating new tail heap "
                         "for BAT %d failed\n", b->batCacheid);
@@ -933,7 +928,7 @@ fixfltheap(BAT *b)
                GDKfatal("fixfltheap: cannot make backup of %s.tail\n", nme);
        /* load old heap */
        h1 = b->theap;
-       h1.filename = NULL;
+       h1.filename[0] = 0;
        h1.base = NULL;
        h1.dirty = 0;
        if (HEAPload(&h1, filename, "tail", 0) != GDK_SUCCEED)
@@ -942,9 +937,7 @@ fixfltheap(BAT *b)
 
        /* create new heap */
        h2 = b->theap;
-       h2.filename = GDKfilepath(NOFARM, NULL, nme, "tail");
-       if (h2.filename == NULL)
-               GDKfatal("fixfltheap: GDKmalloc failed\n");
+       snprintf(h2.filename, sizeof(h2.filename), "%s.tail", nme);
        if (HEAPalloc(&h2, b->batCapacity, b->twidth) != GDK_SUCCEED)
                GDKfatal("fixfltheap: allocating new tail heap "
                         "for BAT %d failed\n", b->batCacheid);
@@ -1201,7 +1194,7 @@ heapinit(BAT *b, const char *buf, int *h
        b->theap.free = (size_t) free;
        b->theap.size = (size_t) size;
        b->theap.base = NULL;
-       b->theap.filename = NULL;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to