summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2022-07-28 15:40:28 +0200
committerMike Pall <mike>2022-07-28 15:40:28 +0200
commita7d0265480c662964988f83d4e245bf139eb7cc0 (patch)
tree0a7c33077b429e61bc86bd90936752710e0cccfa
parent9c3df68a1e00bd1fcaee13610fb063efe8ae3825 (diff)
downloadluajit2-a7d0265480c662964988f83d4e245bf139eb7cc0.tar.gz
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).
-rw-r--r--src/lj_gc.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c
index b35a0d44..2fc52ec1 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -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;