lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, 31 May 2010 18:44:59 +0300, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

I'm trying to understand how stepmul and pause parameters
work in generational mode.

Added printfs to generationalcollection(), it seems that
_ every second luaC_step in generational mode is a full collection _.

You said "it seems that ..."; can you check that?

I can post the test code, and what values trigger the results I see.
There are just too many possible combinations of parameter values and
allocation patterns to "check that" in the mathematical sense :(

If that is really happening, it may be because most objects the program
creates are going to the old generation (that is, they are not becoming
garbage fast enough). The first nursery collection frees very litle, so
the collector tries a full collection.

That's the part of the test. I'm setting up a permanent forest of
SQSIZE*(SQSIZE+1) tables, and then allocate temporary strings and
keep references to last NSIZE of them.

After your reply I tried without the permanent allocation.
It seems that if I set "pause" to something REALLY HUGE (like 200 or more),
it calls full gc every third time...

stepmul doesn't seem to do anything at all.

=====8<================ modification

static void generationalcollection (lua_State *L) {
  global_State *g = G(L);
  lu_mem tlm = g->lastmajormem;
  lu_mem ttb = g->totalbytes;
  int tdeb = g->GCdebt;
  const char *tg = "full";
  if (g->lastmajormem == 0) {  /* signal for another major collection? */
    luaC_fullgc(L, 0);  /* perform a full regular collection */
    g->lastmajormem = g->totalbytes;  /* update control */
  }
  else {
    tg = "short";
    luaC_runtilstate(L, bitmask(GCSpause));  /* run collection */
    if (g->totalbytes > g->lastmajormem/100 * g->gcpause)
      g->lastmajormem = 0;  /* signal for a major collection */
  }
  g->GCdebt = stddebt(g);
fprintf(stderr, "%s lastm %u -> %u totalb %u (%+d) debt %+d -> %+d\n", tg,
          tlm, g->lastmajormem,
          g->totalbytes, g->totalbytes - ttb,
          tdeb, g->GCdebt);
}


=====8<================ test script

local SQSIZE, NSIZE, PAUSE, STEPMUL = ...

collectgarbage "stop"

local function g()
    local ret = {}
    for i=1,SQSIZE do ret[i] = {a=1} end
    return ret
end
b = {}
for i=1,SQSIZE do b[i]=g() end

t = {}

collectgarbage "collect"
collectgarbage "collect"

collectgarbage("setpause", PAUSE)
collectgarbage("setstepmul", STEPMUL)
collectgarbage("restart")
collectgarbage "gen"

local maxalloc = 0

local n = 0
for i=1,1000000 do
    local s = "n" .. i
    t[n] = s
    if n == NSIZE then n = 0 else n = n + 1 end
    local ma = collectgarbage "count"
    if ma > maxalloc then maxalloc = ma end
end

print("OK, done, maxalloc = ", maxalloc, ", #t = ", #t)

collectgarbage "collect"
collectgarbage "collect"

=====8<================ results of some runs


$ ./lua ~/P/gengc-test.lua 500  100 10 0
short lastm 18111333 -> 0 totalb 18111144 (-258) debt +69 -> -1811110
full lastm 0 -> 19000212 totalb 19000212 (-480931) debt +214117 -> -1900020
short lastm 19000212 -> 0 totalb 19959177 (-416306) debt +23 -> -1995910
full lastm 0 -> 21703572 totalb 21703572 (-666094) debt +1463639 -> -2170350 short lastm 21703572 -> 0 totalb 22454614 (-1243204) debt +348640 -> -2245460
full lastm 0 -> 23065336 totalb 23065336 (-1110016) debt +22 -> -2306530
short lastm 23065336 -> 0 totalb 25339128 (-169808) debt +2234706 -> -2533910
full lastm 0 -> 26632560 totalb 26632560 (-1240067) debt +45 -> -2663250
short lastm 26632560 -> 0 totalb 27555960 (-1934029) debt +1243211 -> -2755590 full lastm 0 -> 28017672 totalb 28017672 (-1491578) debt +246732 -> -2801760
short lastm 28017672 -> 0 totalb 28376976 (-1393437) debt +13 -> -2837690
full lastm 0 -> 32679160 totalb 32679160 (-103913) debt +5763195 -> -3267910
short lastm 32679160 -> 0 totalb 34347400 (-1599258) debt +44 -> -3434740
full lastm 0 -> 36100816 totalb 36100816 (-1680885) debt +17 -> -3610080
short lastm 36100816 -> 0 totalb 37532968 (-3470159) debt +3389839 -> -3753290 full lastm 0 -> 38249056 totalb 38249056 (-2783931) debt +1844337 -> -3824900 short lastm 38249056 -> 0 totalb 38607088 (-2440794) debt +1071534 -> -3860700 full lastm 0 -> 38786104 totalb 38786104 (-2269237) debt +685161 -> -3878610 short lastm 38786104 -> 0 totalb 38875624 (-2183470) debt +491988 -> -3887560 full lastm 0 -> 38920384 totalb 38920384 (-2140575) debt +395383 -> -3892030 short lastm 38920384 -> 0 totalb 38942752 (-2119116) debt +347062 -> -3894270 full lastm 0 -> 38953936 totalb 38953936 (-2108398) debt +322920 -> -3895390 short lastm 38953936 -> 0 totalb 38959528 (-2103039) debt +310849 -> -3895950 full lastm 0 -> 38962336 totalb 38962336 (-2100371) debt +304837 -> -3896230 short lastm 38962336 -> 0 totalb 38963728 (-2099014) debt +301784 -> -3896370 full lastm 0 -> 38964424 totalb 38964424 (-2098347) debt +300281 -> -3896440 short lastm 38964424 -> 0 totalb 38964784 (-2098025) debt +299553 -> -3896470 full lastm 0 -> 38964952 totalb 38964952 (-2097841) debt +299147 -> -3896490 short lastm 38964952 -> 0 totalb 38965048 (-2097772) debt +298986 -> -3896500
full lastm 0 -> 41062248 totalb 41062248 (-574) debt +298882 -> -4106220
short lastm 41062248 -> 0 totalb 47359224 (-5818) debt +8488514 -> -4735920
full lastm 0 -> 49777080 totalb 49777080 (-2317640) debt +32 -> -4977700
short lastm 49777080 -> 0 totalb 52318392 (-2435952) debt +20 -> -5231830
full lastm 0 -> 54989472 totalb 54989472 (-2560313) debt +19 -> -5498940
short lastm 54989472 -> 0 totalb 57463056 (-6565350) debt +7734754 -> -5746300 full lastm 0 -> 58699848 totalb 58699848 (-5380091) debt +5065343 -> -5869980
OK, done, maxalloc =    58482.01953125  , #t =  999999


$ ./lua ~/P/gengc-test.lua 500  100 100 0
short lastm 18111314 -> 18111314 totalb 18111125 (-258) debt +69 -> -18111100
short lastm 18111314 -> 0 totalb 30979404 (+0) debt +11 -> -30979400
full lastm 0 -> 41065013 totalb 41065013 (-16139740) debt +4683161 -> -41065000
short lastm 41065013 -> 0 totalb 57616469 (-14027332) debt +32 -> -57616400
OK, done, maxalloc =    69964.603515625 , #t =  999999


$ ./lua ~/P/gengc-test.lua 0 1 200 0
short lastm 17168 -> 17168 totalb 16979 (-240) debt +51 -> -33800
short lastm 17168 -> 0 totalb 40869 (+0) debt +30 -> -81600
full lastm 0 -> 70219 totalb 70219 (-29142) debt +7668 -> -140400
short lastm 70219 -> 70219 totalb 134271 (-46774) debt +20062 -> -268400
short lastm 70219 -> 0 totalb 351740 (+0) debt +47857 -> -703400
full lastm 0 -> 583712 totalb 583712 (-307576) debt +16 -> -1167400
short lastm 583712 -> 583712 totalb 1061757 (-338114) debt +42459 -> -2123400
short lastm 583712 -> 0 totalb 2797182 (+0) debt +398941 -> -5594200
full lastm 0 -> 4638579 totalb 4638579 (-2442074) debt +19 -> -9277000
short lastm 4638579 -> 4638579 totalb 8560475 (-2797817) debt +588925 -> -17120800
short lastm 4638579 -> 0 totalb 22799595 (+0) debt +3410260 -> -45599000
full lastm 0 -> 37777235 totalb 37777235 (-20135603) debt +31 -> -75554400
OK, done, maxalloc =    56555.459960938 , #t =  999999


$ ./lua ~/P/gengc-test.lua 0 1 200 10000
short lastm 17190 -> 17190 totalb 17001 (-240) debt +51 -> -34000
short lastm 17190 -> 0 totalb 41096 (+0) debt +35 -> -82000
full lastm 0 -> 70241 totalb 70241 (-29142) debt +7063 -> -140400
short lastm 70241 -> 70241 totalb 134293 (-46774) debt +20062 -> -268400
short lastm 70241 -> 0 totalb 351762 (+0) debt +47857 -> -703400
full lastm 0 -> 583757 totalb 583757 (-307576) debt +39 -> -1167400
short lastm 583757 -> 583757 totalb 1061779 (-338092) debt +42414 -> -2123400
short lastm 583757 -> 0 totalb 2797204 (+0) debt +398941 -> -5594400
full lastm 0 -> 4638697 totalb 4638697 (-2442166) debt +7 -> -9277200
short lastm 4638697 -> 4638697 totalb 8560545 (-2797771) debt +588631 -> -17121000
short lastm 4638697 -> 0 totalb 22799571 (+0) debt +3409966 -> -45599000
full lastm 0 -> 37777257 totalb 37777257 (-20135557) debt +31 -> -75554400
OK, done, maxalloc =    56555.436523438 , #t =  999999


$ ./lua ~/P/gengc-test.lua 0 100 150 0
short lastm 17170 -> 17170 totalb 16981 (-258) debt +69 -> -25350
short lastm 17170 -> 0 totalb 37079 (+0) debt +4688 -> -55500
full lastm 0 -> 55511 totalb 55511 (-26814) debt +8206 -> -83250
short lastm 55511 -> 0 totalb 97113 (-20686) debt +2 -> -145650
full lastm 0 -> 153787 totalb 153787 (-47551) debt +19 -> -230550
short lastm 153787 -> 0 totalb 269703 (-48618) debt +4 -> -404550
full lastm 0 -> 473133 totalb 473133 (-69597) debt +33 -> -709650
short lastm 473133 -> 0 totalb 906049 (-163828) debt +149722 -> -1359000
full lastm 0 -> 1807169 totalb 1807169 (-360976) debt +427868 -> -2710650
short lastm 1807169 -> 0 totalb 3609409 (-721424) debt +862074 -> -5414100
full lastm 0 -> 7244965 totalb 7244965 (-1473396) debt +1792488 -> -10867350 short lastm 7244965 -> 0 totalb 14584997 (-3015184) debt +3682654 -> -21877350 full lastm 0 -> 29265061 totalb 29265061 (-6029840) debt +7221646 -> -43897500
OK, done, maxalloc =    54509.978515625 , #t =  999999