Skip to content

Conversation

@dovkfir
Copy link

@dovkfir dovkfir commented Apr 7, 2015

Lua memory usage is not limited and a script can crash redis.
The issue is solved with the addition of new memory allocator that uses a new configurable lua-memory-limit.

Implementation details:
currently we are using Lua 5.1.5. In this version the GC cannot be called from within the allocator, thus scripts that doesn't suppose to cross the memory limit can fail on low memory,
Scenarios:

  1. setting memory limit to X, and running a script that allocates large array of X/2, and then run it again, will fail with memory limit message.
  2. setting memory limit to X, allocating large array of X/2, release it and allocating new array of size X/2 at the same script will fail with memory limit message.

to improve the first scenario we added a new configurable lua-gc-threshold, which is tested before we run the script, if the Lua stack cross the threshold we initiate GC cycle to release some memory.

the second issue was resolved in Lua 5.2 with the emergency garbage collector feature and memory limit gc parameter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this check; it's not protecting anything, and the behaviour is not forward compatible.
In lua 5.2+:

When ptr is NULL, osize encodes the kind of object that Lua is allocating. osize is any of LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, or LUA_TTHREAD when (and only when) Lua is creating a new object of that type. When osize is some other value, Lua is allocating memory for something else.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Dov Kfir seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants