diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-10-11 09:38:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-10-11 09:38:45 -0300 |
commit | 1d8920dd7f508af5f2fd743678be1327f30c079b (patch) | |
tree | 31fdd2aa1c2829904c51be79aa334db020847418 /lgc.c | |
parent | 911f1e3e7ff01dafe3e9f77bc9c8e3a25237d7de (diff) | |
download | lua-1d8920dd7f508af5f2fd743678be1327f30c079b.tar.gz lua-1d8920dd7f508af5f2fd743678be1327f30c079b.tar.bz2 lua-1d8920dd7f508af5f2fd743678be1327f30c079b.zip |
some cleaning in GC parameters
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.233 2017/06/29 15:06:44 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.234 2017/08/31 16:06:51 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -47,9 +47,9 @@ | |||
47 | 47 | ||
48 | /* | 48 | /* |
49 | ** The equivalent, in bytes, of one unit of "work" (visiting a slot, | 49 | ** The equivalent, in bytes, of one unit of "work" (visiting a slot, |
50 | ** sweeping an object, etc.) * 10 (for scaling) | 50 | ** sweeping an object, etc.) |
51 | */ | 51 | */ |
52 | #define WORK2MEM (sizeof(TValue) * 10) | 52 | #define WORK2MEM sizeof(TValue) |
53 | 53 | ||
54 | 54 | ||
55 | /* | 55 | /* |
@@ -1256,14 +1256,14 @@ static void fullgen (lua_State *L, global_State *g) { | |||
1256 | ** than last major collection (kept in 'g->GCestimate'), does a major | 1256 | ** than last major collection (kept in 'g->GCestimate'), does a major |
1257 | ** collection. Otherwise, does a minor collection and set debt to make | 1257 | ** collection. Otherwise, does a minor collection and set debt to make |
1258 | ** another collection when memory grows 'genminormul'% larger. | 1258 | ** another collection when memory grows 'genminormul'% larger. |
1259 | ** 'GCdebt <= 0' means an explicity call to GC step with "size" zero; | 1259 | ** 'GCdebt <= 0' means an explicit call to GC step with "size" zero; |
1260 | ** in that case, always do a minor collection. | 1260 | ** in that case, always do a minor collection. |
1261 | */ | 1261 | */ |
1262 | static void genstep (lua_State *L, global_State *g) { | 1262 | static void genstep (lua_State *L, global_State *g) { |
1263 | lu_mem majorbase = g->GCestimate; | 1263 | lu_mem majorbase = g->GCestimate; |
1264 | //lua_checkmemory(L); | 1264 | int majormul = getgcparam(g->genmajormul); |
1265 | if (g->GCdebt > 0 && | 1265 | if (g->GCdebt > 0 && |
1266 | gettotalbytes(g) > (majorbase / 100) * (100 + g->genmajormul)) { | 1266 | gettotalbytes(g) > (majorbase / 100) * (100 + majormul)) { |
1267 | fullgen(L, g); | 1267 | fullgen(L, g); |
1268 | } | 1268 | } |
1269 | else { | 1269 | else { |
@@ -1273,7 +1273,6 @@ static void genstep (lua_State *L, global_State *g) { | |||
1273 | luaE_setdebt(g, -((mem / 100) * g->genminormul)); | 1273 | luaE_setdebt(g, -((mem / 100) * g->genminormul)); |
1274 | g->GCestimate = majorbase; /* preserve base value */ | 1274 | g->GCestimate = majorbase; /* preserve base value */ |
1275 | } | 1275 | } |
1276 | //lua_checkmemory(L); | ||
1277 | } | 1276 | } |
1278 | 1277 | ||
1279 | /* }====================================================== */ | 1278 | /* }====================================================== */ |
@@ -1288,13 +1287,13 @@ static void genstep (lua_State *L, global_State *g) { | |||
1288 | 1287 | ||
1289 | /* | 1288 | /* |
1290 | ** Set the "time" to wait before starting a new GC cycle; cycle will | 1289 | ** Set the "time" to wait before starting a new GC cycle; cycle will |
1291 | ** start when memory use hits the threshold of ('estimate' * gcpause / | 1290 | ** start when memory use hits the threshold of ('estimate' * pause / |
1292 | ** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero, | 1291 | ** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero, |
1293 | ** because Lua cannot even start with less than PAUSEADJ bytes). | 1292 | ** because Lua cannot even start with less than PAUSEADJ bytes). |
1294 | */ | 1293 | */ |
1295 | static void setpause (global_State *g) { | 1294 | static void setpause (global_State *g) { |
1296 | l_mem threshold, debt; | 1295 | l_mem threshold, debt; |
1297 | int pause = g->gcpause + 100; | 1296 | int pause = getgcparam(g->gcpause); |
1298 | l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ | 1297 | l_mem estimate = g->GCestimate / PAUSEADJ; /* adjust 'estimate' */ |
1299 | lua_assert(estimate > 0); | 1298 | lua_assert(estimate > 0); |
1300 | threshold = (pause < MAX_LMEM / estimate) /* overflow? */ | 1299 | threshold = (pause < MAX_LMEM / estimate) /* overflow? */ |
@@ -1482,16 +1481,15 @@ void luaC_runtilstate (lua_State *L, int statesmask) { | |||
1482 | ** controls when next step will be performed. | 1481 | ** controls when next step will be performed. |
1483 | */ | 1482 | */ |
1484 | static void incstep (lua_State *L, global_State *g) { | 1483 | static void incstep (lua_State *L, global_State *g) { |
1485 | int stepmul = (g->gcstepmul | 1); /* avoid division by 0 */ | 1484 | int stepmul = (getgcparam(g->gcstepmul) | 1); /* avoid division by 0 */ |
1486 | l_mem debt = (g->GCdebt / WORK2MEM) * stepmul; | 1485 | l_mem debt = (g->GCdebt / WORK2MEM) * stepmul; |
1487 | l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem)) | 1486 | l_mem stepsize = (g->gcstepsize <= log2maxs(l_mem)) |
1488 | ? cast(l_mem, 1) << g->gcstepsize | 1487 | ? ((cast(l_mem, 1) << g->gcstepsize) / WORK2MEM) * stepmul |
1489 | : MAX_LMEM; | 1488 | : MAX_LMEM; /* overflow; keep maximum value */ |
1490 | stepsize = -((stepsize / WORK2MEM) * stepmul); | ||
1491 | do { /* repeat until pause or enough "credit" (negative debt) */ | 1489 | do { /* repeat until pause or enough "credit" (negative debt) */ |
1492 | lu_mem work = singlestep(L); /* perform one single step */ | 1490 | lu_mem work = singlestep(L); /* perform one single step */ |
1493 | debt -= work; | 1491 | debt -= work; |
1494 | } while (debt > stepsize && g->gcstate != GCSpause); | 1492 | } while (debt > -stepsize && g->gcstate != GCSpause); |
1495 | if (g->gcstate == GCSpause) | 1493 | if (g->gcstate == GCSpause) |
1496 | setpause(g); /* pause until next cycle */ | 1494 | setpause(g); /* pause until next cycle */ |
1497 | else { | 1495 | else { |