Changeset: c4a9d48c3477 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c4a9d48c3477
Modified Files:
clients/Tests/exports.stable.out
geom/monetdb5/geom_atoms.c
monetdb5/mal/mal_client.c
monetdb5/mal/mal_dataflow.c
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_exception.h
monetdb5/mal/mal_interpreter.c
monetdb5/modules/mal/tablet.c
tools/mserver/mserver5.c
tools/mserver/shutdowntest.c
Branch: resource_management
Log Message:
favour tls allocator for short term allocations
diffs (truncated from 710 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
@@ -390,7 +390,7 @@ gdk_return MT_thread_init_add_callback(v
bool MT_thread_register(void);
void MT_thread_set_qry_ctx(QryCtx *ctx);
void MT_thread_setalgorithm(const char *algo);
-void MT_thread_setallocator(allocator *allocator);
+void MT_thread_setallocator(allocator *ma);
void MT_thread_setdata(void *data);
void MT_thread_setlockwait(MT_Lock *lock);
void MT_thread_setsemawait(MT_Sema *sema);
@@ -891,6 +891,7 @@ char *concatErrors(allocator *ma, char *
const char connectRef[];
const char containsRef[];
str convertConstant(allocator *ma, malType type, ValPtr vr);
+str copyException(allocator *, const char *);
InstrPtr copyInstruction(MalBlkPtr mb, const InstrRecord *p);
InstrPtr copyInstructionArgs(MalBlkPtr mb, const InstrRecord *p, int args);
MalBlkPtr copyMalBlk(MalBlkPtr mb);
diff --git a/geom/monetdb5/geom_atoms.c b/geom/monetdb5/geom_atoms.c
--- a/geom/monetdb5/geom_atoms.c
+++ b/geom/monetdb5/geom_atoms.c
@@ -667,7 +667,7 @@ wkbBox2D(Client ctx, mbr **box, wkb **po
GEOSGeom point1_geom, point2_geom;
double xmin = 0.0, ymin = 0.0, xmax = 0.0, ymax = 0.0;
str err = MAL_SUCCEED;
- allocator *ma = ctx->ma;
+ allocator *ma = ctx->curprg->def->ma;
assert(ma);
//check null input
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
@@ -287,7 +287,7 @@ MCinitClient(oid user, bstream *fin, str
c = MCnewClient();
if (c) {
c = MCinitClientRecord(c, user, fin, fout);
- MT_thread_setallocator(c->ma);
+ //MT_thread_setallocator(c->ma);
MT_thread_set_qry_ctx(&c->qryctx);
}
MT_lock_unset(&mal_contextLock);
@@ -440,7 +440,6 @@ MCcloseClient(Client c)
c->mode = FREECLIENT;
c->idx = -1;
}
- MT_thread_setallocator(NULL);
ma_destroy(c->ma);
c->ta = NULL;
c->ma = NULL;
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -253,8 +253,7 @@ DFLOWworker(void *T)
#endif
GDKsetbuf(t->errbuf); /* where to leave errors */
snprintf(t->s.name, sizeof(t->s.name), "DFLOWsema%04zu", MT_getpid());
- allocator *ma = create_allocator(NULL, "TA_tls", false);
- MT_thread_setallocator(ma);
+ allocator *ma = MT_thread_getallocator();
for (;;) {
DataFlow flow;
@@ -342,7 +341,7 @@ DFLOWworker(void *T)
flow->stk,
0, 0);
if (error)
error = MA_STRDUP(flow->mb->ma, error);
- sa_reset(ma);
+ ma_reset(ma);
ATOMIC_DEC(&flow->cntxt->workers);
/* release the memory claim */
@@ -452,7 +451,6 @@ DFLOWworker(void *T)
}
MT_lock_unset(&dataflowLock);
GDKsetbuf(NULL);
- ma_destroy(ma);
}
/*
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -367,3 +367,11 @@ getExceptionMessage(const char *exceptio
msg += 6;
return msg;
}
+
+inline str
+copyException(allocator *ma, const char *exception)
+{
+ if (exception)
+ return MA_STRDUP(ma, exception);
+ return NULL;
+}
diff --git a/monetdb5/mal/mal_exception.h b/monetdb5/mal/mal_exception.h
--- a/monetdb5/mal/mal_exception.h
+++ b/monetdb5/mal/mal_exception.h
@@ -69,6 +69,7 @@ mal_export enum malexception getExceptio
mal_export str getExceptionPlace(allocator *ma, const char *);
mal_export str getExceptionMessageAndState(const char *);
mal_export str getExceptionMessage(const char *);
+mal_export str copyException(allocator *, const char *);
#include "mal_errors.h"
#endif /* _MAL_EXCEPTION_H */
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -366,14 +366,12 @@ runMAL(Client cntxt, MalBlkPtr mb, MalBl
* been observed due the small size of the function).
*/
}
- allocator *tlsma = MT_thread_getallocator();
- MT_thread_setallocator(mb->ta);
- uint64_t offset = ma_open(mb->ta);
- ret = runMALsequence(mb->ta, cntxt, mb, 1, 0, stk, env, 0);
- if (ret)
- ret = MA_STRDUP(mb->ma, ret);
- ma_close_to(mb->ta, offset);
- MT_thread_setallocator(tlsma);
+ // FIX use tls allocator
+ allocator *ta = mb->ta;
+ assert(ta);
+ uint64_t offset = ma_open(ta);
+ ret = copyException(mb->ma, runMALsequence(ta, cntxt, mb, 1, 0, stk,
env, 0));
+ ma_close_to(ta, offset);
if (!stk->keepAlive && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, env != stk);
@@ -410,14 +408,10 @@ reenterMAL(Client cntxt, MalBlkPtr mb, i
if (stk == NULL)
throw(MAL, "mal.interpreter", MAL_STACK_FAIL);
keepAlive = stk->keepAlive;
- allocator *tlsma = MT_thread_getallocator();
- MT_thread_setallocator(mb->ta);
- uint64_t offset = ma_open(mb->ta);
- ret = runMALsequence(mb->ta, cntxt, mb, startpc, stoppc, stk, 0, 0);
- if (ret)
- ret = MA_STRDUP(mb->ta, ret);
- ma_close_to(mb->ta, offset);
- MT_thread_setallocator(tlsma);
+ allocator *ta = MT_thread_getallocator();
+ ma_open(ta);
+ ret = copyException(mb->ma, runMALsequence(ta, cntxt, mb, startpc,
stoppc, stk, 0, 0));
+ ma_close(ta);
if (keepAlive == 0 && garbageControl(getInstrPtr(mb, 0)))
garbageCollector(cntxt, mb, stk, stk != 0);
@@ -473,7 +467,10 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS
if (lhs->bat)
BBPretain(lhs->val.bval);
}
- ret = runMALsequence(mb->ma, cntxt, mb, 1, 0, stk, 0, 0);
+ allocator *ta = MT_thread_getallocator();
+ ma_open(ta);
+ ret = copyException(mb->ma, runMALsequence(ta, cntxt, mb, 1, 0,
stk, 0, 0));
+ ma_close(ta);
break;
case PATcall:
case CMDcall:
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -638,7 +638,7 @@ tablet_read_more(READERtask *task)
/* note, the column value that is passed here is the 0 based value; the
* lineno value on the other hand is 1 based */
static void
-tablet_error(READERtask *task, lng idx, lng lineno, int col, const char *msg,
+tablet_error(allocator *ma, READERtask *task, lng idx, lng lineno, int col,
const char *msg,
const char *fcn)
{
assert(is_int_nil(col) || col >= 0);
@@ -663,28 +663,28 @@ tablet_error(READERtask *task, lng idx,
} else if (!is_lng_nil(lineno)) {
if (!is_int_nil(col)) {
if (colnam)
- task->as->error = createException(MAL,
"sql.copy_from",
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
"line " LLFMT ": column %d %s: %s",
-
lineno, col + 1, colnam, msg);
+
lineno, col + 1, colnam, msg));
else
- task->as->error = createException(MAL,
"sql.copy_from",
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
"line " LLFMT ": column %d: %s",
-
lineno, col + 1, msg);
+
lineno, col + 1, msg));
} else {
- task->as->error = createException(MAL,
"sql.copy_from",
-
"line " LLFMT ": %s", lineno, msg);
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
+
"line " LLFMT ": %s", lineno, msg));
}
} else {
if (!is_int_nil(col)) {
if (colnam)
- task->as->error = createException(MAL,
"sql.copy_from",
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
"column %d %s: %s", col + 1, colnam,
-
msg);
+
msg));
else
- task->as->error = createException(MAL,
"sql.copy_from",
-
"column %d: %s", col + 1, msg);
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from",
+
"column %d: %s", col + 1, msg));
} else {
- task->as->error = createException(MAL,
"sql.copy_from", "%s", msg);
+ task->as->error = copyException(ma,
createException(MAL, "sql.copy_from", "%s", msg));
}
}
}
@@ -807,7 +807,7 @@ mycpstr(char *t, const char *s, size_t l
}
static str
-SQLload_error(READERtask *task, lng idx, BUN attrs)
+SQLload_error(allocator *ma, READERtask *task, lng idx, BUN attrs)
{
str line;
char *s;
@@ -821,9 +821,9 @@ SQLload_error(READERtask *task, lng idx,
}
sz += task->rseplen + 1;
- s = line = GDKmalloc(sz);
+ s = line = ma_alloc(ma, sz);
if (line == NULL) {
- tablet_error(task, idx, lng_nil, int_nil, "SQLload malloc
error",
+ tablet_error(ma, task, idx, lng_nil, int_nil, "SQLload malloc
error",
"SQLload_error");
return NULL;
}
@@ -880,15 +880,15 @@ SQLinsert_val(allocator *ma, READERtask
lng row = task->cnt + idx + 1;
if (adt == NULL) {
if (task->rowerror) {
- err = SQLload_error(task, idx, task->as->nr_attrs);
+ err = SQLload_error(ma, task, idx, task->as->nr_attrs);
if (s) {
size_t slen = mystrlen(s);
char *scpy = ma_alloc(ma, slen + 1);
if (scpy == NULL) {
- tablet_error(task, idx, row, col,
+ tablet_error(ma, task, idx, row, col,
SQLSTATE(HY013) MAL_MALLOC_FAIL, err);
task->besteffort = false; /* no
longer best effort */
- GDKfree(err);
+ //GDKfree(err);
return -1;
}
mycpstr(scpy, s, slen + 1);
@@ -897,8 +897,8 @@ SQLinsert_val(allocator *ma, READERtask
snprintf(buf, sizeof(buf), "'%s' expected%s%s%s",
fmt->type,
s ? " in '" : "", s ? s : "", s ? "'"
: "");
//GDKfree(s);
- tablet_error(task, idx, row, col, buf, err);
- GDKfree(err);
+ tablet_error(ma, task, idx, row, col, buf, err);
+ //GDKfree(err);
if (!task->besteffort)
return -1;
}
@@ -913,10 +913,10 @@ SQLinsert_val(allocator *ma, READERtask
/* failure */
if (task->rowerror) {
char *msg = GDKerrbuf;
- err = SQLload_error(task, idx, task->as->nr_attrs);
- tablet_error(task, idx, row, col, msg
+ err = SQLload_error(ma, task, idx, task->as->nr_attrs);
+ tablet_error(ma, task, idx, row, col, msg
&& *msg ? msg : "insert failed", err);
- GDKfree(err);
+ //GDKfree(err);
}
task->besteffort = false; /* no longer best effort */
return -1;
@@ -938,7 +938,7 @@ SQLworker_column(READERtask *task, int c
if (!fmt[col].skip
&& BATcapacity(fmt[col].c) < BATcount(fmt[col].c) + task->next)
{
if (BATextend(fmt[col].c, BATgrows(fmt[col].c) + task->limit)
!= GDK_SUCCEED) {
- tablet_error(task, lng_nil, lng_nil, col,
+ tablet_error(ma, task, lng_nil, lng_nil, col,
"Failed to extend the BAT\n",
"SQLworker_column");
MT_lock_unset(&mal_copyLock);
return -1;
@@ -965,7 +965,7 @@ SQLworker_column(READERtask *task, int c
* We also trim the quotes around strings.
*/
static int
-SQLload_parse_row(READERtask *task, int idx)
+SQLload_parse_row(allocator *ma, READERtask *task, int idx)
{
BUN i;
char errmsg[BUFSIZ];
@@ -992,11 +992,11 @@ SQLload_parse_row(READERtask *task, int
row = tablet_skip_string(row + 1, task->quote,
task->escape);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]