Changeset: 5b855158dbe6 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/5b855158dbe6 Modified Files: gdk/gdk_bbp.c gdk/gdk_hash.c gdk/gdk_heap.c gdk/gdk_imprints.c gdk/gdk_orderidx.c gdk/gdk_storage.c gdk/gdk_strimps.c Branch: default Log Message:
Merge with Sep2022 branch. diffs (truncated from 349 to 300 lines): diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c --- a/gdk/gdk_align.c +++ b/gdk/gdk_align.c @@ -203,7 +203,7 @@ BATmaterialize(BAT *b, BUN cap) .dirty = true, }; settailname(tail, BBP_physical(b->batCacheid), TYPE_oid, 0); - if (HEAPalloc(tail, cap, sizeof(oid), 0) != GDK_SUCCEED) { + if (HEAPalloc(tail, cap, sizeof(oid)) != GDK_SUCCEED) { GDKfree(tail); return GDK_FAIL; } diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -280,7 +280,7 @@ COLnew2(oid hseq, int tt, BUN cap, role_ cap /= 8; /* 8 values per byte */ /* alloc the main heaps */ - if (tt && HEAPalloc(bn->theap, cap, bn->twidth, ATOMsize(bn->ttype)) != GDK_SUCCEED) { + if (tt && HEAPalloc(bn->theap, cap, bn->twidth) != GDK_SUCCEED) { goto bailout; } diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -84,6 +84,16 @@ #ifndef S_ISDIR #define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR) #endif +#ifndef O_CLOEXEC +#ifdef _O_NOINHERIT +#define O_CLOEXEC _O_NOINHERIT /* Windows */ +#else +#define O_CLOEXEC 0 +#endif +#endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif /* * The BBP has a fixed address, so re-allocation due to a growing BBP @@ -907,7 +917,6 @@ BBPcheckbats(unsigned bbpversion) path = GDKfilepath(0, BATDIR, b->theap->filename, NULL); if (path == NULL) return GDK_FAIL; -#if 1 /* first check string offset heap with width, * then without */ if (MT_stat(path, &statb) < 0) { @@ -932,44 +941,22 @@ BBPcheckbats(unsigned bbpversion) return GDK_FAIL; } } -#else - /* first check string offset heap without width, - * then with */ -#ifdef GDKLIBRARY_TAILN - /* if bbpversion > GDKLIBRARY_TAILN, the offset heap can - * exist with either name .tail1 (etc) or .tail, if <= - * GDKLIBRARY_TAILN, only with .tail */ - char tailsave = 0; - size_t taillen = 0; - if (b->ttype == TYPE_str && - b->twidth < SIZEOF_VAR_T) { - /* old version: .tail, not .tail1, .tail2, .tail4 */ - taillen = strlen(path) - 1; - tailsave = path[taillen]; - path[taillen] = 0; - } -#endif - if (MT_stat(path, &statb) < 0 -#ifdef GDKLIBRARY_TAILN - && bbpversion > GDKLIBRARY_TAILN - && b->ttype == TYPE_str - && b->twidth < SIZEOF_VAR_T - && (path[taillen] = tailsave) != 0 - && MT_stat(path, &statb) < 0 -#endif - ) { - - GDKsyserror("cannot stat file %s (expected size %zu)\n", - path, b->theap->free); - GDKfree(path); - return GDK_FAIL; - } -#endif if ((size_t) statb.st_size < b->theap->free) { GDKerror("file %s too small (expected %zu, actual %zu)\n", path, b->theap->free, (size_t) statb.st_size); GDKfree(path); return GDK_FAIL; } + size_t hfree = b->theap->free; + hfree = (hfree + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize - 1); + if (hfree == 0) + hfree = GDK_mmap_pagesize; + if (statb.st_size > (off_t) hfree) { + int fd; + if ((fd = MT_open(path, O_RDWR | O_CLOEXEC | O_BINARY)) >= 0) { + (void) ftruncate(fd, hfree); + (void) close(fd); + } + } GDKfree(path); } if (b->tvheap != NULL && b->tvheap->free > 0) { @@ -987,6 +974,17 @@ BBPcheckbats(unsigned bbpversion) GDKfree(path); return GDK_FAIL; } + size_t hfree = b->tvheap->free; + hfree = (hfree + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize - 1); + if (hfree == 0) + hfree = GDK_mmap_pagesize; + if (statb.st_size > (off_t) hfree) { + int fd; + if ((fd = MT_open(path, O_RDWR | O_CLOEXEC | O_BINARY)) >= 0) { + (void) ftruncate(fd, hfree); + (void) close(fd); + } + } GDKfree(path); } } @@ -1269,7 +1267,7 @@ fixhashashbat(BAT *b) return GDK_FAIL; } *h2 = *b->theap; - if (HEAPalloc(h2, b->batCapacity, b->twidth, 0) != GDK_SUCCEED) { + if (HEAPalloc(h2, b->batCapacity, b->twidth) != GDK_SUCCEED) { GDKfree(h2); GDKfree(vh2); GDKfree(srcdir); diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c --- a/gdk/gdk_cand.c +++ b/gdk/gdk_cand.c @@ -1309,7 +1309,7 @@ BATnegcands(BUN nr, BAT *odels) strconcat_len(dels->filename, sizeof(dels->filename), nme, ".theap", NULL); - if (HEAPalloc(dels, hi - lo + (sizeof(ccand_t)/sizeof(oid)), sizeof(oid), 0) != GDK_SUCCEED) { + if (HEAPalloc(dels, hi - lo + (sizeof(ccand_t)/sizeof(oid)), sizeof(oid)) != GDK_SUCCEED) { GDKfree(dels); BBPreclaim(bn); return NULL; @@ -1376,7 +1376,7 @@ BATmaskedcands(oid hseq, BUN nr, BAT *ma nme, ".theap", NULL); nmask = (nr + 31) / 32; - if (HEAPalloc(msks, nmask + (sizeof(ccand_t)/sizeof(uint32_t)), sizeof(uint32_t), 0) != GDK_SUCCEED) { + if (HEAPalloc(msks, nmask + (sizeof(ccand_t)/sizeof(uint32_t)), sizeof(uint32_t)) != GDK_SUCCEED) { GDKfree(msks); BBPreclaim(bn); return NULL; @@ -1488,7 +1488,7 @@ BATunmask(BAT *b) HEAPalloc(dels, cnt * 32 - bi.count + sizeof(ccand_t) / sizeof(oid), - sizeof(oid), 0) != GDK_SUCCEED) { + sizeof(oid)) != GDK_SUCCEED) { GDKfree(dels); BBPreclaim(bn); bat_iterator_end(&bi); diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c --- a/gdk/gdk_hash.c +++ b/gdk/gdk_hash.c @@ -140,13 +140,13 @@ HASHnew(Hash *h, int tpe, BUN size, BUN h->width = HASHwidth(size); if (!bcktonly) { - if (HEAPalloc(&h->heaplink, size, h->width, 0) != GDK_SUCCEED) + if (HEAPalloc(&h->heaplink, size, h->width) != GDK_SUCCEED) return GDK_FAIL; h->heaplink.free = size * h->width; h->heaplink.dirty = true; h->Link = h->heaplink.base; } - if (HEAPalloc(&h->heapbckt, mask + HASH_HEADER_SIZE * SIZEOF_SIZE_T / h->width, h->width, 0) != GDK_SUCCEED) + if (HEAPalloc(&h->heapbckt, mask + HASH_HEADER_SIZE * SIZEOF_SIZE_T / h->width, h->width) != GDK_SUCCEED) return GDK_FAIL; h->heapbckt.free = mask * h->width + HASH_HEADER_SIZE * SIZEOF_SIZE_T; h->heapbckt.dirty = true; @@ -778,7 +778,7 @@ BAThash_impl(BAT *restrict b, struct can strconcat_len(h->heapbckt.filename, sizeof(h->heapbckt.filename), nme, ".", ext, "b", NULL); if (HEAPalloc(&h->heaplink, hascand ? ci->ncand : BATcapacity(b), - h->width, 0) != GDK_SUCCEED) { + h->width) != GDK_SUCCEED) { GDKfree(h); bat_iterator_end(&bi); return NULL; diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c --- a/gdk/gdk_heap.c +++ b/gdk/gdk_heap.c @@ -107,7 +107,7 @@ HEAPgrow(Heap **hp, size_t size, bool ma .wasempty = old->wasempty, }; memcpy(new->filename, old->filename, sizeof(new->filename)); - if (HEAPalloc(new, size, 1, 1) == GDK_SUCCEED) { + if (HEAPalloc(new, size, 1) == GDK_SUCCEED) { ATOMIC_INIT(&new->refs, 1 | (refs & HEAPREMOVE)); new->free = old->free; new->cleanhash = old->cleanhash; @@ -137,9 +137,8 @@ HEAPgrow(Heap **hp, size_t size, bool ma * Windows, it actually always performs I/O which is not nice). */ gdk_return -HEAPalloc(Heap *h, size_t nitems, size_t itemsize, size_t itemsizemmap) +HEAPalloc(Heap *h, size_t nitems, size_t itemsize) { - (void) itemsizemmap; h->base = NULL; h->size = 1; if (itemsize) { @@ -459,7 +458,7 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c .wasempty = old->wasempty, }; settailname(new, BBP_physical(b->batCacheid), b->ttype, width); - if (HEAPalloc(new, newsize, 1, 1) != GDK_SUCCEED) { + if (HEAPalloc(new, newsize, 1) != GDK_SUCCEED) { GDKfree(new); return GDK_FAIL; } @@ -563,7 +562,7 @@ HEAPcopy(Heap *dst, Heap *src, size_t of { if (offset > src->free) offset = src->free; - if (HEAPalloc(dst, src->free - offset, 1, 1) == GDK_SUCCEED) { + if (HEAPalloc(dst, src->free - offset, 1) == GDK_SUCCEED) { dst->free = src->free - offset; memcpy(dst->base, src->base + offset, src->free - offset); dst->cleanhash = src->cleanhash; @@ -999,7 +998,7 @@ HEAP_initialize(Heap *heap, size_t nbyte size_t total = 100 + nbytes + nprivate + sizeof(HEADER) + sizeof(CHUNK); total = roundup_8(total); - if (HEAPalloc(heap, total, 1, 1) != GDK_SUCCEED) + if (HEAPalloc(heap, total, 1) != GDK_SUCCEED) return GDK_FAIL; heap->free = heap->size; } diff --git a/gdk/gdk_imprints.c b/gdk/gdk_imprints.c --- a/gdk/gdk_imprints.c +++ b/gdk/gdk_imprints.c @@ -564,7 +564,7 @@ BATimprints(BAT *b) pages * (imprints->bits / 8) + /* imps */ sizeof(uint64_t) + /* padding for alignment */ pages * sizeof(cchdc_t), /* dict */ - 1, 1) != GDK_SUCCEED) { + 1) != GDK_SUCCEED) { MT_lock_unset(&b->batIdxLock); bat_iterator_end(&bi); GDKfree(imprints); diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c --- a/gdk/gdk_orderidx.c +++ b/gdk/gdk_orderidx.c @@ -144,7 +144,7 @@ createOIDXheap(BAT *b, bool stable) strconcat_len(m->filename, sizeof(m->filename), BBP_physical(b->batCacheid), ".torderidx", NULL) >= sizeof(m->filename) || - HEAPalloc(m, BATcount(b) + ORDERIDXOFF, SIZEOF_OID, 0) != GDK_SUCCEED) { + HEAPalloc(m, BATcount(b) + ORDERIDXOFF, SIZEOF_OID) != GDK_SUCCEED) { GDKfree(m); return NULL; } @@ -371,7 +371,7 @@ GDKmergeidx(BAT *b, BAT**a, int n_ar) (m->farmid = BBPselectfarm(b->batRole, bi.type, orderidxheap)) < 0 || strconcat_len(m->filename, sizeof(m->filename), nme, ".torderidx", NULL) >= sizeof(m->filename) || - HEAPalloc(m, BATcount(b) + ORDERIDXOFF, SIZEOF_OID, 0) != GDK_SUCCEED) { + HEAPalloc(m, BATcount(b) + ORDERIDXOFF, SIZEOF_OID) != GDK_SUCCEED) { GDKfree(m); MT_lock_unset(&b->batIdxLock); bat_iterator_end(&bi); diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -194,7 +194,7 @@ BUN HASHmask(BUN cnt) __attribute__((__visibility__("hidden"))); gdk_return HASHnew(Hash *h, int tpe, BUN size, BUN mask, BUN count, bool bcktonly) __attribute__((__visibility__("hidden"))); -gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize, size_t itemsizemmap) +gdk_return HEAPalloc(Heap *h, size_t nitems, size_t itemsize) __attribute__((__warn_unused_result__)) __attribute__((__visibility__("hidden"))); gdk_return HEAPcopy(Heap *dst, Heap *src, size_t offset) diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c --- a/gdk/gdk_storage.c +++ b/gdk/gdk_storage.c @@ -801,7 +801,7 @@ BATload_intern(bat bid, bool lock) if (b->ttype != TYPE_void) { b->theap->storage = b->theap->newstorage = STORE_INVALID; if ((b->batCount == 0 ? - HEAPalloc(b->theap, b->batCapacity, b->twidth, ATOMsize(b->ttype)) : + HEAPalloc(b->theap, b->batCapacity, b->twidth) : HEAPload(b->theap, b->theap->filename, NULL, b->batRestricted == BAT_READ)) != GDK_SUCCEED) { HEAPfree(b->theap, false); return NULL; _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org