[mod] Stop LUAJIT OOM crashes [stop_lj_oom]

Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

[mod] Stop LUAJIT OOM crashes [stop_lj_oom]

by blert2112 » Sat Jan 30, 2016 18:34

Plagued by LUAJIT Out-Of-Memory crashes? Can't use the mods you really want to without disabling LUAJIT because of it's low memory limit? Then give this a try.

GitHub -> https://github.com/blert2112/stop_lj_oom.git
Download -> https://github.com/blert2112/stop_lj_oo ... master.zip
License -> WTFPL

I like to use some pretty heavy mods. The Valleys_C helper mod, or mg_Villages, alone is enough to cause LUAJIT OOM crashing. Sure, you can compile without LUAJIT, but when you then notice that a seemingly simple LVM operation that took ~70ms to complete using LUAJIT now takes ~350ms you start to see the huge benefit of using LUAJIT.

Read the comments in the init.lua carefully. If you set the number too low you can cause even more memory issues.
Code: Select all
Stop LUAJIT Out-Of-Memory (OOM) crashes [stop_lj_oom]

by: blert2112
license: WTFPL

What it does:
      Runs the LUA Garbage Collector if the garbage memory count exceeds the
   specified limit.
      LUAJIT is restricted to the lower 1GB/2GB/4GB (depending on OS and
   bitness), regardless of the fact that you may have 128GBs installed in your
   rig, but much of that is being taken up by persistent things that don't get
   garbage collected. When something happens that makes LUAJIT exceed it's
   memory limit it crashes.
      From what I can discern, when you see a LUA_OOM crash the value that is
   reported to you is not the amount of memory LUAJIT is using, it is the
   amount of memory that can potentially be freed with a garbage collection
   AT THE TIME THE SAMPLE WAS TAKEN. What this mean is: The engine got a sample
   value of LUAJIT's garbage memory count, let's say it was 70MB. Then,
   something happened to cause LUAJIT to exceed it's memory limit and... BOOM!
   Since it crashed before it could get another usage value it reports that it
   crashed with a 70MB usage. So, between then and now, there could very well
   have been a huge amount of garbage that needed collecting.
How to use:
   Just enable the mod as you would any other.

      See that number down there on line 45?... When LUAJIT's garbage memory
   count exceeds that number the Garbage Collector will be run. Change the
   number to fit your needs. It is in KB, the default of 307200 is 300MB
   (300x1024). The smaller the number the more the   Garbage Collector will be
   run, resulting in slower performance and possibly unfinished collections or
   even causing the collector to never complete, so be careful not to set it
   too low. If, for example, your game has crashed with memory usage of 70MB
   do not set this number to 71680, that reported number is inaccurate! That
   value was sampled before even more memory was used which caused the crash.
   Start high and slowly decrease the value if you need to.
      Uncomment the "print" line (44) if you want to see the memory usage
   numbers in the console as they are counted and collected.

   if collectgarbage("count") > 307200 then

Yes, there are ways to get around the memory limit but I do not know enough of C/C++ to even attempt to mess around with FFI malloc() stuff to, for example, move a mod's PerlinNoise data and large persistent tables out of the realm of LUAJIT's memory limit and into upper memory. That is for someone else to figure out.
Please note that this mod cannot stop all crashes. The amount of mods you have installed, and what those mods do, directly relates to how much memory is available for non-persistent things that can be garbage collected. At some point you will have to set the collection amount to too low of a number. At that point you need to start thinking about doing away with some mods. For instance, the mods I use require me to use a limit of 50MB before running garbage collection. This doesn't hurt performance too much unless I am flying around in fast mode, but it's better than crashing. For normal play, I can up that limit to between 100 and 200MB and for playing on my local server (with all the same mods) I don't need the mod at all.

Posts: 36
Joined: Sun Feb 07, 2016 11:58
GitHub: foxzoolm
In-game: foxz

Posts: 244
Joined: Sat Apr 25, 2015 04:05
GitHub: blert2112

Re: [mod] Stop LUAJIT OOM crashes [stop_lj_oom]

by blert2112 » Sat Feb 20, 2016 01:07

I don't understand what you mean.
Do you mean the stuff like "collectgarbage()"? That's a standard Lua function. Search Lua to find tutorials and manuals.
Do you mean the interchangIbility of "minetest." and "core."? "minetest." = "core.", it's easier to type "core".

Posts: 831
Joined: Wed Feb 18, 2015 02:44
GitHub: wilkgr76

Re: [mod] Stop LUAJIT OOM crashes [stop_lj_oom]

by wilkgr76 » Sun Mar 13, 2016 05:26

☻☻☻☺☺ (That's a 3/5 rating, btw)

It does help with mods like Cityscape, but flexrealms does overload it :/.

Still, never would've thought of this, so thanks a lot blert2112 :)

User avatar
Posts: 895
Joined: Sun Jul 31, 2011 11:23
Location: Ukraine
IRC: Fixer
In-game: Fixer

Return to WIP Mods

Who is online

Users browsing this forum: Andrey01, MSN [Bot] and 5 guests