From: Igor Munkin <imun@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>, Sergey Ostanevich <sergos@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 2/2] box: reduce box_process_lua Lua GC memory usage Date: Fri, 19 Jun 2020 23:40:55 +0300 [thread overview] Message-ID: <7b8e95f3d6da39f0c3c6ca742abccddda817ac5e.1592597647.git.imun@tarantool.org> (raw) In-Reply-To: <cover.1592597647.git.imun@tarantool.org> <box_process_lua> function created a new GCfunc object for a handler having no upvalues depending on the request context on each call. The changes introduces the folliwing mapping: | <handler id> -> <handler GCfunc object> Initializing this mapping on Tarantool startup is aimed to reduce Lua GC memory usage. Signed-off-by: Igor Munkin <imun@tarantool.org> --- src/box/lua/call.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/box/lua/call.c b/src/box/lua/call.c index 6588ec2fa..e1b1a5e81 100644 --- a/src/box/lua/call.c +++ b/src/box/lua/call.c @@ -48,6 +48,15 @@ #include "mpstream/mpstream.h" #include "box/session.h" +enum handlers { + HANDLER_CALL, + HANDLER_CALL_BY_REF, + HANDLER_EVAL, + HANDLER_MAX, +}; + +static int execute_lua_refs[HANDLER_MAX]; + /** * A helper to find a Lua function by name and put it * on top of the stack. @@ -527,7 +536,7 @@ static const struct port_vtab port_lua_vtab = { }; static inline int -box_process_lua(lua_CFunction handler, struct execute_lua_ctx *ctx, +box_process_lua(enum handlers handler, struct execute_lua_ctx *ctx, struct port *ret) { lua_State *L = luaT_newthread(tarantool_L); @@ -537,7 +546,8 @@ box_process_lua(lua_CFunction handler, struct execute_lua_ctx *ctx, port_lua_create(ret, L); ((struct port_lua *) ret)->ref = coro_ref; - lua_pushcfunction(L, handler); + lua_rawgeti(L, LUA_REGISTRYINDEX, execute_lua_refs[handler]); + assert(lua_isfunction(L, -1)); lua_pushlightuserdata(L, ctx); if (luaT_call(L, 1, LUA_MULTRET) != 0) { port_lua_destroy(ret); @@ -554,7 +564,7 @@ box_lua_call(const char *name, uint32_t name_len, ctx.name = name; ctx.name_len = name_len; ctx.args = args; - return box_process_lua(execute_lua_call, &ctx, ret); + return box_process_lua(HANDLER_CALL, &ctx, ret); } int @@ -565,7 +575,7 @@ box_lua_eval(const char *expr, uint32_t expr_len, ctx.name = expr; ctx.name_len = expr_len; ctx.args = args; - return box_process_lua(execute_lua_eval, &ctx, ret); + return box_process_lua(HANDLER_EVAL, &ctx, ret); } struct func_lua { @@ -781,7 +791,7 @@ func_persistent_lua_call(struct func *base, struct port *args, struct port *ret) struct execute_lua_ctx ctx; ctx.lua_ref = func->lua_ref; ctx.args = args; - return box_process_lua(execute_lua_call_by_ref, &ctx, ret); + return box_process_lua(HANDLER_CALL_BY_REF, &ctx, ret); } @@ -998,6 +1008,18 @@ box_lua_call_init(struct lua_State *L) */ on_alter_func_in_lua.data = L; trigger_add(&on_alter_func, &on_alter_func_in_lua); + + lua_CFunction handles[] = { + [HANDLER_CALL] = execute_lua_call, + [HANDLER_CALL_BY_REF] = execute_lua_call_by_ref, + [HANDLER_EVAL] = execute_lua_eval, + }; + + for (int i = 0; i < HANDLER_MAX; i++) { + lua_pushcfunction(L, handles[i]); + execute_lua_refs[i] = luaL_ref(L, LUA_REGISTRYINDEX); + } + #if 0 /* Get CTypeID for `struct port *' */ int rc = luaL_cdef(L, "struct port;"); -- 2.25.0
next prev parent reply other threads:[~2020-06-19 20:50 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-19 20:50 [Tarantool-patches] [PATCH 0/2] Reduce Lua GC pressure in Tarantool Igor Munkin 2020-06-19 20:40 ` [Tarantool-patches] [PATCH 1/2] test: disable JIT for Lua Fun totable function Igor Munkin 2020-06-21 10:26 ` Sergey Ostanevich 2020-06-21 20:24 ` Igor Munkin 2020-06-25 9:43 ` Sergey Ostanevich 2020-06-26 11:11 ` Igor Munkin 2020-06-26 13:11 ` Igor Munkin 2020-06-23 18:04 ` Igor Munkin 2020-06-23 18:45 ` Alexander V. Tikhonov 2020-06-23 21:58 ` Igor Munkin 2020-06-19 20:40 ` Igor Munkin [this message] 2020-06-20 17:42 ` [Tarantool-patches] [PATCH 2/2] box: reduce box_process_lua Lua GC memory usage Vladislav Shpilevoy 2020-06-20 21:24 ` Igor Munkin 2020-06-21 10:27 ` Sergey Ostanevich 2020-06-21 10:40 ` Igor Munkin 2020-06-21 15:35 ` Vladislav Shpilevoy 2020-06-21 19:09 ` Igor Munkin 2020-06-22 22:54 ` [Tarantool-patches] [PATCH 0/2] Reduce Lua GC pressure in Tarantool Vladislav Shpilevoy 2020-06-23 21:06 ` Vladislav Shpilevoy 2020-06-23 21:58 ` Igor Munkin 2020-06-23 21:59 ` Igor Munkin 2020-06-27 13:22 ` Igor Munkin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=7b8e95f3d6da39f0c3c6ca742abccddda817ac5e.1592597647.git.imun@tarantool.org \ --to=imun@tarantool.org \ --cc=sergos@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/2] box: reduce box_process_lua Lua GC memory usage' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox