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 5E53E2ACC1; Fri, 11 Nov 2022 16:12:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5E53E2ACC1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1668172350; bh=mJy8kQQlAtDSsjfWRn2vipBvpJNVQRfa8rlL911l2rs=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=j+XHneuEVw0g78th1Dd9pTv3kieYVk0dYwp/NV+1MXaRj9ezdMZy2FcfNWOtpZuWW 4O/VJYu5i6eYi9jPHXKR3sg2KEy7V+Ecqga5y65nym0vadT6rjL/gNOmS2ua4wrgHx xcS94LcAtmi91buinN8HLofTzBpm0ZvemN6lNxCM= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 4AA1A2ACC1 for ; Fri, 11 Nov 2022 16:12:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4AA1A2ACC1 Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1otTpc-0004Nj-Fb; Fri, 11 Nov 2022 16:12:29 +0300 Date: Fri, 11 Nov 2022 16:09:23 +0300 To: Igor Munkin , tarantool-patches@dev.tarantool.org Message-ID: References: <20221109174948.10952-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD9D880D530162779F178E23083C3E8ECE834C3F16CAFD57852182A05F538085040B24EF8656A03B3736D2585E5BCA59B9736AC88271615865A2974DA8C26B9E751 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F68DA2F3749BB650EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377F69ABDCCC31D2058638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B10CFEE926A1B755D9F99FF9691283DC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735207B96B19DC4093321CB629EEF1311BF91D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE042285CD7A5C321F2AE38A8E97BAFFB1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE34B6F6234D9065C97C0837EA9F3D19764C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637EC3198ECE464ADAEEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34F6110710A6CC527F912265CECC5973CED77EC73D4B4277D9C8CCE4B02A34AA2F61B179969A9918E91D7E09C32AA3244C629F3E68C71F5C52E07C2C1A7FBB049E5A1673A01BA68E40729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSqkc8Nj21UPYsbTyWLAccg== X-Mailru-Sender: 87D5297B137A96FE4AECA001A08BCABA52069C57DD3D226B4E8E2D8AA3AF89FF65E6EFD542448DCE525762887713E5F1475755348978188EF9D3679FA3DE6E791CC59163FFD68303B0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Ensure correct stack top for OOM error message. 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, again! Added minor fixes. On 11.11.22, Sergey Kaplun via Tarantool-patches wrote: > =================================================================== > diff --git a/test/tarantool-tests/lj-906-fix-err-mem.test.lua b/test/tarantool-tests/lj-906-fix-err-mem.test.lua > index f512e802..0ec1b30e 100644 > --- a/test/tarantool-tests/lj-906-fix-err-mem.test.lua > +++ b/test/tarantool-tests/lj-906-fix-err-mem.test.lua > @@ -12,7 +12,7 @@ local KB = 1024 > local MB = 1024 * KB > > -- The maximum available table size, taking into account created > --- constants for one function. > +-- constants for one function and nested level. > local TNEW_SIZE = 511 > > local gc_anchor = {} > @@ -29,9 +29,8 @@ local function eat_chunks(size) > end > > -- Function to format inner tab leading to TDUP emitting. > -local function format_inner_tab() > +local function make_flat_table(inner_depth) Should be deep_table, obviously. =================================================================== diff --git a/test/tarantool-tests/lj-906-fix-err-mem.test.lua b/test/tarantool-tests/lj-906-fix-err-mem.test.lua index 7dbc1614..69f74893 100644 --- a/test/tarantool-tests/lj-906-fix-err-mem.test.lua +++ b/test/tarantool-tests/lj-906-fix-err-mem.test.lua @@ -29,7 +29,7 @@ local function eat_chunks(size) end -- Function to format inner tab leading to TDUP emitting. -local function make_flat_table(inner_depth) +local function make_deep_table(inner_depth) local inner_tab = '' -- Repeate table template for TDUP. for _ = 1, inner_depth do @@ -49,7 +49,7 @@ local function format_TDUP_chunk() local big_tab = 'local _ = {\n' -- The maximum available table size, taking into account created -- constants for one function and nested level. - local inner_tab = make_flat_table(128) + local inner_tab = make_deep_table(128) for _ = 1, TNEW_SIZE do big_tab = big_tab .. inner_tab .. '\n' end =================================================================== > local inner_tab = '' > - local inner_depth = 128 > -- Repeate table template for TDUP. > for _ = 1, inner_depth do > inner_tab = inner_tab .. '{a =' > @@ -43,9 +42,14 @@ local function format_inner_tab() > return inner_tab > end > > +-- The `lj_err_mem()` doesn't fix `L->top`, when called from > +-- helper function (like `lj_tab_dup()`) before the patch. > +-- This function creates a chunk with many BC_TDUP inside. > local function format_TDUP_chunk() > local big_tab = 'local _ = {\n' > - local inner_tab = format_inner_tab() > + -- The maximum available table size, taking into account created > + -- constants for one function and nested level. > + local inner_tab = make_flat_table(128) > for _ = 1, TNEW_SIZE do > big_tab = big_tab .. inner_tab .. '\n' > end > @@ -56,12 +60,10 @@ end > local TDUP, err = loadstring(format_TDUP_chunk()) > assert(TDUP, err) > > +-- Function to create the additional frame after to be rewrited > +-- one in case of `lj_err_mem()` misbehaviour. Also, minor comments fixes and renaming. =================================================================== diff --git a/test/tarantool-tests/lj-906-fix-err-mem.test.lua b/test/tarantool-tests/lj-906-fix-err-mem.test.lua index 69f74893..f4ec6620 100644 --- a/test/tarantool-tests/lj-906-fix-err-mem.test.lua +++ b/test/tarantool-tests/lj-906-fix-err-mem.test.lua @@ -45,7 +45,7 @@ end -- The `lj_err_mem()` doesn't fix `L->top`, when called from -- helper function (like `lj_tab_dup()`) before the patch. -- This function creates a chunk with many BC_TDUP inside. -local function format_TDUP_chunk() +local function make_TDUP_chunk() local big_tab = 'local _ = {\n' -- The maximum available table size, taking into account created -- constants for one function and nested level. @@ -57,11 +57,11 @@ local function format_TDUP_chunk() return big_tab end -local TDUP, err = loadstring(format_TDUP_chunk()) +local TDUP, err = loadstring(make_TDUP_chunk()) assert(TDUP, err) --- Function to create the additional frame after to be rewrited --- one in case of `lj_err_mem()` misbehaviour. +-- Function to create the additional frame to be rewritten later +-- in case of `lj_err_mem()` misbehaviour. local function frame_before_TDUP() TDUP() end =================================================================== Branch is force-pushed. > local function frame_before_TDUP() > - -- Stack slots are needed for coredump in case of misbehaviour. > - -- luacheck: no unused > - local frame_slot1, frame_slot2 > TDUP() > - return frame_slot1, frame_slot2 > end > > collectgarbage() > =================================================================== > > > > > > > + -- luacheck: no unused > > > + local frame_slot1, frame_slot2 > > > + TDUP() > > > + return frame_slot1, frame_slot2 > > > +end > > > + > > > > Minor: I believe you can pack these two lines into something one can > > call : > > | local function janitor() > > | collectgarbage('collect') > > | collectgarbage('stop') > > | end > > > > Anyway, you can leave this as is. > > Added, thanks! > See the iterative patch below. > =================================================================== > diff --git a/test/tarantool-tests/lj-906-fix-err-mem.test.lua b/test/tarantool-tests/lj-906-fix-err-mem.test.lua > index 519e6bf6..7dbc1614 100644 > --- a/test/tarantool-tests/lj-906-fix-err-mem.test.lua > +++ b/test/tarantool-tests/lj-906-fix-err-mem.test.lua > @@ -66,8 +66,12 @@ local function frame_before_TDUP() > TDUP() > end > > -collectgarbage() > -collectgarbage('stop') > +local function janitor() > + collectgarbage('collect') > + collectgarbage('stop') > +end > + > +janitor() > > -- Avoid OOM on traces. > jit.off() > @@ -75,14 +79,11 @@ jit.off() > -- Stack slots are needed for coredump in case of misbehaviour. > -- luacheck: no unused > local r, e = pcall(eat_chunks, 8 * MB) > -collectgarbage() > -collectgarbage('stop') > +janitor() > pcall(eat_chunks, 8 * KB) > -collectgarbage() > -collectgarbage('stop') > +janitor() > pcall(eat_chunks, 8) > -collectgarbage() > -collectgarbage('stop') > +janitor() > > pcall(frame_before_TDUP) > =================================================================== > > > > > > > +collectgarbage() > > > +collectgarbage('stop') > > > + > > > +-- Avoid OOM on traces. > > > +jit.off() > > > + > > > +-- Stack slots are needed for coredump in case of misbehaviour. > > > +-- luacheck: no unused > > > +local r, e = pcall(eat_chunks, 8 * MB) > > > +collectgarbage() > > > +pcall(eat_chunks, 8 * KB) > > > +collectgarbage() > > > +pcall(eat_chunks, 8) > > > +collectgarbage() > > > + > > > +pcall(frame_before_TDUP) > > > > Do we need to check the status of the above? > > I suppose no. As we disscussed offline the test may be flaky (false > positive, when we can alloc all tables) due to memory allocations. > Also, this part is very fragile, and we don't want to fix test later by > removing this check the status of the `pcall()`. > > > > > > + > > > +-- Release memory for `tap` functions. > > > +gc_anchor = nil > > > +collectgarbage() > > > > Is this step required? I doubt. > > Yes it is. Without it we may get the OOM error inside `test:ok()` or > `test:check()` functions (I faced it on my local machine, when rewrite > this test). > > > > > > + > > > +test:ok(true, 'correctly throw memory error') > > > + > > > +os.exit(test:check() and 0 or 1) > > > -- > > > 2.34.1 > > > > > > > -- > > Best regards, > > IM > > -- > Best regards, > Sergey Kaplun -- Best regards, Sergey Kaplun