From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 223F817CE74D for ; Mon, 18 Mar 2013 17:56:03 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 344A5EA6D1C for ; Mon, 18 Mar 2013 17:34:14 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 247E297A82C for ; Mon, 18 Mar 2013 17:34:14 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JYYSsofRch6j for ; Mon, 18 Mar 2013 17:34:14 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 0377197A827 for ; Mon, 18 Mar 2013 17:34:14 +0900 (JST) Received: from carbon.ruby-lang.org (carbon.ruby-lang.org [221.186.184.68]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id CDC4A95241A for ; Mon, 18 Mar 2013 17:34:11 +0900 (JST) Received: from beryllium.ruby-lang.org (beryllium.ruby-lang.org [127.0.0.1]) by carbon.ruby-lang.org (Postfix) with ESMTP id 4908D3C21F72D; Mon, 18 Mar 2013 17:33:35 +0900 (JST) Received: from fluorine.ruby-lang.org (www.rubyist.net [210.251.121.216]) by carbon.ruby-lang.org (Postfix) with ESMTP id BD7B43C21ED77 for ; Mon, 18 Mar 2013 17:32:52 +0900 (JST) Received: from ruby-lang.org (localhost [127.0.0.1]) by fluorine.ruby-lang.org (Postfix) with ESMTP id 9BDD23E003 for ; Mon, 18 Mar 2013 17:32:52 +0900 (JST) Delivered-To: ruby-core@ruby-lang.org Date: Mon, 18 Mar 2013 17:32:53 +0900 Posted: Mon, 18 Mar 2013 17:32:52 +0900 From: "authorNari (Narihiro Nakamura)" Reply-To: ruby-core@ruby-lang.org Subject: [ruby-core:53496] [ruby-trunk - Bug #8092] [patch] gc: improve accuracy of objspace_live_num() and allocated/freed counters To: ruby-core@ruby-lang.org Message-Id: References: X-ML-Name: ruby-core X-Mail-Count: 53496 X-MLServer: fml [fml 4.0.3 release (20011202/4.0.3)]; post only (only members can post) X-ML-Info: If you have a question, send e-mail with the body "help" (without quotes) to the address ruby-core-ctl@ruby-lang.org; help= X-Mailer: Redmine X-Redmine-Issue-Author: tmm1 X-Redmine-Issue-Assignee: authorNari X-Auto-Response-Suppress: OOF X-Redmine-Issue-Id: 8092 X-Redmine-Mailinglistintegration-Message-Ids: 26653 X-Redmine-Project: ruby-trunk Auto-Submitted: auto-generated X-Redmine-Site: Ruby Issue Tracking System X-Redmine-Host: bugs.ruby-lang.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Precedence: bulk List-Id: ruby-core.ruby-lang.org List-Software: fml [fml 4.0.3 release (20011202/4.0.3)] List-Post: List-Owner: List-Help: List-Unsubscribe: Issue #8092 has been updated by authorNari (Narihiro Nakamura). Thank you for bug report. But, the following test case is failure. I think ko1-san is the implementer of GC.stat. ko1-san, what do you think? === start === $ git diff test diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index bed58f3..8cb036a 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -64,6 +64,15 @@ class TestGc < Test::Unit::TestCase assert_equal(arg, res) assert_equal(false, res.empty?) assert_kind_of(Integer, res[:count]) + + stat, count = {}, {} + GC.start + GC.stat(stat) + ObjectSpace.count_objects(count) + puts "" + p stat + p count + assert_equal(stat[:heap_live_num], count[:TOTAL]-count[:FREE]) end def test_singleton_method $ % make test-all TESTS='ruby/test_defined.rb ruby/test_integer.rb ruby/test_objectspace.rb ruby/test_sprintf_comb.rb ruby/test_argf.rb ruby/test_fiber.rb ruby/test_gc.rb' .... # Running tests: [ 91/131] TestGc#test_stat {:count=>351, :heap_used=>684, :heap_length=>1139, :heap_increment=>399, :heap_live_num=>46061, :heap_free_num=>152639, :heap_final_num=>0, :total_allocated_object=>402509, :total_freed_object=>356448} {:TOTAL=>198553, :FREE=>152639, :T_OBJECT=>31312, :T_CLASS=>655, :T_MODULE=>56, :T_FLOAT=>10, :T_STRING=>8425, :T_REGEXP=>146, :T_ARRAY=>1966, :T_HASH=>49, :T_STRUCT=>10, :T_BIGNUM=>25, :T_FILE=>10, :T_DATA=>2225, :T_MATCH=>22, :T_COMPLEX=>1, :T_NODE=>934, :T_ICLASS=>68} = 0.01 s 1) Failure: test_stat(TestGc) [/home/nari/source/ruby/ruby-git/test/ruby/test_gc.rb:75]: <46061> expected but was <45914>. Finished tests in 6.628281s, 19.7638 tests/s, 657.9383 assertions/s. 131 tests, 4361 assertions, 1 failures, 0 errors, 0 skips ruby -v: ruby 2.1.0dev (2013-03-14 trunk 38552) [x86_64-linux] make: *** [yes-test-all] Error 1 === end === ---------------------------------------- Bug #8092: [patch] gc: improve accuracy of objspace_live_num() and allocated/freed counters https://bugs.ruby-lang.org/issues/8092#change-37690 Author: tmm1 (Aman Gupta) Status: Open Priority: Normal Assignee: authorNari (Narihiro Nakamura) Category: core Target version: ruby -v: ruby 2.1.0dev (2013-03-14 trunk 39748) [x86_64-darwin12.2.1] Test with large rails app: ruby -e' require "./config/environment" stat, count = {}, {} GC.start GC.stat(stat) ObjectSpace.count_objects(count) printf "%d == %d\n", stat[:heap_live_num], count[:TOTAL]-count[:FREE] ' Without patch: 632974 == 628506 With patch: 628506 == 628506 diff --git a/gc.c b/gc.c index bd95073..48f9470 100644 --- a/gc.c +++ b/gc.c @@ -1432,10 +1432,8 @@ finalize_list(rb_objspace_t *objspace, RVALUE *p) run_final(objspace, (VALUE)p); if (!FL_TEST(p, FL_SINGLETON)) { /* not freeing page */ add_slot_local_freelist(objspace, p); - if (!is_lazy_sweeping(objspace)) { - objspace->total_freed_object_num++; - objspace->heap.free_num++; - } + objspace->total_freed_object_num++; + objspace->heap.free_num++; } else { struct heaps_slot *slot = (struct heaps_slot *)(VALUE)RDATA(p)->dmark; @@ -1939,9 +1937,9 @@ slot_sweep(rb_objspace_t *objspace, struct heaps_slot *sweep_slot) else { sweep_slot->free_next = NULL; } - objspace->total_freed_object_num += freed_num; objspace->heap.free_num += freed_num + empty_num; } + objspace->total_freed_object_num += freed_num; objspace->heap.final_num += final_num; if (deferred_final_list && !finalizing) { @@ -2965,11 +2963,11 @@ rb_gc_force_recycle(VALUE p) rb_objspace_t *objspace = &rb_objspace; struct heaps_slot *slot; + objspace->total_freed_object_num++; if (MARKED_IN_BITMAP(GET_HEAP_BITMAP(p), p)) { add_slot_local_freelist(objspace, (RVALUE *)p); } else { - objspace->total_freed_object_num++; objspace->heap.free_num++; slot = add_slot_local_freelist(objspace, (RVALUE *)p); if (slot->free_next == NULL) { -- http://bugs.ruby-lang.org/