Changeset: 68c9c450ff6b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/68c9c450ff6b
Modified Files:
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/modules/mal/clients.c
        monetdb5/optimizer/opt_mitosis.c
        sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:

Repurpose procedure sys.setmemorylimit to set maximum transient heap space.
The value is still in MiB (unlike the value in sys.db_user_info table)
and cannot be increased above that limit.
Next step is to properly use the limit (or check that is's already
properly used) in mitosis and dataflow.


diffs (99 lines):

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
@@ -270,6 +270,7 @@ MCinitClientRecord(Client c, oid user, b
        c->qryctx.starttime = 0;
        ATOMIC_SET(&c->qryctx.datasize, 0);
        c->qryctx.maxmem = 0;
+       c->maxmem = 0;
        c->itrace = 0;
        c->errbuf = 0;
 
@@ -396,6 +397,7 @@ MCforkClient(Client father)
                son->memorylimit = father->memorylimit;
                son->qryctx.querytimeout = father->qryctx.querytimeout;
                son->qryctx.maxmem = father->qryctx.maxmem;
+               son->maxmem = father->maxmem;
                son->sessiontimeout = father->sessiontimeout;
 
                if (son->prompt)
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -69,6 +69,7 @@ typedef struct CLIENT {
        char    optimizer[IDLENGTH];/* The optimizer pipe preferred for this 
session */
        int     workerlimit;            /* maximum number of workthreads 
processing a query */
        int             memorylimit;            /* Memory claim highwater mark, 
0 = no limit */
+       lng maxmem;                                     /* maximum memory from 
db_user_info table */
        lng         sessiontimeout;             /* session abort after x usec, 
0 = no limit */
        QryCtx  qryctx;                         /* per query limitations */
 
diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c
--- a/monetdb5/modules/mal/clients.c
+++ b/monetdb5/modules/mal/clients.c
@@ -334,14 +334,18 @@ CLTsetmemorylimit(Client cntxt, MalBlkPt
                throw(MAL, "clients.setmemorylimit", "The memmory limit cannot 
be NULL");
        if( limit < 0)
                throw(MAL, "clients.setmemorylimit", "The memmory limit cannot 
be negative");
-       if( (size_t) limit > GDK_mem_maxsize / 1048576)
-               throw(MAL,"clients.setmemorylimit","Memory claim beyond 
physical memory");
 
        MT_lock_set(&mal_contextLock);
        if (mal_clients[idx].mode == FREECLIENT)
                msg = createException(MAL,"clients.setmemorylimit","Session not 
active anymore");
-       else
+       else if (cntxt->user != MAL_ADMIN &&
+                        mal_clients[idx].maxmem > 0 &&
+                        mal_clients[idx].maxmem < (lng) limit << 20)
+               msg = createException(MAL, "clients.setmemorylimit","Cannot 
increase memory limit");
+       else {
                mal_clients[idx].memorylimit = limit;
+               mal_clients[idx].qryctx.maxmem = (ATOMIC_BASE_TYPE) limit << 20;
+       }
        MT_lock_unset(&mal_contextLock);
        return msg;
 }
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -166,11 +166,13 @@ OPTmitosisImplementation(Client cntxt, M
        /* respect the memory limit size set for the user
        * and determine the column part size
        */
-       if( cntxt->memorylimit)
-               m = (((size_t) cntxt->memorylimit) * 1048576) / argsize;
-       else {
-               m = GDK_mem_maxsize / (size_t) MCactiveClients() / argsize;
-       }
+       m = GDK_mem_maxsize / MCactiveClients(); /* use temporarily */
+       if (cntxt->memorylimit > 0 && (size_t) cntxt->memorylimit << 20 < m)
+               m = ((size_t) cntxt->memorylimit << 20) / argsize;
+       else if (cntxt->maxmem > 0 && cntxt->maxmem < (lng) m)
+               m = (size_t) (cntxt->maxmem / argsize);
+       else
+               m = m / argsize;
 
        /* if data exceeds memory size,
         * i.e., (rowcnt*argsize > GDK_mem_maxsize),
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
@@ -270,11 +270,14 @@ SQLprepareClient(Client c, int login)
                        default:
                                break;
                }
-               lng maxmem;
-               if (monet5_user_get_max_memory(m, m->user_id, &maxmem) == 0)
-                       c->qryctx.maxmem = (ATOMIC_BASE_TYPE) (maxmem > 0 ? 
maxmem : 0);
-               else
+               if (monet5_user_get_max_memory(m, m->user_id, &c->maxmem) == 0) 
{
+                       c->qryctx.maxmem = (ATOMIC_BASE_TYPE) (c->maxmem > 0 ? 
c->maxmem : 0);
+               } else {
+                       c->maxmem = 0;
                        c->qryctx.maxmem = 0;
+               }
+               if (c->memorylimit > 0 && c->qryctx.maxmem > 
((ATOMIC_BASE_TYPE) c->memorylimit << 20))
+                       c->qryctx.maxmem = (ATOMIC_BASE_TYPE) c->memorylimit << 
20;
        }
 
        if (c->handshake_options) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to