[Tarantool-patches] [PATCH luajit 1/2] Fix frame for on-trace out-of-memory error.

Maxim Kokryashkin m.kokryashkin at tarantool.org
Fri Sep 8 16:18:52 MSK 2023


Hi, Sergey!
Thanks for the review!
See my answers below.

> > +local testoomframe = require('testoomframe')
> > +
> > +local anchor_memory = {} -- luacheck: no unused
> > +local function eatchunks(size)
> > +  while true do
> > +    anchor_memory[ffi.new('char[?]', size)] = 1
> 
> 
> Why ffi.new() is a key, not a value?
Its just a very common pattern in our tests, also I don't
really want to manage a separate counter for the key. ffi.new()
can be a value as well, no issue with that.
> 
> > +  end
> > +end
> > +
> > +pcall(eatchunks, 512 * 1024 * 1024)
> 
> Why exactly this size is used?
It is empirically selected number, dropped a comment.

> 
> 
> > +
> > +local anchor = {}
> > +local function extra_frame(val)
> > +  table.insert(anchor, val)
> > +end
> > +
> > +local function chomp()
> > +  while true do
> > +    extra_frame(testoomframe.allocate_userdata())
> > +  end
> > +end
> > +
> > +local st, err = pcall(chomp)
> > +test:ok(st == false, 'on-trace error handled successfully')
> > +test:like(err, 'not enough memory', 'error is OOM')
> > +test:done(true)
> > diff --git a/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt b/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt
> > new file mode 100644
> > index 00000000..3bca5df8
> > --- /dev/null
> > +++ b/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt
> > @@ -0,0 +1 @@
> > +BuildTestCLib(testoomframe testoomframe.c)
> > diff --git a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
> > new file mode 100644
> > index 00000000..a54eac63
> > --- /dev/null
> > +++ b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
> > @@ -0,0 +1,17 @@
> > +#include <lua.h>
> > +#include <lauxlib.h>
> 
> Test uses headers provided by systems instead of headers provided by
> LuaJIT-under-test. It is expected?
Fixed, thanks.
> 
> --- a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
> +++ b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
> @@ -1,5 +1,5 @@
> -#include <lua.h>
> -#include <lauxlib.h>
> +#include "lua.h"
> +#include "lauxlib.h"
> 
>  static int allocate_userdata(lua_State *L) {
>         lua_newuserdata(L, 1);
> 
> > +
> > +static int allocate_userdata(lua_State *L) {
> > +	lua_newuserdata(L, 1);
> > +	return 1;
> > +}
> > +
> > +static const struct luaL_Reg testoomframe[] = {
> > +	{"allocate_userdata", allocate_userdata},
> > +	{NULL, NULL}
> > +};
> > +
> > +LUA_API int luaopen_testoomframe(lua_State *L) {
> > +	luaL_register(L, "testoomframe", testoomframe);
> > +	return 1;
> > +}

Here is the diff with changes. Branch is force-psuhed.
diff --git a/test/tarantool-tests/lj-1004-oom-error-frame.test.lua b/test/tarantool-tests/lj-1004-oom-error-frame.test.lua
index b6b5a9f2..3be6b555 100644
--- a/test/tarantool-tests/lj-1004-oom-error-frame.test.lua
+++ b/test/tarantool-tests/lj-1004-oom-error-frame.test.lua
@@ -17,6 +17,9 @@ local function eatchunks(size)
   end
 end
 
+-- The chunk size below is empirical. It is big enough, so the test
+-- is not too long, yet small enough for the OOM frame issue to have
+-- enough iterations in the second loop to trigger.
 pcall(eatchunks, 512 * 1024 * 1024)
 
 local anchor = {}
diff --git a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
index a54eac63..dbfe17db 100644
--- a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
+++ b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c
@@ -1,5 +1,5 @@
-#include <lua.h>
-#include <lauxlib.h>
+#include "lua.h"
+#include "lauxlib.h"
 
 static int allocate_userdata(lua_State *L) {
 	lua_newuserdata(L, 1);


More information about the Tarantool-patches mailing list