lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Carlos Abalde <carlos.abalde@gmail.com>于2018年10月15日周一 上午1:48写道:
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 (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! :)


You may try to turn off the tcache of jemalloc. I guess tcache may use huge memory since you create 20k threads.