lua-users home
lua-l archive

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


in case 1,
my process stops lua-gc, and do step-gc in lua by calling collectgarbage.
it run normally in lua5.3.5 by default gc param. (gc cost is 1%)
but when it run in lua5.4.3 by default gc param. lua gc cost is very high (22%)

 i found debt is divided by STEPMULADJ in lua5.3.6 :
```
static l_mem getdebt (global_State *g) {
  l_mem debt = g->GCdebt;
  int stepmul = g->gcstepmul;
  if (debt <= 0) return 0;  /* minimal debt */
  else {
    debt = (debt / STEPMULADJ) + 1;
    debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
    return debt;
  }
}
``` 
but there is no such code in lua5.4.3. 
the process run normally in lua5.4.3  when debt divided by LUAI_GCMUL

 
2. in case 2. 
the size of gc step does't meet the expectation. i.e. when i call collectgarbage("step", step_size),
the actual size of step is much larger than step_size

i found that it reset gc debt when gc is stopped  in lua5.3.5 
```
void luaC_step (lua_State *L) {
  global_State *g = G(L);
  l_mem debt = getdebt(g);  /* GC deficit (be paid now) */
  if (!g->gcrunning) {  /* not running? */
    luaE_setdebt(g, -GCSTEPSIZE * 10);  /* avoid being called too often */
    return;
  }
  do {  /* repeat until pause or enough "credit" (negative debt) */
    lu_mem work = singlestep(L);  /* perform one single step */
    debt -= work;
  } while (debt > -GCSTEPSIZE && g->gcstate != GCSpause);
  if (g->gcstate == GCSpause)
    setpause(g);  /* pause until next cycle */
  else {
    debt = (debt / g->gcstepmul) * STEPMULADJ;  /* convert 'work units' to Kb */
    luaE_setdebt(g, debt);
    runafewfinalizers(L);
  }
}
```

but there is no this code in lua5.4.3
when I add the reset code in lua5.4.3
the process  collectgarbage by step_size as expectation.   





Roberto Ierusalimschy <roberto@inf.puc-rio.br> 于2022年1月18日周二 19:25写道:
> 1. in incstep function, it miss divide by LUAI_GCMUL  when calculate debt.
> [...]
>
> 2. in luaC_step function, it should be setdebt to avoid being called too
> often as Lua5.3.5 when gc is stopped
> [...]

What are the bugs? Is there something not working as it should?

-- Roberto