Changeset: 74de688903fd for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/74de688903fd
Modified Files:
gdk/gdk_bbp.c
gdk/gdk_private.h
gdk/gdk_storage.c
Branch: default
Log Message:
Merge with Jan2022 branch.
diffs (191 lines):
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -515,7 +515,14 @@ heapinit(BAT *b, const char *buf,
/* (properties & 0x0200) is the old tdense flag */
b->tseqbase = (properties & 0x0200) == 0 || base >= (uint64_t) oid_nil
? oid_nil : (oid) base;
b->theap->free = (size_t) free;
- b->theap->size = (size_t) size;
+ /* set heap size to match capacity */
+ if (b->ttype == TYPE_msk) {
+ /* round up capacity to multiple of 32 */
+ b->batCapacity = (b->batCapacity + 31) & ~((BUN) 31);
+ b->theap->size = b->batCapacity / 8;
+ } else {
+ b->theap->size = (size_t) b->batCapacity << b->tshift;
+ }
b->theap->base = NULL;
settailname(b->theap, filename, t, width);
b->theap->storage = STORE_INVALID;
@@ -531,10 +538,6 @@ heapinit(BAT *b, const char *buf,
b->tmaxpos = (BUN) maxpos;
else
b->tmaxpos = BUN_NONE;
- if (b->theap->free > b->theap->size) {
- TRC_CRITICAL(GDK, "\"free\" value larger than \"size\" in heap
of bat %d on line %d\n", (int) bid, lineno);
- return -1;
- }
return n;
}
@@ -558,6 +561,13 @@ vheapinit(BAT *b, const char *buf, bat b
TRC_CRITICAL(GDK, "cannot allocate memory for heap.");
return -1;
}
+ if (ATOMstorage(b->ttype) == TYPE_str &&
+ free < GDK_STRHASHTABLE * sizeof(stridx_t) + BATTINY *
GDK_VARALIGN)
+ size = GDK_STRHASHTABLE * sizeof(stridx_t) + BATTINY *
GDK_VARALIGN;
+ else if (free < 512)
+ size = 512;
+ else
+ size = free;
*b->tvheap = (Heap) {
.free = (size_t) free,
.size = (size_t) size,
@@ -572,10 +582,6 @@ vheapinit(BAT *b, const char *buf, bat b
strconcat_len(b->tvheap->filename, sizeof(b->tvheap->filename),
filename, ".theap", NULL);
ATOMIC_INIT(&b->tvheap->refs, 1);
- if (b->tvheap->free > b->tvheap->size) {
- TRC_CRITICAL(GDK, "\"free\" value larger than \"size\"
in var heap of bat %d on line %d\n", (int) bid, lineno);
- return -1;
- }
}
return n;
}
@@ -680,7 +686,8 @@ BBPreadEntries(FILE *fp, unsigned bbpver
bn->batRestricted = (properties & 0x06) >> 1;
bn->batCount = (BUN) count;
bn->batInserted = bn->batCount;
- bn->batCapacity = (BUN) capacity;
+ /* set capacity to at least count */
+ bn->batCapacity = (BUN) count <= BATTINY ? BATTINY : (BUN)
count;
char name[MT_NAME_LEN];
snprintf(name, sizeof(name), "heaplock%d", bn->batCacheid); /*
fits */
MT_lock_init(&bn->theaplock, name);
@@ -1805,8 +1812,9 @@ BBPexit(void)
* reclaimed as well.
*/
static inline int
-heap_entry(FILE *fp, BAT *b, BUN size, BATiter *bi)
+heap_entry(FILE *fp, BATiter *bi, BUN size)
{
+ BAT *b = bi->b;
size_t free = bi->hfree;
if (size < BUN_NONE) {
if ((bi->type >= 0 && ATOMstorage(bi->type) == TYPE_msk))
@@ -1818,7 +1826,7 @@ heap_entry(FILE *fp, BAT *b, BUN size, B
}
if ((GDKdebug & TAILCHKMASK) && free > 0) {
- char *fname = GDKfilepath(0, BATDIR,
BBP_physical(b->batCacheid), gettailname(b));
+ char *fname = GDKfilepath(0, BATDIR,
BBP_physical(b->batCacheid), gettailnamebi(bi));
if (fname != NULL) {
struct stat stb;
if (stat(fname, &stb) == -1) {
@@ -1857,18 +1865,18 @@ heap_entry(FILE *fp, BAT *b, BUN size, B
}
static inline int
-vheap_entry(FILE *fp, Heap *h, BUN size, BATiter *bi)
+vheap_entry(FILE *fp, BATiter *bi, BUN size)
{
(void) size;
- if (h == NULL)
+ if (bi->vh == NULL)
return 0;
if ((GDKdebug & TAILCHKMASK) && size > 0) {
- char *fname = GDKfilepath(0, BATDIR, BBP_physical(h->parentid),
"theap");
+ char *fname = GDKfilepath(0, BATDIR,
BBP_physical(bi->vh->parentid), "theap");
if (fname != NULL) {
struct stat stb;
if (stat(fname, &stb) == -1) {
assert(0);
- TRC_WARNING(GDK, "file %s not found (expected
size %zu)\n", fname, h->free);
+ TRC_WARNING(GDK, "file %s not found (expected
size %zu)\n", fname, bi->vhfree);
} else if ((size_t) stb.st_size < bi->vhfree) {
/* no assert since this can actually happen */
TRC_WARNING(GDK, "file %s too small (expected
%zu, actual %zu)\n", fname, bi->vhfree, (size_t) stb.st_size);
@@ -1876,7 +1884,7 @@ vheap_entry(FILE *fp, Heap *h, BUN size,
GDKfree(fname);
}
}
- return fprintf(fp, " %zu %zu %d", bi->vhfree, h->size, 0);
+ return fprintf(fp, " %zu %zu %d", bi->vhfree, bi->vh->size, 0);
}
static gdk_return
@@ -1885,16 +1893,16 @@ new_bbpentry(FILE *fp, bat i, BUN size,
#ifndef NDEBUG
assert(i > 0);
assert(i < (bat) ATOMIC_GET(&BBPsize));
- assert(BBP_desc(i));
- assert(BBP_desc(i)->batCacheid == i);
- assert(BBP_desc(i)->batRole == PERSISTENT);
- assert(0 <= BBP_desc(i)->theap->farmid && BBP_desc(i)->theap->farmid <
MAXFARMS);
- assert(BBPfarms[BBP_desc(i)->theap->farmid].roles & (1U << PERSISTENT));
- if (BBP_desc(i)->tvheap) {
- assert(0 <= BBP_desc(i)->tvheap->farmid &&
BBP_desc(i)->tvheap->farmid < MAXFARMS);
- assert(BBPfarms[BBP_desc(i)->tvheap->farmid].roles & (1U <<
PERSISTENT));
+ assert(bi->b);
+ assert(bi->b->batCacheid == i);
+ assert(bi->b->batRole == PERSISTENT);
+ assert(0 <= bi->h->farmid && bi->h->farmid < MAXFARMS);
+ assert(BBPfarms[bi->h->farmid].roles & (1U << PERSISTENT));
+ if (bi->vh) {
+ assert(0 <= bi->vh->farmid && bi->vh->farmid < MAXFARMS);
+ assert(BBPfarms[bi->vh->farmid].roles & (1U << PERSISTENT));
}
- assert(size <= BBP_desc(i)->batCount || size == BUN_NONE);
+ assert(size <= bi->count || size == BUN_NONE);
#endif
if (size > bi->count)
@@ -1905,12 +1913,12 @@ new_bbpentry(FILE *fp, bat i, BUN size,
BBP_status(i) & BBPPERSISTENT,
BBP_logical(i),
BBP_physical(i),
- BBP_desc(i)->batRestricted << 1,
+ bi->b->batRestricted << 1,
size,
- BBP_desc(i)->batCapacity,
- BBP_desc(i)->hseqbase) < 0 ||
- heap_entry(fp, BBP_desc(i), size, bi) < 0 ||
- vheap_entry(fp, BBP_desc(i)->tvheap, size, bi) < 0 ||
+ bi->b->batCapacity,
+ bi->b->hseqbase) < 0 ||
+ heap_entry(fp, bi, size) < 0 ||
+ vheap_entry(fp, bi, size) < 0 ||
(BBP_options(i) && fprintf(fp, " %s", BBP_options(i)) < 0) ||
fprintf(fp, "\n") < 0) {
GDKsyserror("new_bbpentry: Writing BBP.dir entry failed\n");
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -282,6 +282,26 @@ void VIEWdestroy(BAT *b)
BAT *virtualize(BAT *bn)
__attribute__((__visibility__("hidden")));
+static inline const char *
+gettailnamebi(const BATiter *bi)
+{
+ if (bi->type == TYPE_str) {
+ switch (bi->width) {
+ case 1:
+ return "tail1";
+ case 2:
+ return "tail2";
+#if SIZEOF_VAR_T == 8
+ case 4:
+ return "tail4";
+#endif
+ default:
+ break;
+ }
+ }
+ return "tail";
+}
+
static inline bool
imprintable(int tpe)
{
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]