From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 857CA54A69F; Wed, 26 Jul 2023 15:17:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 857CA54A69F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1690373828; bh=jSTFdQIijd1g+fnWG1pY7k8kyJo7UAVxfoQ6GpLoP8k=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=J+ToGoiwB7aBF3kW62pkmtznHe3lBvzcq49/TEMxeKqyiw/NdzcBeqcGb7OwgQTea f0uOZLvM1tKhP2vwmAPfkKi/OA2V+0ko+y3cg8mlGgyJTJYNEGnesSvm8FcPgdbZis tKM3cm89sPgElTcVrTYu94Y7ZpjdcxSBgmlDcOZ8= Received: from smtp50.i.mail.ru (smtp50.i.mail.ru [95.163.41.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B96DB543BC1 for ; Wed, 26 Jul 2023 15:17:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B96DB543BC1 Received: by smtp50.i.mail.ru with esmtpa (envelope-from ) id 1qOdRy-002ul3-SE; Wed, 26 Jul 2023 15:17:07 +0300 Date: Wed, 26 Jul 2023 15:12:40 +0300 To: Maxim Kokryashkin Message-ID: References: <20230724144148.289140-1-m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230724144148.289140-1-m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9F4F4431F26286E4642A2C51A91B2CCA306681F3D44141338182A05F538085040104BD2C4254989FA196FA28E88F83EA9504051329A42B46A70B717F053425DA1 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7D77100FFB2844417EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CAA352D56883AEE98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F5DB56E072597EE5955AF99137CE053E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520437C869540D2AB0FE5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE0AC5B80A05675ACD07FB45A5F6E725C8D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE3F8BD4E506CFA3D889735652A29929C6CC4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CA9FF340AA05FB58C35872C767BF85DA227C277FBC8AE2E8B779389CF6F126FEC75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A575697C6F8D5E9CD3D15DB5136B0DA9E114A5B20C8C156AEDF87CCE6106E1FC07E67D4AC08A07B9B062B3BD3CC35DA588CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFDF845B77ABB513ABA292C364AF929E721FBD0BCE62F133B667B71D853C39F8D9DAFD28DA9052916A2D8A5E5B53F5BD047F9CE9BE9C91AA6403DD50E19EFD1354A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojXeYlEwgoYE+5s2jvk7eaHQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769768D932E8A86CAC9196FA28E88F83EA952685D71546B8E9EDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix frame for on-trace out-of-memory error. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the patch! Please, consider my comments below. On 24.07.23, Maxim Kokryashkin wrote: > Reported by ruidong007. > > (cherry-picked from commit 2d8300c1944f3a62c10f0829e9b7847c5a6f0482) > > When an on-trace OOM error is triggered from a frame that is > child in regard to `jit_base`, and `L->base` is not updated > correspondingly (FUNCC, for example), it is possible to > encounter an inconsistent Lua stack in the error handler. > > This patch adds a fixup for OOM errors on trace that always Typo: s/on trace/on the trace/ > sets the Lua stack base to `jit_base`, so the stack is > now consistent. > > Part of tarantool/tarantool#8825 > --- > +local testoomframe = require('testoomframe') > + > +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 Before the patch the test takes really a lot of time to wait: | time LUA_PATH="src/?.lua;test/tarantool-tests/?.lua;;" LUA_CPATH="test/tarantool-tests/lj-1004-oom-error-frame/?.so;;" src/luajit test/tarantool-tests/lj-1 | 004-oom-error-frame.test.lua | TAP version 13 | 1..1 | ok - on-trace error handled successfully | | real 0m12.984s | user 0m12.207s | sys 0m0.775s I've added the simple chunk eater (and reduce lightuserdata size, just in case). And this speedups test x2. But I believe that we can make it even x20 faster with careful size calculations. Also, I suggest to try to use some non-compilable fast function instead Lua C call to forcify trace stitching (looks like the error in userdata allocations is the main blocker). =================================================================== 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 fd167d14..f8dde4e6 100644 --- a/test/tarantool-tests/lj-1004-oom-error-frame.test.lua +++ b/test/tarantool-tests/lj-1004-oom-error-frame.test.lua @@ -1,13 +1,25 @@ local tap = require('tap') +local ffi = require('ffi') local test = tap.test('lj-1004-oom-error-frame'):skipcond({ ['Test requires JIT enabled'] = not jit.status(), - ['Test requires GC64 mode disabled'] = require('ffi').abi('gc64'), + ['Test requires GC64 mode disabled'] = ffi.abi('gc64'), }) test:plan(1) local testoomframe = require('testoomframe') +local anchor_memory = {} -- luacheck: no unused +local function eatchunks(size) + while true do + anchor_memory[ffi.new('char[?]', size)] = 1 + end +end + +if not ffi.abi('gc64') then + local r,e = pcall(eatchunks, 512 * 1024 * 1024) +end + local anchor = {} local function extra_frame(val) table.insert(anchor, val) 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 13071b4e..a54eac63 100644 --- a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c +++ b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c @@ -2,7 +2,7 @@ #include static int allocate_userdata(lua_State *L) { - lua_newuserdata(L, 16); + lua_newuserdata(L, 1); return 1; } =================================================================== | time LUA_PATH="src/?.lua;test/tarantool-tests/?.lua;;" LUA_CPATH="test/tarantool-tests/lj-1004-oom-error-frame/?.so;;" src/luajit test/tarantool-tests/lj-1 | 004-oom-error-frame.test.lua | TAP version 13 | 1..1 | ok - on-trace error handled successfully | | real 0m5.803s | user 0m5.006s | sys 0m0.795s I suggest to play a bit with this sizings and stitching, to decrease time of waiting. But be aware! The test should fail before the commit as for `make LuaJIT-test` command as well as for the one-line command (like above). > + > +local st, _ = pcall(chomp) > +test:ok(st == false, 'on-trace error handled successfully') Should we also check the error type to be sure that test is still valid? I.e. that we catch OOM, and not TABOV, for example? > -- > 2.41.0 > -- Best regards, Sergey Kaplun