From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 E9A67469719 for ; Mon, 5 Oct 2020 21:54:18 +0300 (MSK) Date: Mon, 5 Oct 2020 21:43:42 +0300 From: Igor Munkin Message-ID: <20201005184342.GM18920@tarantool.org> References: <61072ba98da2e4098b0c35cad83ffcdcbc537c8e.1601644669.git.imun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <61072ba98da2e4098b0c35cad83ffcdcbc537c8e.1601644669.git.imun@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH] lua: prohibit fiber yield when GC hook is active List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirill Yukhin Cc: tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy Kirill, Please proceed with the patch. On 02.10.20, Igor Munkin wrote: > While running GC hook (i.e. __gc metamethod) garbage collector engine > is "stopped": the memory penalty threshold is set to LJ_MAX_MEM and > incremental GC step is not triggered as a result. Ergo, yielding the > execution at the finalizer body leads to further running platform with > disabled LuaJIT GC. It is not re-enabled until the yielded fiber doesn't > get the execution back. > > This changeset extends routine with the check whether GC > hook is active. If the switch-over occurs in scope of __gc metamethod > the platform is forced to stop its execution with EXIT_FAILURE and calls > panic routine before the exit. > > Relates to #4518 > Follows up #4727 > > Signed-off-by: Igor Munkin > --- > > Vlad introduced the internal interface and local internal background > fiber in scope of 8443bd9 ("fiber: introduce schedule_task() internal > function") to postpone any yielding finalization (e.g. 3d5b4da ("fio: > close unused descriptors automatically") and f073834 ("swim: use > fiber._internal.schedule_task() for GC")). After this patch is merged we > need to update docs and provide users a correct scenario to detect and > fix yielding finalizers. > > Here are also the benchmark results for the Release build: > * Vanilla (2711797) -> Patched (61072ba) (min, median, mean, max): > | fibers: 10; iters: 100 0% 0% 0% 2% > | fibers: 10; iters: 1000 -3% 0% 0% 1% > | fibers: 10; iters: 10000 -3% 0% -1% -2% > | fibers: 10; iters: 100000 0% 0% 0% 1% > | fibers: 100; iters: 100 -1% -2% -2% -9% > | fibers: 100; iters: 1000 0% 0% 0% 5% > | fibers: 100; iters: 10000 0% 0% 0% 0% > | fibers: 100; iters: 100000 0% 0% 0% -3% > | fibers: 1000; iters: 100 0% 0% 0% 0% > | fibers: 1000; iters: 1000 0% 0% 0% 0% > | fibers: 1000; iters: 10000 0% 0% 0% 1% > | fibers: 1000; iters: 100000 0% 0% 0% 2% > | fibers: 10000; iters: 100 0% -3% -1% -2% > | fibers: 10000; iters: 1000 0% -2% -3% -2% > | fibers: 10000; iters: 10000 0% 0% 0% -2% > | fibers: 10000; iters: 100000 0% -3% -3% -6% > > src/lua/utils.c | 26 ++++++++++++++- > test/app-tap/yield-in-gc-finalizer.test.lua | 36 +++++++++++++++++++++ > 2 files changed, 61 insertions(+), 1 deletion(-) > create mode 100755 test/app-tap/yield-in-gc-finalizer.test.lua > > -- > 2.25.0 > -- Best regards, IM