From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 260A91F42F for ; Sun, 9 Sep 2018 09:53:51 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 3/4] cont.c (fiber_memsize): do not rely on ROOT_FIBER_CONTEXT Date: Sun, 9 Sep 2018 09:53:46 +0000 Message-Id: <20180909095347.30757-4-e@80x24.org> In-Reply-To: <20180909095347.30757-1-e@80x24.org> References: <20180909095347.30757-1-e@80x24.org> List-Id: We can check if the fiber we're interested in is the th->root_fiber for the owner thread, so there is no need to use ROOT_FIBER_CONTEXT. Note: there is no guarantee th->ec points to &th->root_fiber->cont.saved_ec, thus vm::thread_memsize may not account for root fiber correctly (pre-existing bug). [Bug #15050] --- cont.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cont.c b/cont.c index 2b83c52768..27f956f5c8 100644 --- a/cont.c +++ b/cont.c @@ -493,12 +493,15 @@ static size_t fiber_memsize(const void *ptr) { const rb_fiber_t *fib = ptr; - size_t size = 0; + size_t size = sizeof(*fib); + const rb_execution_context_t *saved_ec = &fib->cont.saved_ec; + const rb_thread_t *th = rb_ec_thread_ptr(saved_ec); - size = sizeof(*fib); - if (fib->cont.type != ROOT_FIBER_CONTEXT && - fib->cont.saved_ec.local_storage != NULL) { - size += st_memsize(fib->cont.saved_ec.local_storage); + /* + * vm.c::thread_memsize already counts th->ec->local_storage + */ + if (saved_ec->local_storage && fib != th->root_fiber) { + size += st_memsize(saved_ec->local_storage); } size += cont_memsize(&fib->cont); return size; -- EW