]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua: stop trying to tweak lua's GC
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 9 Oct 2019 12:29:28 +0000 (14:29 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 12 Dec 2019 11:20:07 +0000 (12:20 +0100)
cherry-picked from f0ca89ac, original author Vlada Cunat

TL;DR: I believe all lua_gc() calls stemmed from misunderstanding lua
documentation, and the current settings seem potentially dangerous.

First, let me rely on lua 5.1 docs, as luajit 2 is documented to have
done only minor changes in the GC.
http://www.lua.org/manual/5.1/manual.html#lua_gc
http://wiki.luajit.org/New-Garbage-Collector#rationale

Commit 5a709411 claims to have increased the speed of GC to 400 % of
speed of allocation, but LUA_GCSETSTEPMUL is the parameter that
controls that, and that one was lowered to 99 % and later in
0ee2d1d7 even to 50 %.  Documentation explicitly says that setting
the value under 100 % may cause problems.

The default values seem perfectly sane to me and currently I can't see
any particular reason to change them.  It's 200 % relative GC speed,
and waiting for allocated size to double before starting another cycle.

I assume the resulting possibility of GC being too slow caused the need
to explicitly force a non-incremental GC cycle once in a while, but
that seems not useful anymore and not good for latency.

daemon/engine.c
daemon/worker.c

index 7f3402109c0143283ec3595d24282dbbd7a28ffc..796f055492ca9dee716328efa83cac5f1ec029c1 100644 (file)
@@ -482,7 +482,6 @@ static int init_state(struct engine *engine)
                return kr_error(ENOMEM);
        }
        /* Initialize used libraries. */
-       lua_gc(engine->L, LUA_GCSTOP, 0);
        luaL_openlibs(engine->L);
        /* Global functions */
        lua_pushcfunction(engine->L, l_help);
@@ -733,12 +732,8 @@ int engine_load_defaults(struct engine *engine)
 
 int engine_start(struct engine *engine)
 {
-       /* Clean up stack and restart GC */
+       /* Clean up stack */
        lua_settop(engine->L, 0);
-       lua_gc(engine->L, LUA_GCCOLLECT, 0);
-       lua_gc(engine->L, LUA_GCSETSTEPMUL, 50);
-       lua_gc(engine->L, LUA_GCSETPAUSE, 400);
-       lua_gc(engine->L, LUA_GCRESTART, 0);
 
        return kr_ok();
 }
index df0f704e6470bac396bdaef079a723009a6044cf..9b0aeae61b88e304277726a984800304d0612c0c 100644 (file)
@@ -382,15 +382,6 @@ static void request_free(struct request_ctx *ctx)
        /* Return mempool to ring or free it if it's full */
        pool_release(worker, ctx->req.pool.ctx);
        /* @note The 'task' is invalidated from now on. */
-       /* Decommit memory every once in a while */
-       static int mp_delete_count = 0;
-       if (++mp_delete_count == 100000) {
-               lua_gc(worker->engine->L, LUA_GCCOLLECT, 0);
-#if defined(__GLIBC__) && defined(_GNU_SOURCE)
-               malloc_trim(0);
-#endif
-               mp_delete_count = 0;
-       }
        worker->stats.rconcurrent -= 1;
 }
 
@@ -1734,7 +1725,7 @@ int worker_end_tcp(struct session *session)
        }
 
        session_timer_stop(session);
-       
+
        uv_handle_t *handle = session_get_handle(session);
        struct worker_ctx *worker = handle->loop->data;
        struct sockaddr *peer = session_get_peer(session);