Changeset: 72aae5619f56 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/72aae5619f56
Modified Files:
clients/Tests/exports.stable.out
gdk/gdk_align.c
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_bbp.c
gdk/gdk_bbp.h
gdk/gdk_heap.c
gdk/gdk_imprints.c
gdk/gdk_logger_old.c
gdk/gdk_private.h
gdk/gdk_project.c
gdk/gdk_select.c
sql/backends/monet5/sql_statistics.c
Branch: default
Log Message:
Get rid of BBPshare/BBPunshare, instead use a single logical reference per
non-owned heap.
diffs (truncated from 619 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -222,7 +222,6 @@ int BBPrelease(bat b);
int BBPrename(BAT *b, const char *nme);
int BBPretain(bat b);
gdk_return BBPsave(BAT *b);
-void BBPshare(bat b);
gdk_return BBPsync(int cnt, bat *restrict subcommit, BUN *restrict sizes, lng
logno, lng transid);
void BBPtmlock(void);
void BBPtmunlock(void);
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -133,20 +133,9 @@ VIEWcreate(oid seq, BAT *b)
HEAPincref(b->tvheap);
MT_lock_unset(&b->theaplock);
- if (tp)
- BBPshare(tp);
- if (bn->tvheap) {
- assert(bn->tvheap->parentid > 0);
- BBPshare(bn->tvheap->parentid);
- }
-
if (BBPcacheit(bn, true) != GDK_SUCCEED) { /* enter in BBP */
- if (tp)
- BBPunshare(tp);
- if (bn->tvheap) {
- BBPunshare(bn->tvheap->parentid);
+ if (bn->tvheap)
HEAPdecref(bn->tvheap, false);
- }
HEAPdecref(bn->theap, false);
MT_lock_destroy(&bn->theaplock);
MT_lock_destroy(&bn->batIdxLock);
@@ -154,6 +143,9 @@ VIEWcreate(oid seq, BAT *b)
GDKfree(bn);
return NULL;
}
+ BBPretain(bn->theap->parentid);
+ if (bn->tvheap)
+ BBPretain(bn->tvheap->parentid);
TRC_DEBUG(ALGO, ALGOBATFMT " -> " ALGOBATFMT "\n",
ALGOBATPAR(b), ALGOBATPAR(bn));
return bn;
@@ -264,9 +256,14 @@ BATmaterialize(BAT *b, BUN cap)
BATsetcount(b, b->batCount);
BATsetcapacity(b, cap);
MT_lock_unset(&b->theaplock);
+ if (h->parentid != b->batCacheid)
+ BBPrelease(h->parentid);
HEAPdecref(h, false);
- if (vh)
+ if (vh) {
+ if (vh->parentid != b->batCacheid)
+ BBPrelease(vh->parentid);
HEAPdecref(vh, true);
+ }
return GDK_SUCCEED;
}
@@ -330,6 +327,7 @@ void
VIEWdestroy(BAT *b)
{
assert(isVIEW(b));
+ bat tp = 0, tvp = 0;
/* remove any leftover private hash structures */
HASHdestroy(b);
@@ -342,7 +340,8 @@ VIEWdestroy(BAT *b)
/* heaps that are left after VIEWunlink are ours, so need to be
* destroyed (and files deleted) */
if (b->theap) {
- HEAPdecref(b->theap, b->theap->parentid == b->batCacheid);
+ tp = b->theap->parentid;
+ HEAPdecref(b->theap, tp == b->batCacheid);
b->theap = NULL;
}
if (b->tvheap) {
@@ -350,9 +349,14 @@ VIEWdestroy(BAT *b)
* our own (not a view), and then it doesn't make sense
* that the offset heap was a view (at least one of them
* had to be) */
- HEAPdecref(b->tvheap, b->tvheap->parentid == b->batCacheid);
+ tvp = b->tvheap->parentid;
+ HEAPdecref(b->tvheap, tvp == b->batCacheid);
b->tvheap = NULL;
}
MT_lock_unset(&b->theaplock);
+ if (tp != 0 && tp != b->batCacheid)
+ BBPrelease(tp);
+ if (tvp != 0 && tvp != b->batCacheid)
+ BBPrelease(tvp);
BATfree(b);
}
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -589,6 +589,8 @@ BATclear(BAT *b, bool force)
STRMPdestroy(b);
PROPdestroy(b);
+ bat tvp = 0;
+
/* we must dispose of all inserted atoms */
MT_lock_set(&b->theaplock);
if (force && BATatoms[b->ttype].atomDel == NULL) {
@@ -615,6 +617,7 @@ BATclear(BAT *b, bool force)
MT_lock_unset(&b->theaplock);
return GDK_FAIL;
}
+ tvp = b->tvheap->parentid;
ATOMIC_INIT(&th->refs, 1);
HEAPdecref(b->tvheap, false);
b->tvheap = th;
@@ -644,6 +647,8 @@ BATclear(BAT *b, bool force)
b->theap->dirty = true;
BATsettrivprop(b);
MT_lock_unset(&b->theaplock);
+ if (tvp != 0 && tvp != b->batCacheid)
+ BBPrelease(tvp);
return GDK_SUCCEED;
}
@@ -814,6 +819,8 @@ COLcopy(BAT *b, int tt, bool writable, r
if (tt != bn->ttype) {
bn->ttype = tt;
if (bn->tvheap && !ATOMvarsized(tt)) {
+ if (bn->tvheap->parentid != bn->batCacheid)
+ BBPrelease(bn->tvheap->parentid);
HEAPdecref(bn->tvheap, false);
bn->tvheap = NULL;
}
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -40,12 +40,11 @@ unshare_varsized_heap(BAT *b)
}
ATOMIC_INIT(&h->refs, 1);
MT_lock_set(&b->theaplock);
- int parent = b->tvheap->parentid;
Heap *oh = b->tvheap;
b->tvheap = h;
MT_lock_unset(&b->theaplock);
+ BBPrelease(oh->parentid);
HEAPdecref(oh, false);
- BBPunshare(parent);
}
return GDK_SUCCEED;
}
@@ -84,13 +83,14 @@ insert_string_bat(BAT *b, BATiter *ni, s
/* we can share the vheaps, so we then only need to
* append the offsets */
MT_lock_set(&b->theaplock);
- if (b->tvheap->parentid != b->batCacheid)
- BBPunshare(b->tvheap->parentid);
- HEAPdecref(b->tvheap, b->tvheap->parentid == b->batCacheid);
+ bat bid = b->tvheap->parentid;
+ HEAPdecref(b->tvheap, bid == b->batCacheid);
HEAPincref(ni->vh);
b->tvheap = ni->vh;
MT_lock_unset(&b->theaplock);
- BBPshare(ni->vh->parentid);
+ BBPretain(ni->vh->parentid);
+ if (bid != b->batCacheid)
+ BBPrelease(bid);
toff = 0;
MT_thread_setalgorithm("share vheap");
} else {
@@ -356,13 +356,14 @@ append_varsized_bat(BAT *b, BATiter *ni,
* is read-only, we replace b's vheap with a reference
* to n's */
MT_lock_set(&b->theaplock);
- if (b->tvheap->parentid != b->batCacheid)
- BBPunshare(b->tvheap->parentid);
- BBPshare(ni->vh->parentid);
+ bat bid = b->tvheap->parentid;
HEAPdecref(b->tvheap, true);
HEAPincref(ni->vh);
b->tvheap = ni->vh;
MT_lock_unset(&b->theaplock);
+ BBPretain(ni->vh->parentid);
+ if (bid != b->batCacheid)
+ BBPrelease(bid);
}
if (b->tvheap == ni->vh) {
/* if b and n use the same vheap, we only need to copy
@@ -418,13 +419,13 @@ append_varsized_bat(BAT *b, BATiter *ni,
GDKfree(h);
return GDK_FAIL;
}
- bat parid = b->tvheap->parentid;
- BBPunshare(parid);
ATOMIC_INIT(&h->refs, 1);
MT_lock_set(&b->theaplock);
Heap *oh = b->tvheap;
b->tvheap = h;
MT_lock_unset(&b->theaplock);
+ if (oh->parentid != b->batCacheid)
+ BBPrelease(oh->parentid);
HEAPdecref(oh, false);
}
if (BATcount(b) == 0 && BATatoms[b->ttype].atomFix == NULL &&
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -61,13 +61,6 @@
* Bats use have two kinds of references: logical and physical
* (pointer) ones. The logical references are administered by
* BBPretain/BBPrelease, the physical ones by BBPfix/BBPunfix.
- *
- * @item share counting
- * Views use the heaps of there parent bats. To save guard this, the
- * parent has a shared counter, which is incremented and decremented
- * using BBPshare and BBPunshare. These functions make sure the parent
- * is memory resident as required because of the 'pointer' sharing.
- * @end table
*/
#include "monetdb_config.h"
@@ -1306,6 +1299,7 @@ fixhashashbat(BAT *b)
return GDK_FAIL;
}
*h2 = *b->theap;
+ h2->base = NULL;
if (HEAPalloc(h2, b->batCapacity, b->twidth) != GDK_SUCCEED) {
GDKfree(h2);
GDKfree(vh2);
@@ -1917,7 +1911,7 @@ BBPexit(void)
} while (skipped);
GDKfree(BBP_hash);
BBP_hash = NULL;
- // these need to be NULL, otherwise no new ones get created
+ /* these need to be NULL, otherwise no new ones get created */
backup_files = 0;
backup_dir = 0;
backup_subdir = 0;
@@ -2798,24 +2792,12 @@ BBPretain(bat i)
return incref(i, true, lock);
}
-void
-BBPshare(bat parent)
-{
- bool lock = locked_by == 0 || locked_by != MT_getpid();
-
- assert(parent > 0);
- (void) incref(parent, true, lock);
- assert(BBP_refs(parent) > 0);
- (void) BATdescriptor(parent);
-}
-
static inline int
decref(bat i, bool logical, bool lock, const char *func)
{
int refs = 0, lrefs;
bool swap = false;
bool locked = false;
- bat tp = 0, tvp = 0;
int farmid = 0;
BAT *b;
@@ -2854,15 +2836,11 @@ decref(bat i, bool logical, bool lock, c
GDKerror("%s: %s does not have pointer fixes.\n", func,
BBP_logical(i));
assert(0);
} else {
- assert(b == NULL || b->theap == NULL ||
BBP_refs(b->theap->parentid) > 0);
- assert(b == NULL || b->tvheap == NULL ||
BBP_refs(b->tvheap->parentid) > 0);
refs = --BBP_refs(i);
if (b && refs == 0) {
MT_lock_set(&b->theaplock);
locked = true;
- tp = VIEWtparent(b);
- tvp = VIEWvtparent(b);
- if (tp || tvp)
+ if (VIEWtparent(b) || VIEWvtparent(b))
BBP_status_on(i, BBPHOT);
}
}
@@ -2946,10 +2924,6 @@ decref(bat i, bool logical, bool lock, c
BBP_status_off(i, BBPUNLOADING);
}
}
- if (tp)
- decref(tp, false, lock, func);
- if (tvp)
- decref(tvp, false, lock, func);
return refs;
}
@@ -2994,30 +2968,6 @@ BATdescriptor(bat i)
if (BBPcheck(i)) {
bool lock = locked_by == 0 || locked_by != MT_getpid();
- /* parent bats get a single fix for all physical
- * references of a view and in order to do that
- * properly, we must incref the parent bats always
- * before our own incref, then after that decref them if
- * we were not the first */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]