Changeset: b9daead4c540 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b9daead4c540
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk_private.h
        gdk/gdk_system.c
        gdk/gdk_utils.h
        monetdb5/mal/mal_client.c
        sql/backends/monet5/sql_scenario.c
        sql/storage/store.c
Branch: resource_management
Log Message:

No point printing per-thread allocator info if it's identical for all threads.
Also, the allocator size is already included in the client allocator
info.
And apart from all this, this fixes a use after free bug if the info is
getting printed while threads are exiting.


diffs (135 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
@@ -534,6 +534,7 @@ struct tm *gmtime_r(const time_t *restri
 ssize_t hgeFromStr(allocator *ma, const char *src, size_t *len, hge **dst, 
bool external);
 ssize_t hgeToStr(allocator *ma, str *dst, size_t *len, const hge *src, bool 
external);
 const hge hge_nil;
+char *humansize(size_t val, char *buf, size_t buflen) 
__attribute__((__access__(write_only, 2, 3)));
 const inet4 inet4_nil;
 const inet6 inet6_nil;
 ssize_t intFromStr(allocator *ma, const char *src, size_t *len, int **dst, 
bool external);
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -241,8 +241,6 @@ void HEAP_recover(Heap *, const var_t *,
 gdk_return HEAPsave(Heap *h, const char *nme, const char *ext, bool dosync, 
BUN free, MT_Lock *lock)
        __attribute__((__warn_unused_result__))
        __attribute__((__visibility__("hidden")));
-char *humansize(size_t val, char *buf, size_t buflen)
-       __attribute__((__visibility__("hidden")));
 double joincost(BAT *r, BUN lcount, struct canditer *rci, bool *hash, bool 
*phash, bool *cand)
        __attribute__((__visibility__("hidden")));
 void STRMPincref(Strimps *strimps)
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -195,7 +195,7 @@ struct thread_funcs {
 };
 
 struct mtthread {
-       allocator* thread_allocator;
+       allocator *thread_allocator;
        struct mtthread *next;
        void (*func) (void *);  /* function to be called */
        void *data;             /* and its data */
@@ -298,7 +298,6 @@ void
 dump_threads(void)
 {
        char buf[1024];
-       char abuf[128]; // allocator buffer
 #if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(HAVE_CLOCK_GETTIME)
        struct timespec ts;
        clock_gettime(CLOCK_REALTIME, &ts);
@@ -324,17 +323,6 @@ dump_threads(void)
                MT_Cond *cn = t->condwait;
                struct mtthread *jn = t->joinwait;
                const char *working = ATOMIC_PTR_GET(&t->working);
-               if (t->thread_allocator) {
-                       const char *name =
-                               sa_name(t->thread_allocator);
-                       snprintf(abuf, sizeof(abuf),
-                                       ", %s allocator %zu bytes",
-                                       name ? name : "(unknown)",
-                                       sa_size(t->thread_allocator));
-
-               }
-               else
-                       abuf[0] = 0;
 
                int pos = snprintf(buf, sizeof(buf),
                                   "%s, tid %zu, "
@@ -344,7 +332,7 @@ dump_threads(void)
 #ifdef HAVE_GETTID
                                   "LWP %ld, "
 #endif
-                                  "%"PRIu32" free bats, waiting for %s%s, 
working on %.200s%s",
+                                  "%"PRIu32" free bats, waiting for %s%s, 
working on %.200s",
                                   t->threadname,
                                   t->tid,
 #ifdef HAVE_PTHREAD_H
@@ -357,7 +345,7 @@ dump_threads(void)
                                   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" :
-                                  working ? working : "nothing", abuf);
+                                  working ? working : "nothing");
 #ifdef LOCK_OWNER
                const char *sep = ", locked: ";
                for (MT_Lock *l = t->mylocks; l && pos < (int) sizeof(buf); l = 
l->nxt) {
diff --git a/gdk/gdk_utils.h b/gdk/gdk_utils.h
--- a/gdk/gdk_utils.h
+++ b/gdk/gdk_utils.h
@@ -110,6 +110,8 @@ gdk_export str GDKstrndup(const char *s,
        __attribute__((__malloc__(GDKfree, 1)))
        __attribute__((__warn_unused_result__));
 gdk_export size_t GDKmallocated(const void *s);
+gdk_export char *humansize(size_t val, char *buf, size_t buflen)
+       __attribute__((__access__(write_only, 2, 3)));
 
 gdk_export void MT_init(void); /*  init the package. */
 struct opt;
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -437,10 +437,10 @@ MCcloseClient(Client c)
                c->mode = FREECLIENT;
                c->idx = -1;
        }
+       MT_thread_setallocator(NULL);
        ma_destroy(c->ma);
        c->ta = NULL;
        c->ma = NULL;
-       MT_thread_setallocator(NULL);
        MT_lock_unset(&mal_contextLock);
 }
 
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -175,10 +175,10 @@ CLIENTprintinfo(void)
                                        ma_used += sa_size(be->mvc->pa);
                        }
                        if (ma_used)
-                               snprintf(mabuf, sizeof(mabuf), ", Allocators 
combined: %zu bytes", ma_used);
+                               snprintf(mabuf, sizeof(mabuf), ", allocators 
combined: %zu%s bytes", ma_used, humansize(ma_used, (char[24]){0}, 24));
                        else
                                mabuf[0] = 0;
-                       printf("client %d, user %s, thread %s, using %"PRIu64" 
bytes of transient space%s%s%s%s%s%s%s%s%s%s\n", c->idx, c->username, 
c->mythread ? c->mythread : "?", (uint64_t) ATOMIC_GET(&c->qryctx.datasize), 
mmbuf, tmbuf, trbuf, chbuf, cabuf, clbuf, cpbuf, crbuf, qybuf, mabuf);
+                       printf("client %d, user %s, thread %s, using %"PRIu64" 
bytes of transient space%s%s%s%s%s%s%s%s%s%s\n", c->idx, c->username, 
c->mythread ? c->mythread : "?", (uint64_t) ATOMIC_GET(&c->qryctx.datasize), 
mmbuf, mabuf, tmbuf, trbuf, chbuf, cabuf, clbuf, cpbuf, crbuf, qybuf);
                        break;
                case FINISHCLIENT:
                        /* finishing */
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -7881,7 +7881,8 @@ store_printinfo(sqlstore *store)
        }
        printf("WAL:\n");
        printf("SQL store oldest pending "ULLFMT"\n", store->oldest_pending);
-       printf("SQL store allocator: %zu bytes\n", sa_size(store->sa));
+       size_t sz = sa_size(store->sa);
+       printf("SQL store allocator: %zu%s\n", sz, humansize(sz, (char[24]){0}, 
24));
        log_printinfo(store->logger);
        MT_lock_unset(&store->commit);
 }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to