Changeset: dc4bb61bb076 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/dc4bb61bb076 Modified Files: gdk/ChangeLog.Dec2023 gdk/gdk_bbp.c gdk/gdk_private.h gdk/gdk_system.c gdk/gdk_system_private.h Branch: Dec2023 Log Message:
Fixed issue where the bat free list was not returned when a thread exited. Also, BBPtrim now more quickly skips over free bats. diffs (121 lines): diff --git a/gdk/ChangeLog.Dec2023 b/gdk/ChangeLog.Dec2023 --- a/gdk/ChangeLog.Dec2023 +++ b/gdk/ChangeLog.Dec2023 @@ -1,6 +1,12 @@ # ChangeLog file for GDK # This file is updated with Maddlog +* Thu Mar 28 2024 Sjoerd Mullender <sjo...@acm.org> +- Threads have their own list of free bats. The list was not returned + to the system when a thread exited, meaning that the free bats that + were in the list would not be reused by any thread. This has been + fixed. + * Mon Mar 18 2024 Sjoerd Mullender <sjo...@acm.org> - Fixed a couple of deadlock situations, one actually observed, one never observed. diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c --- a/gdk/gdk_bbp.c +++ b/gdk/gdk_bbp.c @@ -1721,17 +1721,27 @@ BBPtrim(bool aggressive, bat nbat) int n = 0; int waitctr = 0; bool changed = false; + bool locked = false; unsigned flag = BBPUNLOADING | BBPSYNCING | BBPSAVING; if (!aggressive) flag |= BBPHOT; lng t0 = GDKusec(); for (bat bid = 1; bid < nbat && !GDKexiting(); bid++) { /* don't do this during a (sub)commit */ - BBPtmlock(); + if (!locked) { + BBPtmlock(); + locked = true; + } MT_lock_set(&GDKswapLock(bid)); BAT *b = NULL; bool swap = false; - if (!(BBP_status(bid) & flag) && + unsigned status = BBP_status(bid); + if (status == 0) { + /* quickly skip free bats */ + MT_lock_unset(&GDKswapLock(bid)); + continue; + } + if (!(status & flag) && BBP_refs(bid) == 0 && BBP_lrefs(bid) != 0 && (b = BBP_cache(bid)) != NULL) { @@ -1755,12 +1765,15 @@ BBPtrim(bool aggressive, bat nbat) changed = true; } BBPtmunlock(); + locked = false; /* every once in a while, give others a chance */ if (++waitctr >= 1000) { waitctr = 0; MT_sleep_ms(2); } } + if (locked) + BBPtmunlock(); if (n > 0) TRC_INFO(BAT_, "unloaded %d bats in "LLFMT" usec%s\n", n, GDKusec() - t0, aggressive ? " (also hot)" : ""); return changed; @@ -2958,10 +2971,8 @@ BBPclear(bat i) } void -BBPrelinquish(void) +BBPrelinquish(struct freebats *t) { - struct freebats *t = MT_thread_getfreebats(); - if (t->nfreebats == 0) return; MT_lock_set(&GDKcacheLock); diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -112,8 +112,6 @@ bat BBPinsert(BAT *bn) __attribute__((__visibility__("hidden"))); void BBPprintinfo(void) __attribute__((__visibility__("hidden"))); -void BBPrelinquish(void) - __attribute__((__visibility__("hidden"))); int BBPselectfarm(role_t role, int type, enum heaptype hptype) __attribute__((__visibility__("hidden"))); BUN binsearch(const oid *restrict indir, oid offset, int type, const void *restrict vals, const char * restrict vars, int width, BUN lo, BUN hi, const void *restrict v, int ordering, int last) diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -285,9 +285,10 @@ dump_threads(void) MT_Cond *cn = t->condwait; struct mtthread *jn = t->joinwait; int pos = snprintf(buf, sizeof(buf), - "%s, tid %zu, waiting for %s%s, working on %.200s", + "%s, tid %zu, %"PRIu32" free bats, waiting for %s%s, working on %.200s", t->threadname, t->tid, + t->freebats.nfreebats, lk ? "lock " : sm ? "semaphore " : cn ? "condvar " : jn ? "thread " : "", lk ? lk->name : sm ? sm->name : cn ? cn->name : jn ? jn->threadname : "nothing", ATOMIC_GET(&t->exited) ? "exiting" : @@ -314,6 +315,7 @@ rm_mtthread(struct mtthread *t) struct mtthread **pt; assert(t != &mainthread); + BBPrelinquish(&t->freebats); thread_lock(); for (pt = &mtthreads; *pt && *pt != t; pt = &(*pt)->next) ; diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h --- a/gdk/gdk_system_private.h +++ b/gdk/gdk_system_private.h @@ -45,3 +45,5 @@ struct freebats { }; struct freebats *MT_thread_getfreebats(void) __attribute__((__visibility__("hidden"))); +void BBPrelinquish(struct freebats *t) + __attribute__((__visibility__("hidden"))); _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org