Changeset: 05dcbea93816 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=05dcbea93816
Modified Files:
monetdb5/mal/Tests/recycle01.mal
monetdb5/mal/Tests/recycle02.mal
monetdb5/mal/mal_recycle.c
Branch: default
Log Message:
Recycler code/test reshuffles
diffs (270 lines):
diff --git a/monetdb5/mal/Tests/recycle01.mal b/monetdb5/mal/Tests/recycle01.mal
--- a/monetdb5/mal/Tests/recycle01.mal
+++ b/monetdb5/mal/Tests/recycle01.mal
@@ -48,10 +48,6 @@ optimizer.recycler("user","qry");
mdb.list("user","qry");
io.print("start");
qry(1,10);
-io.print("zoom in");
-qry(1,5);
-io.print("next step");
-qry(2,3);
-io.print("last");
-qry(1,11);
+io.print("reuse BAT");
+qry(1,10);
recycle.dump();
diff --git a/monetdb5/mal/Tests/recycle02.mal b/monetdb5/mal/Tests/recycle02.mal
--- a/monetdb5/mal/Tests/recycle02.mal
+++ b/monetdb5/mal/Tests/recycle02.mal
@@ -1,9 +1,9 @@
#test the basics of the recycler
-# re-use joins temporal constrainted
+#reusing select results
module sql;
function sql.mvc():int;
- return mvc:=1;
+ return mvc:=1;
end mvc;
function sql.tid(mvc:int,s:str,t:str):bat[:oid,:oid];
@@ -12,10 +12,11 @@ barrier i:= 0:oid;
bat.append(b,i);
redo i:= iterator.next(1:oid,11:oid);
exit i;
+ io.print(tid);
return tid:= b;
end tid;
-function sql.bind(m:int,s:str,t:str,c:str,i:int):bat[:oid,:int];
+function sql.bind(mvc:int, s:str,t:str,c:str,i:int):bat[:oid,:int];
b:= bat.new(:oid,:int);
bat.insert(b,0@0,0);
bat.insert(b,1@0,1);
@@ -29,16 +30,18 @@ function sql.bind(m:int,s:str,t:str,c:st
bat.insert(b,9@0,9);
bat.insert(b,10@0,10);
bat.insert(b,11@0,11);
+ io.print(b);
return bind:=b;
end bind;
function qry(low:int, hgh:int);
- m:= sql.mvc();
- x:bat[:oid,:oid] := sql.tid(m,"sys","tbl");
- b:bat[:oid,:int]:= sql.bind(m,"sys","tbl","col",0);
- s1:= algebra.subselect(b,x,low,hgh,true,true,false);
- j:= algebra.join(s1,b);
- io.print(j);
+ m:= sql.mvc();
+ x:bat[:oid,:oid] := sql.tid(m,"sys","tbl");
+ io.print(x);
+ b:bat[:oid,:int]:= sql.bind(m,"sys","tbl","col",0);
+ io.print(b);
+ s:= algebra.subselect(b,x,low,hgh,true,true,false);
+ io.print(s);
end qry;
optimizer.recycler("user","qry");
diff --git a/monetdb5/mal/mal_recycle.c b/monetdb5/mal/mal_recycle.c
--- a/monetdb5/mal/mal_recycle.c
+++ b/monetdb5/mal/mal_recycle.c
@@ -133,6 +133,22 @@ static str subselectRef = 0, thetasubsel
*/
RecyclePool recyclePool = NULL;
+/*
+ * The Recycle catalog is a global structure, which should be
+ * protected with locks when updated.
+ * The recycle statistics can be kept in the performance table
+ * associated with the recycle MAL block without problems, because
+ * the block is never executed.
+ */
+static void RECYCLEspace(void)
+{
+ if (recycleBlk == NULL) {
+ recycleBlk = newMalBlk(MAXVARS, STMT_INCREMENT);
+ recycleBlk->profiler = (ProfPtr) GDKzalloc(
+ recycleBlk->ssize*sizeof(ProfRecord));
+ }
+}
+
void RECYCLEinitRecyclePool(int sz)
{
if (recyclePool == NULL) {
@@ -150,6 +166,7 @@ void RECYCLEinitRecyclePool(int sz)
thetasubselectRef = putName("thetasubselect",14);
like_subselectRef= putName("like_subselect",14);
recycleCacheLimit=HARDLIMIT_STMT;
+ RECYCLEspace();
MT_lock_unset(&recycleLock, "recycle");
}
}
@@ -268,23 +285,6 @@ static void returnCredit(InstrPtr q)
}
}
-
-/*
- * The Recycle catalog is a global structure, which should be
- * protected with locks when updated.
- * The recycle statistics can be kept in the performance table
- * associated with the recycle MAL block without problems, because
- * the block is never executed.
- */
-static void RECYCLEspace(void)
-{
- if (recycleBlk == NULL) {
- recycleBlk = newMalBlk(MAXVARS, STMT_INCREMENT);
- recycleBlk->profiler = (ProfPtr) GDKzalloc(
- recycleBlk->ssize*sizeof(ProfRecord));
- }
-}
-
void RECYCLEinit(void){
#ifdef NEED_MT_LOCK_INIT
MT_lock_init(&recycleLock,"recycleLock");
@@ -422,12 +422,12 @@ static void RECYCLEcleanCache(Client cnt
InstrPtr *old, *newstmt;
bit *lmask, *dmask;
int k, *lvs, *vm;
- int limit, mem, idx;
+ int limit, idx;
+ size_t mem;
int cont, reserve;
lng oldclk, wr;
dbl minben, ben;
bte *used;
- lng memLimit = monet_memory;
if (!recycleBlk)
return;
@@ -518,7 +518,7 @@ newpass:
#ifdef _DEBUG_CACHE_
mnstr_printf(cntxt->fdout,"\n#RECYCLEcleanCache: policy=PROFIT
usedmem="LLFMT"\n", recyclerMemoryUsed);
- mnstr_printf(cntxt->fdout,"#Target memory "LLFMT"KB Available
"LLFMT"KB\n", wr,memLimit-recyclerMemoryUsed);
+ mnstr_printf(cntxt->fdout,"#Target memory "LLFMT"KB Available
"LLFMT"KB\n", wr,monet_memory -recyclerMemoryUsed);
mnstr_printf(cntxt->fdout,"#Candidates for eviction\n#(#
LRU\t\tTicks\tLife\tSZ\tCnt\tWgt\tBen\tProf)\n");
for (l = 0; l < ltop; l++)
mnstr_printf(cntxt->fdout,"%3d "LLFMT"\t"LLFMT"\t %5.2f\t
"LLFMT"\t%3d\t%5.1f\n",
@@ -531,7 +531,7 @@ newpass:
#endif
/* find entries to evict */
- mem = recyclerMemoryUsed + wr > memLimit;
+ mem = (size_t)(recyclerMemoryUsed + wr) > monet_memory ;
vm = (int *)GDKzalloc(sizeof(int)*ltop);
vtop = 0;
@@ -554,7 +554,7 @@ newpass:
/* mnstr_printf(cntxt->fdout,"ltop %d k
%d\n",ltop, k); */
if ( k > 0 )
ltop = k;
- vtop = chooseVictims(cntxt,lvs, ltop, recyclerMemoryUsed + wr -
memLimit);
+ vtop = chooseVictims(cntxt,lvs, ltop, recyclerMemoryUsed + wr -
monet_memory );
for (v = 0; v < vtop; v++){
vm[v] = lvs[v];
wr -= recycleBlk->profiler[lvs[v]].wbytes;
@@ -562,7 +562,7 @@ newpass:
}
/* check if a new pass of cache cleaning is needed */
- if (recyclerMemoryUsed + wr > memLimit)
+ if ( (size_t)(recyclerMemoryUsed + wr) > monet_memory )
cont = 1;
#ifdef _DEBUG_CACHE_
@@ -792,7 +792,6 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb,
ValRecord *v;
ValRecord cst;
InstrPtr q;
- lng memLimit;
(void) mb;
(void) pc;
@@ -800,8 +799,7 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb,
RECYCLEspace();
if ( recycleSize >= recycleCacheLimit)
return ; /* no more caching */
- memLimit = monet_memory;
- if ( recyclerMemoryUsed + wr > memLimit)
+ if ( (size_t)(recyclerMemoryUsed + wr) > monet_memory)
return ; /* no more caching */
/*
@@ -827,7 +825,7 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb,
setArg(q,i,c);
}
#ifdef _DEBUG_RECYCLE_
- mnstr_printf(cntxt->fdout,"#RECYCLE [%d] ",recycleBlk->stop);
+ mnstr_printf(cntxt->fdout,"#RECYCLE [%3d] ",recycleBlk->stop);
printInstruction( cntxt->fdout,recycleBlk, 0, q,LIST_MAL_STMT);
#else
(void) cntxt;
@@ -1295,7 +1293,7 @@ RECYCLEreuse(Client cntxt, MalBlkPtr mb,
}
}
/* 2: exact covering */
- if (p->argc > q->argc) continue;
+ if (p->argc != q->argc || p->retc != q->retc) continue;
for (j = p->retc; j < p->argc; j++)
if (VALcmp(&s->stk[getArg(p,j)],
&getVarConstant(recycleBlk, getArg(q,j))))
goto notfound;
@@ -1343,12 +1341,12 @@ RECYCLEreuse(Client cntxt, MalBlkPtr mb,
ticks = GDKusec();
i= getPC(mb,p);
#ifdef _DEBUG_RECYCLE_REUSE
- mnstr_printf(cntxt->fdout,"#RECYCLEreuse subselect ");
- printInstruction(cntxt->fdout, recycleBlk, 0,getInstrPtr(recycleBlk,pc),
LIST_MAL_STMT);
+ mnstr_printf(cntxt->fdout,"#RECYCLEreuse subselect ");
+ printInstruction(cntxt->fdout, recycleBlk,
0,getInstrPtr(recycleBlk,pc), LIST_MAL_STMT);
- mnstr_printf(cntxt->fdout,">>>");
- printTraceCall(cntxt->fdout, mb, s,i, LIST_MAL_STMT);
- mnstr_printf(cntxt->fdout,"\n");
+ mnstr_printf(cntxt->fdout,">>>");
+ printTraceCall(cntxt->fdout, mb, s,i, LIST_MAL_STMT);
+ mnstr_printf(cntxt->fdout,"\n");
#endif
nbid = s->stk[getArg(p,1)].val.bval;
s->stk[getArg(p,1)].val.bval = bid;
@@ -1404,8 +1402,10 @@ RECYCLEentry(Client cntxt, MalBlkPtr mb,
return 1;
i = RECYCLEreuse(cntxt,mb,stk,p,pc) >= 0;
#ifdef _DEBUG_RECYCLE_
- mnstr_printf(cntxt->fdout,"#REUSE [%d] ",i);
- printInstruction(cntxt->fdout,mb,0,p, LIST_MAL_STMT);
+ if ( i > 0) {
+ mnstr_printf(cntxt->fdout,"#REUSE [%3d] ",i);
+ printInstruction(cntxt->fdout,mb,0,p, LIST_MAL_STMT);
+ }
#endif
return i >= 0 ? 0: GDKusec();
}
@@ -1455,13 +1455,13 @@ RECYCLEexitImpl(Client cntxt, MalBlkPtr
}
void
-RECYCLEexit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int pc, lng
clk0)
+RECYCLEexit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int pc, lng
clk)
{
if ( cntxt->rcc->curQ < 0 ) /* don't use recycling before initialization
by prelude() */
return;
MT_lock_set(&recycleLock, "recycle");
- RECYCLEexitImpl(cntxt,mb,stk,p, pc, GDKusec()-clk0);
+ RECYCLEexitImpl(cntxt,mb,stk,p, pc, clk);
MT_lock_unset(&recycleLock, "recycle");
}
@@ -1807,7 +1807,7 @@ RECYCLEdump(stream *s)
recycleBlk->profiler[i].ticks,
recycleBlk->profiler[i].rbytes,
recycleBlk->profiler[i].wbytes,
- instruction2str(recycleBlk,0,getInstrPtr(recycleBlk,i),TRUE));
+
instruction2str(recycleBlk,0,getInstrPtr(recycleBlk,i),LIST_MAL_DEBUG));
}
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list