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 6C9274B711F; Tue, 6 Jun 2023 16:56:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6C9274B711F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1686059768; bh=kEw8Nykr9ZSAIFDgWsdePrYTrGjfTJivQPew7iLHp+4=; 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=J4y7hO0bUFubv8/4cQq510gUx7pu4C3zV43KCgkvtH1ORpafLjmcMj6fw0z3r2S4r +Bttj+TZJ1Tup5n44jPaRYF1Y4NsYdPTjGcM7kwkALZlNSOFI/iuTJrH1igI/jwASW KtZCYzlKHt4KHCt4tyqmqcqmI1tYPzrr1kssTQ0o= Received: from smtp3.i.mail.ru (smtp3.i.mail.ru [95.163.41.67]) (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 AA7434405A1 for ; Tue, 6 Jun 2023 16:56:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AA7434405A1 Received: by smtp3.i.mail.ru with esmtpa (envelope-from ) id 1q6XAM-00Dpz1-Sl; Tue, 06 Jun 2023 16:56:07 +0300 Date: Tue, 6 Jun 2023 16:51:57 +0300 To: Maxim Kokryashkin Message-ID: References: <20230531132806.216178-1-m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230531132806.216178-1-m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD93D74B10BAB639DE3ABEDFB2F706F8B45A10CD4D140639AA900894C459B0CD1B956C7B62C246BB9837A58CCAFCC3853D8CAD5F10AFE872393141B3585208100AE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77603ADE015AF816DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375CC217B55A7C05578638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82DDDC7E0E3CAC41C665BD4277CD9E6CD117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCE2CCD8F0CAA010FB389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8643FE6A0CAC512C7F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CD3FF21A3814AB5936E0066C2D8992A164AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3D8561A2FEC730ACEBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE74ABCC139FF3F849B731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A56F6DDD5909D41DD5F7C5D988477048C915F4149156B2F134F87CCE6106E1FC07E67D4AC08A07B9B0DB8A315C1FF4794DBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF80F170CB1FA51A4029951FF63A6474867EA3B5DFE0706C2C95DE9D7DAFA0E838B23470503F0B8DDF588A46A5EBCE8E3715B9165C6722D5C7E08F59B367991A3BE48CAC7CA610320002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojBFnFgsoZgk7Han1MdPsEvA== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7692E36AD813772C1F83C5F4A2AB95D2BA8FE5F7FEA15315F16DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix memory probing allocator to check for valid end address, too. 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! The patch is LGTM except a few insiginificant nits below. But I'm wondering: can we examine a test case mentioned in the [1]? I.e. create a really long trace, near the upper bound of the 2GB, so its results become meaningless? You may take a look into or for the inspiration. This is desired to show actual problem, and not changes in some synthetic behaviour. On 31.05.23, Maxim Kokryashkin wrote: > From: Mike Pall > > (cherry-picked from commit 646148e747759f0af3b47f9bd287cedd7e174631) > > Before the patch `mmap_probe` only checked if the allocated chunk > start was within the 2^LJ_ALLOC_MBITS bytes region. However, if the > chunk is big enough, its end can reach outside of that region. This > patch adds the corresponding check, to avoid such situations. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#8516 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-445-fix-memory-probing-allocator > PR: https://github.com/tarantool/tarantool/pull/8720 > LuaJIT issue: https://github.com/LuaJIT/LuaJIT/issues/445 > > src/lj_alloc.c | 3 +- > ...-445-fix-memory-probing-allocator.test.lua | 32 +++++++++++++++++++ > 2 files changed, 34 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/lj-445-fix-memory-probing-allocator.test.lua > > diff --git a/src/lj_alloc.c b/src/lj_alloc.c > index ffcd019b..f7039b5b 100644 > --- a/src/lj_alloc.c > +++ b/src/lj_alloc.c > diff --git a/test/tarantool-tests/lj-445-fix-memory-probing-allocator.test.lua b/test/tarantool-tests/lj-445-fix-memory-probing-allocator.test.lua > new file mode 100644 > index 00000000..44763e38 > --- /dev/null > +++ b/test/tarantool-tests/lj-445-fix-memory-probing-allocator.test.lua > @@ -0,0 +1,32 @@ > +local tap = require('tap') > +local ffi = require('ffi') > +local test = tap.test('lj-445-fix-memory-probing-allocator'):skipcond({ > + ['Unlikely to hit beyond the upper bound for GC64'] = ffi.abi('gc64'), > +}) > + > +local bit = require('bit') > +local shr = bit.rshift > +local uintptr_t = ffi.typeof('uintptr_t') > + > +-- Due to limitations in the x64 compiler backend, max memory limit is Minor: comment line width is more than 66 symbols. > +-- two times lower when JIT is not disabled entirely. > +local HAS_JIT = jit.status() > +local LJ_ALLOC_MBITS = HAS_JIT and 31 or 32 > +local MAX_GB = HAS_JIT and 2 or 4 > + > +test:plan(MAX_GB) > + > +-- Chomp memory in currently allocated GC space. > +collectgarbage('stop') > + > +-- Every allocation must either result in a chunk that fits into the Ditto. > +-- `MAX_GB`-sized region entirely or return an OOM error. > +for _ = 1, MAX_GB do > + local status, result = pcall(ffi.new, 'char[?]', 1024 * 1024 * 1024) > + if status then > + local upper_bound = ffi.cast(uintptr_t, result) + ffi.sizeof(result) > + test:ok(shr(upper_bound, LJ_ALLOC_MBITS) == 0, 'non-extended address') > + else > + test:ok(result == 'not enough memory', 'OOM encountered') > + end > +end Nit: Mising `os.exit()`. > -- > 2.40.1 > [1]: https://github.com/LuaJIT/LuaJIT/issues/445 -- Best regards, Sergey Kaplun