Changeset: 7768ba63f9b2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/7768ba63f9b2
Modified Files:
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_heap.c
gdk/gdk_string.c
Branch: Jul2021
Log Message:
Use HEAPextend instead of HEAPgrow when we can (i.e. single ref to heap).
diffs (157 lines):
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -556,7 +556,7 @@ BATextend(BAT *b, BUN newcap)
b->theap->filename, b->theap->size, theap_size);
MT_lock_set(&b->theaplock);
if (ATOMIC_GET(&b->theap->refs) == 1) {
- rc = HEAPextend(b->theap, theap_size, true);
+ rc = HEAPextend(b->theap, theap_size, b->batRestricted
== BAT_READ);
} else {
MT_lock_unset(&b->theaplock);
Heap *h = HEAPgrow(b->theap, theap_size);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -56,7 +56,7 @@ unshare_varsized_heap(BAT *b)
* of inserting individual strings. See the comments in the code for
* more information. */
static gdk_return
-insert_string_bat(BAT *b, BAT *n, struct canditer *ci, bool mayshare)
+insert_string_bat(BAT *b, BAT *n, struct canditer *ci, bool force, bool
mayshare)
{
BATiter ni; /* iterator */
size_t toff = ~(size_t) 0; /* tail offset */
@@ -147,14 +147,24 @@ insert_string_bat(BAT *b, BAT *n, struct
(var_t) 1 << 17;
MT_thread_setalgorithm("copy vheap, copy heap");
if (b->tvheap->size < ni.vh->free) {
- Heap *h = HEAPgrow(b->tvheap, ni.vh->free);
- if (h == NULL) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
+ MT_lock_set(&b->theaplock);
+ if (ATOMIC_GET(&b->tvheap->refs) == 1) {
+ if (HEAPextend(b->tvheap, ni.vh->free,
force) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
+ }
+ } else {
+ MT_lock_unset(&b->theaplock);
+ Heap *h = HEAPgrow(b->tvheap,
ni.vh->free);
+ if (h == NULL) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
+ }
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(b->tvheap, false);
+ b->tvheap = h;
}
- MT_lock_set(&b->theaplock);
- HEAPdecref(b->tvheap, false);
- b->tvheap = h;
MT_lock_unset(&b->theaplock);
}
memcpy(b->tvheap->base, ni.vh->base, ni.vh->free);
@@ -200,14 +210,24 @@ insert_string_bat(BAT *b, BAT *n, struct
toff = (toff + GDK_VARALIGN - 1) &
~(GDK_VARALIGN - 1);
/* if in "force" mode, the heap may be
* shared when memory mapped */
- Heap *h = HEAPgrow(b->tvheap, toff +
ni.vh->size);
- if (h == NULL) {
- bat_iterator_end(&ni);
- return GDK_FAIL;
+ MT_lock_set(&b->theaplock);
+ if (ATOMIC_GET(&b->tvheap->refs) == 1) {
+ if (HEAPextend(b->tvheap, toff +
ni.vh->size, force) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
+ }
+ } else {
+ MT_lock_unset(&b->theaplock);
+ Heap *h = HEAPgrow(b->tvheap, toff +
ni.vh->size);
+ if (h == NULL) {
+ bat_iterator_end(&ni);
+ return GDK_FAIL;
+ }
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(b->tvheap, false);
+ b->tvheap = h;
}
- MT_lock_set(&b->theaplock);
- HEAPdecref(b->tvheap, false);
- b->tvheap = h;
MT_lock_unset(&b->theaplock);
MT_thread_setalgorithm("append vheap");
memcpy(b->tvheap->base + toff, ni.vh->base,
ni.vh->free);
@@ -896,7 +916,7 @@ BATappend2(BAT *b, BAT *n, BAT *s, bool
b->tnil |= n->tnil && cnt == ni.count;
}
if (b->ttype == TYPE_str) {
- if (insert_string_bat(b, n, &ci, mayshare) != GDK_SUCCEED) {
+ if (insert_string_bat(b, n, &ci, force, mayshare) !=
GDK_SUCCEED) {
bat_iterator_end(&ni);
return GDK_FAIL;
}
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -1088,12 +1088,21 @@ HEAP_malloc(BAT *b, size_t nbytes)
/* Increase the size of the heap. */
TRC_DEBUG(HEAP, "HEAPextend in HEAP_malloc %s %zu %zu\n",
heap->filename, heap->size, newsize);
- Heap *new = HEAPgrow(heap, newsize);
- if (new == NULL)
- return 0;
MT_lock_set(&b->theaplock);
- HEAPdecref(heap, false);
- b->tvheap = heap = new;
+ if (ATOMIC_GET(&heap->refs) == 1) {
+ if (HEAPextend(heap, newsize, false) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
+ return 0;
+ }
+ } else {
+ MT_lock_unset(&b->theaplock);
+ Heap *new = HEAPgrow(heap, newsize);
+ if (new == NULL)
+ return 0;
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(heap, false);
+ b->tvheap = heap = new;
+ }
MT_lock_unset(&b->theaplock);
heap->free = newsize;
hheader = HEAP_index(heap, 0, HEADER);
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -340,12 +340,21 @@ strPut(BAT *b, var_t *dst, const void *V
return 0;
}
TRC_DEBUG(HEAP, "HEAPextend in strPut %s %zu %zu\n",
h->filename, h->size, newsize);
- Heap *new = HEAPgrow(h, newsize);
- if (new == NULL)
- return 0;
MT_lock_set(&b->theaplock);
- HEAPdecref(h, false);
- b->tvheap = h = new;
+ if (ATOMIC_GET(&h->refs) == 1) {
+ if (HEAPextend(h, newsize, true) != GDK_SUCCEED) {
+ MT_lock_unset(&b->theaplock);
+ return 0;
+ }
+ } else {
+ MT_lock_unset(&b->theaplock);
+ Heap *new = HEAPgrow(h, newsize);
+ if (new == NULL)
+ return 0;
+ MT_lock_set(&b->theaplock);
+ HEAPdecref(h, false);
+ b->tvheap = h = new;
+ }
MT_lock_unset(&b->theaplock);
/* make bucket point into the new heap */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list