Improve GC estimation for userdata with attached managed memory.

This works well for string.buffers, but not for userdata or
cdata with attached unmanaged memory (malloc/free, mmap/munmap).
master
Mike Pall 2022-07-28 15:40:28 +02:00
parent 9c3df68a1e
commit a7d0265480
1 changed files with 3 additions and 0 deletions

View File

@ -700,9 +700,12 @@ static size_t gc_onestep(lua_State *L)
}
case GCSfinalize:
if (gcref(g->gc.mmudata) != NULL) {
GCSize old = g->gc.total;
if (tvref(g->jit_base)) /* Don't call finalizers on trace. */
return LJ_MAX_MEM;
gc_finalize(L); /* Finalize one userdata object. */
if (old >= g->gc.total && g->gc.estimate > old - g->gc.total)
g->gc.estimate -= old - g->gc.total;
if (g->gc.estimate > GCFINALIZECOST)
g->gc.estimate -= GCFINALIZECOST;
return GCFINALIZECOST;