Carlos Abalde
2018-10-14 17:08:07 UTC
Hi all,
I've found an apparently weird situation when using Lua + jemalloc. After a lot of debugging I'been able to reduce the problem to a toy C program uploaded to https://gist.github.com/carlosabalde/bd6cb2b17aa71fd4c53864037b89f36b <https://gist.github.com/carlosabalde/bd6cb2b17aa71fd4c53864037b89f36b> (I've tested this in CentOS 7 using Lua 5.1): 20k threads are created, all of them sharing a single Lua engine (obviously protecting it with a mutex), an executing lua_pcall() every second. That call executes a dummy function containing a local table.
Everything works as expected when using the system allocator (i.e. gcc test.c -lpthread -llua): contant resident memory consumtion (~ 170 MB). However, when using jemalloc (i.e. gcc test.c -lpthread -llua -ljemalloc) memory consumption is much higher (~ 3.6 GB) and it continues slowly increasing.
It seems that's related with the local table defined inside the function, but I don't know if that's the expected behavior or how to avoid it (not using jemalloc is not an option). Btw, this is also happening in Lua 5.3, but not in LuaJIT (I guess because LuaJIT uses its own allocator).
Any explanation for this behavior?
Thanks a lot! :)
--
Carlos Abalde
I've found an apparently weird situation when using Lua + jemalloc. After a lot of debugging I'been able to reduce the problem to a toy C program uploaded to https://gist.github.com/carlosabalde/bd6cb2b17aa71fd4c53864037b89f36b <https://gist.github.com/carlosabalde/bd6cb2b17aa71fd4c53864037b89f36b> (I've tested this in CentOS 7 using Lua 5.1): 20k threads are created, all of them sharing a single Lua engine (obviously protecting it with a mutex), an executing lua_pcall() every second. That call executes a dummy function containing a local table.
Everything works as expected when using the system allocator (i.e. gcc test.c -lpthread -llua): contant resident memory consumtion (~ 170 MB). However, when using jemalloc (i.e. gcc test.c -lpthread -llua -ljemalloc) memory consumption is much higher (~ 3.6 GB) and it continues slowly increasing.
It seems that's related with the local table defined inside the function, but I don't know if that's the expected behavior or how to avoid it (not using jemalloc is not an option). Btw, this is also happening in Lua 5.3, but not in LuaJIT (I guess because LuaJIT uses its own allocator).
Any explanation for this behavior?
Thanks a lot! :)
--
Carlos Abalde