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 B9A876EC40; Wed, 11 Aug 2021 23:35:36 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B9A876EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628714136; bh=bimejxLSVlGzcL/NIt04CGeaqUkD4W5O54NHwuoF3x4=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Fj8EZHcmXbI3ihIgKnuwwTVjwbqPh34BIHcL6x0cKMOIMeoLkwIDsMo8SckHQYL0E ZvOhEsLWdHuFo7iDmRnHNHKhO9STrqqG6AGyK4Fr/6vOMRnOV1zcfqc02RYIb7Odth b+QyZ4O3TylMVCwg+e8ERD1vKxqsC9H/GN0MJcE8= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [94.100.177.90]) (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 4B9736EC44 for ; Wed, 11 Aug 2021 23:33:35 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4B9736EC44 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1mDuus-0007H4-FX; Wed, 11 Aug 2021 23:33:34 +0300 To: v.shpilevoy@tarantool.org, imun@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Wed, 11 Aug 2021 23:33:31 +0300 Message-Id: <32b7ac476fec0b675b34d032a61326970491c7cf.1628713520.git.babinoleg@mail.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD91BCCB18F2C129F87F36E61E9E4584E9D182A05F538085040549BE34BD7BCB59171D031C498715BE864F0FBC22FB266353671D2F3E561CA1A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE728A881FD0F09D355EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C867FEFF36BCDF178638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80F4C1E616050BE18E05B5C1B4138B082117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC3A703B70628EAD7BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18F04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE140C956E756FBB7A86750DBF4DC650F2D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE3FA486DC37A503D0BC0837EA9F3D19764C4224003CC836476EA7A3FFF5B025636E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637E62180BDA7F10F15EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D94463893BF8742D0975B52514B22C041 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C6B668463F4F89F86059EC171252E98CCC441023793849DFE9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFA183FDCE24978B01699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C264B329661203DA58E3E0300D17BCFCFCB8EE48D84AFD580E47EFC862C0B59641B53007950F94501D7E09C32AA3244CD592F1B2051A5D42D5F59FCF59F9800F30452B15D76AEC14FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKW4rnL99YhJlXNIAVpSt5g== X-Mailru-Sender: 583F1D7ACE8F49BD1042885CEC987B6BDB3D20F452EE499D71D031C498715BE88FF8BC079CCEBBDC7019711D9D5B048E1458020726E2BC9FD5ECBA0B92C0A936CDC7563AA7CEBD287402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 4/4] fiber: allocate on_stop triggers using mempool 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: Oleg Babin via Tarantool-patches Reply-To: olegrok@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Oleg Babin Previously we use malloc for such purpose however we created on_stop triggers only if fiber storage was touched. Currently we create on_stop trigger for each lua fiber. So it seems reasonable to use mempool for such frequent allocations/deallocations. --- src/lua/fiber.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lua/fiber.c b/src/lua/fiber.c index 268ddf9cc..f7c0ca63f 100644 --- a/src/lua/fiber.c +++ b/src/lua/fiber.c @@ -36,10 +36,19 @@ #include "backtrace.h" #include "tt_static.h" +#include #include #include #include +static struct mempool on_stop_triggers_pool; + +static void +on_stop_trigger_free(struct trigger *t) +{ + mempool_free(&on_stop_triggers_pool, t); +} + void luaL_testcancel(struct lua_State *L) { @@ -110,7 +119,7 @@ lbox_fiber_on_stop(struct trigger *trigger, void *event) luaL_unref(tarantool_L, LUA_REGISTRYINDEX, ref); f->storage.lua.ref = LUA_NOREF; trigger_clear(trigger); - free(trigger); + on_stop_trigger_free(trigger); return 0; } @@ -122,12 +131,13 @@ lbox_pushfiber(struct lua_State *L, struct fiber *f) { int ref = f->storage.lua.ref; if (ref <= 0) { - struct trigger *t = (struct trigger *)malloc(sizeof(*t)); + struct trigger *t = mempool_alloc(&on_stop_triggers_pool);; if (t == NULL) { diag_set(OutOfMemory, sizeof(*t), "malloc", "t"); luaT_error(L); } - trigger_create(t, lbox_fiber_on_stop, NULL, (trigger_f0) free); + trigger_create(t, lbox_fiber_on_stop, NULL, + on_stop_trigger_free); trigger_add(&f->on_stop, t); uint64_t fid = f->fid; @@ -921,6 +931,9 @@ static const struct luaL_Reg fiberlib[] = { void tarantool_lua_fiber_init(struct lua_State *L) { + mempool_create(&on_stop_triggers_pool, &cord()->slabc, + sizeof(struct trigger)); + luaL_register_module(L, fiberlib_name, fiberlib); lua_pop(L, 1); luaL_register_type(L, fiberlib_name, lbox_fiber_meta); -- 2.32.0