summaryrefslogtreecommitdiff
path: root/package/lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-07-26 15:06:43 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-07-26 15:06:43 +0000
commitb18a60e1accf47ea1bd2567f7ee0988f0750ddcd (patch)
tree1ea9ae390b31ea22bb9409cff64b32b96380fba3 /package/lua
parent3fee02f1a927d9c88886e1c981a031076b963b42 (diff)
downloadmtk-20170518-b18a60e1accf47ea1bd2567f7ee0988f0750ddcd.zip
mtk-20170518-b18a60e1accf47ea1bd2567f7ee0988f0750ddcd.tar.gz
mtk-20170518-b18a60e1accf47ea1bd2567f7ee0988f0750ddcd.tar.bz2
lua: introduce soft memory limits that trigger a gc run but do not result in an oom error
SVN-Revision: 17016
Diffstat (limited to 'package/lua')
-rw-r--r--package/lua/Makefile2
-rw-r--r--package/lua/patches/040-memory-limits.patch32
2 files changed, 23 insertions, 11 deletions
diff --git a/package/lua/Makefile b/package/lua/Makefile
index f5fca7b..b418b30 100644
--- a/package/lua/Makefile
+++ b/package/lua/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=lua
PKG_VERSION:=5.1.4
-PKG_RELEASE:=4
+PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
diff --git a/package/lua/patches/040-memory-limits.patch b/package/lua/patches/040-memory-limits.patch
index 52bae6a..bc6526b 100644
--- a/package/lua/patches/040-memory-limits.patch
+++ b/package/lua/patches/040-memory-limits.patch
@@ -147,7 +147,7 @@
last -= n-1;
--- a/src/lua.c
+++ b/src/lua.c
-@@ -19,6 +19,82 @@
+@@ -19,6 +19,94 @@
#include "llimits.h"
@@ -156,6 +156,7 @@
+ lua_State *L;
+ size_t memused;
+ size_t peak_memused;
++ size_t gc_memused;
+ size_t max_memused;
+ int collecting;
+} script_info_t;
@@ -172,7 +173,8 @@
+ return NULL;
+ }
+ info->memused += nsize;
-+ if(info->max_memused > 0 && nsize > osize && info->memused >= info->max_memused) {
++ if(info->max_memused > 0 && nsize > osize &&
++ (info->memused >= info->max_memused || info->memused >= info->gc_memused)) {
+#ifdef LOW_MEM_DEBUG
+ printf("LOW MEM: 1 osize=%zd, nsize=%zd, used=%zu, peak=%zu, need=%zd\n", osize, nsize,
+ info->memused, info->peak_memused, (info->memused - info->max_memused));
@@ -207,15 +209,24 @@
+
+static int set_memory_limit(lua_State *L)
+{
-+ int limit = luaL_checknumber(L, 1);
++ int hardlimit = luaL_checknumber(L, 1);
++ int softlimit = luaL_optnumber(L, 2, 0);
++
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+
-+ if( limit >= 0 )
-+ info->max_memused = limit;
++ if( hardlimit >= 0 )
++ {
++ if( softlimit <= 0 )
++ softlimit = (int)((float)hardlimit * 0.75);
++
++ info->max_memused = hardlimit;
++ info->gc_memused = softlimit;
++ }
+
-+ lua_pushnumber(L, limit);
-+ return 1;
++ lua_pushnumber(L, hardlimit);
++ lua_pushnumber(L, softlimit);
++ return 2;
+}
+
+static int get_memory_limit(lua_State *L)
@@ -223,14 +234,15 @@
+ script_info_t *info;
+ lua_getallocf(L, (void *)(&info));
+ lua_pushnumber(L, info->max_memused);
-+ return 1;
++ lua_pushnumber(L, info->gc_memused);
++ return 2;
+}
+
+
static lua_State *globalL = NULL;
static const char *progname = LUA_PROGNAME;
-@@ -377,11 +453,28 @@
+@@ -377,11 +465,28 @@
int main (int argc, char **argv) {
int status;
struct Smain s;
@@ -260,7 +272,7 @@
/* Checking 'sizeof(lua_Integer)' cannot be made in preprocessor on all compilers.
*/
#ifdef LNUM_INT16
-@@ -396,6 +489,14 @@
+@@ -396,6 +501,14 @@
status = lua_cpcall(L, &pmain, &s);
report(L, status);
lua_close(L);