Skip to content

gt: release memory pressure on Lua#635

Merged
AltraMayor merged 3 commits intomasterfrom
luamem
Mar 28, 2023
Merged

gt: release memory pressure on Lua#635
AltraMayor merged 3 commits intomasterfrom
luamem

Conversation

@AltraMayor
Copy link
Owner

As Lua policies evolve, they may increase the memory pressure on Lua. This pull request releases some of this pressure.

The long-term solution is to upgrade to LuaJIT v2.1 and to enable GC64 once LuaJIT v2.1 is stable.

@AltraMayor AltraMayor added this to the Version 1.1 milestone Mar 21, 2023
@AltraMayor AltraMayor force-pushed the luamem branch 5 times, most recently from aa07afe to 2cbccd5 Compare March 24, 2023 15:02
Although the code already uses lua_pcall() to call the Lua
function lookup_policy(), it does not protect the code that sets
the call frame of lookup_policy().  Therefore, if Lua runs out of
memory (or any other error), the Lua state panics.

Not only does this commit protect the code that sets the call frame
of lookup_policy(), but it also runs Lua's garbage collector and
retries lookup_policy() if the failure was due to a lack of memory.
@AltraMayor AltraMayor force-pushed the luamem branch 3 times, most recently from acd4b25 to 7adb7aa Compare March 27, 2023 18:59
The TBL24 present in a FIB head takes 64MB.  A Lua policy may have
4 FIBs: IPv4 source, IPv4 destination, IPv6 source, IPv6
destination.  Therefore, an instance of a Lua policy may take more
than 4 * 64MB = 256MB.

A typical Grantor server has 2 instances of the GT Block.
Therefore, The instances of a Lua policy may take more than
2 * 256MB = 512MB.

During reloads or recreation of FIBs, the number of FIBs may double.
Which requires more than 1GB of memory and reaches LuaJIT's limit of
1GB per process.

This patch moves FIB heads to huge pages to avoid the problem
decribed above.  Moreover, having TBL24s in huge pages is also
a performance improvement since it puts less load on the virtual
memory subsystem and it is NUMA aware.
@AltraMayor
Copy link
Owner Author

AltraMayor commented Mar 28, 2023

This pull request has successfully reduced the memory pressure on Lua policies in production.

@AltraMayor AltraMayor merged commit 0e626c0 into master Mar 28, 2023
@AltraMayor AltraMayor deleted the luamem branch March 28, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant