[前][次][番号順一覧][スレッド一覧]

ruby-changes:71084

From: Peter <ko1@a...>
Date: Fri, 4 Feb 2022 05:07:21 +0900 (JST)
Subject: [ruby-changes:71084] af321ea727 (master): Move total_freed_pages to size pool

https://git.ruby-lang.org/ruby.git/commit/?id=af321ea727

From af321ea7273e43d65ea7f5743f56e10dcd4e98b0 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Thu, 3 Feb 2022 11:51:20 -0500
Subject: Move total_freed_pages to size pool

---
 gc.c                 | 20 +++++++++++++++++---
 test/ruby/test_gc.rb |  2 ++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gc.c b/gc.c
index e7cd8c373a..e637861ab2 100644
--- a/gc.c
+++ b/gc.c
@@ -691,6 +691,7 @@ typedef struct rb_size_pool_struct { https://github.com/ruby/ruby/blob/trunk/gc.c#L691
 
     /* Basic statistics */
     size_t total_allocated_pages;
+    size_t total_freed_pages;
 
 #if USE_RVARGC
     /* Sweeping statistics */
@@ -809,7 +810,6 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L810
 	/* basic statistics */
 	size_t count;
 	size_t total_freed_objects;
-	size_t total_freed_pages;
         uint64_t total_time_ns;
         struct timespec start_time;
     } profile;
@@ -1085,6 +1085,17 @@ total_allocated_pages(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L1085
     return count;
 }
 
+static inline size_t
+total_freed_pages(rb_objspace_t *objspace)
+{
+    size_t count = 0;
+    for (int i = 0; i < SIZE_POOL_COUNT; i++) {
+        rb_size_pool_t *size_pool = &size_pools[i];
+        count += size_pool->total_freed_pages;
+    }
+    return count;
+}
+
 #define gc_mode(objspace)                gc_mode_verify((enum gc_mode)(objspace)->flags.mode)
 #define gc_mode_set(objspace, mode)      ((objspace)->flags.mode = (unsigned int)gc_mode_verify(mode))
 
@@ -1937,7 +1948,7 @@ static void https://github.com/ruby/ruby/blob/trunk/gc.c#L1948
 heap_page_free(rb_objspace_t *objspace, struct heap_page *page)
 {
     heap_allocated_pages--;
-    objspace->profile.total_freed_pages++;
+    page->size_pool->total_freed_pages++;
     rb_aligned_free(GET_PAGE_BODY(page->start), HEAP_PAGE_SIZE);
     free(page);
 }
@@ -10670,7 +10681,7 @@ gc_stat_internal(VALUE hash_or_sym) https://github.com/ruby/ruby/blob/trunk/gc.c#L10681
     SET(heap_eden_pages, heap_eden_total_pages(objspace));
     SET(heap_tomb_pages, heap_tomb_total_pages(objspace));
     SET(total_allocated_pages, total_allocated_pages(objspace));
-    SET(total_freed_pages, objspace->profile.total_freed_pages);
+    SET(total_freed_pages, total_freed_pages(objspace));
     SET(total_allocated_objects, objspace->total_allocated_objects);
     SET(total_freed_objects, objspace->profile.total_freed_objects);
     SET(malloc_increase_bytes, malloc_increase);
@@ -10760,6 +10771,7 @@ enum gc_stat_heap_sym { https://github.com/ruby/ruby/blob/trunk/gc.c#L10771
     gc_stat_heap_sym_heap_tomb_pages,
     gc_stat_heap_sym_heap_tomb_slots,
     gc_stat_heap_sym_total_allocated_pages,
+    gc_stat_heap_sym_total_freed_pages,
     gc_stat_heap_sym_last
 };
 
@@ -10777,6 +10789,7 @@ setup_gc_stat_heap_symbols(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L10789
         S(heap_tomb_pages);
         S(heap_tomb_slots);
         S(total_allocated_pages);
+        S(total_freed_pages);
 #undef S
     }
 }
@@ -10818,6 +10831,7 @@ gc_stat_heap_internal(int size_pool_idx, VALUE hash_or_sym) https://github.com/ruby/ruby/blob/trunk/gc.c#L10831
     SET(heap_tomb_pages, SIZE_POOL_TOMB_HEAP(size_pool)->total_pages);
     SET(heap_tomb_slots, SIZE_POOL_TOMB_HEAP(size_pool)->total_slots);
     SET(total_allocated_pages, size_pool->total_allocated_pages);
+    SET(total_freed_pages, size_pool->total_freed_pages);
 #undef SET
 
     if (!NIL_P(key)) { /* matched key should return above */
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index e19df8f2f9..b081e9fa78 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -159,6 +159,7 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L159
       assert_operator stat_heap[:heap_tomb_pages], :<=, stat[:heap_tomb_pages]
       assert_operator stat_heap[:heap_tomb_slots], :>=, 0
       assert_operator stat_heap[:total_allocated_pages], :>=, 0
+      assert_operator stat_heap[:total_freed_pages], :>=, 0
     end
 
     GC.stat_heap(0, stat_heap)
@@ -205,6 +206,7 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L206
     assert_equal stat[:heap_tomb_pages], stat_heap_sum[:heap_tomb_pages]
     assert_equal stat[:heap_available_slots], stat_heap_sum[:heap_eden_slots] + stat_heap_sum[:heap_tomb_slots]
     assert_equal stat[:total_allocated_pages], stat_heap_sum[:total_allocated_pages]
+    assert_equal stat[:total_freed_pages], stat_heap_sum[:total_freed_pages]
   end
 
   def test_latest_gc_info
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]