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

ruby-changes:71083

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

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

From a9221406aa3177f98be507ff5474f2f7d78b481a Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
Date: Thu, 3 Feb 2022 11:45:37 -0500
Subject: Move total_allocated_pages to size pool

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

diff --git a/gc.c b/gc.c
index 0309559481..e7cd8c373a 100644
--- a/gc.c
+++ b/gc.c
@@ -689,6 +689,9 @@ typedef struct rb_size_pool_struct { https://github.com/ruby/ruby/blob/trunk/gc.c#L689
 
     size_t allocatable_pages;
 
+    /* Basic statistics */
+    size_t total_allocated_pages;
+
 #if USE_RVARGC
     /* Sweeping statistics */
     size_t freed_slots;
@@ -716,6 +719,7 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L719
 	size_t allocated_size;
 	size_t allocations;
 #endif
+
     } malloc_params;
 
     struct {
@@ -805,7 +809,6 @@ typedef struct rb_objspace { https://github.com/ruby/ruby/blob/trunk/gc.c#L809
 	/* basic statistics */
 	size_t count;
 	size_t total_freed_objects;
-	size_t total_allocated_pages;
 	size_t total_freed_pages;
         uint64_t total_time_ns;
         struct timespec start_time;
@@ -1071,6 +1074,17 @@ heap_allocatable_slots(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L1074
     return count;
 }
 
+static inline size_t
+total_allocated_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_allocated_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))
 
@@ -2042,7 +2056,7 @@ heap_page_allocate(rb_objspace_t *objspace, rb_size_pool_t *size_pool) https://github.com/ruby/ruby/blob/trunk/gc.c#L2056
     GC_ASSERT(heap_eden_total_pages(objspace) + heap_tomb_total_pages(objspace) == heap_allocated_pages - 1);
     GC_ASSERT(heap_allocated_pages <= heap_pages_sorted_length);
 
-    objspace->profile.total_allocated_pages++;
+    size_pool->total_allocated_pages++;
 
     if (heap_allocated_pages > heap_pages_sorted_length) {
 	rb_bug("heap_page_allocate: allocated(%"PRIdSIZE") > sorted(%"PRIdSIZE")",
@@ -10655,7 +10669,7 @@ gc_stat_internal(VALUE hash_or_sym) https://github.com/ruby/ruby/blob/trunk/gc.c#L10669
     SET(heap_marked_slots, objspace->marked_slots);
     SET(heap_eden_pages, heap_eden_total_pages(objspace));
     SET(heap_tomb_pages, heap_tomb_total_pages(objspace));
-    SET(total_allocated_pages, objspace->profile.total_allocated_pages);
+    SET(total_allocated_pages, total_allocated_pages(objspace));
     SET(total_freed_pages, objspace->profile.total_freed_pages);
     SET(total_allocated_objects, objspace->total_allocated_objects);
     SET(total_freed_objects, objspace->profile.total_freed_objects);
@@ -10745,6 +10759,7 @@ enum gc_stat_heap_sym { https://github.com/ruby/ruby/blob/trunk/gc.c#L10759
     gc_stat_heap_sym_heap_eden_slots,
     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_last
 };
 
@@ -10761,6 +10776,7 @@ setup_gc_stat_heap_symbols(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L10776
         S(heap_eden_slots);
         S(heap_tomb_pages);
         S(heap_tomb_slots);
+        S(total_allocated_pages);
 #undef S
     }
 }
@@ -10801,6 +10817,7 @@ gc_stat_heap_internal(int size_pool_idx, VALUE hash_or_sym) https://github.com/ruby/ruby/blob/trunk/gc.c#L10817
     SET(heap_eden_slots, SIZE_POOL_EDEN_HEAP(size_pool)->total_slots);
     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);
 #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 fc49659c27..e19df8f2f9 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -158,6 +158,7 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L158
       assert_operator stat_heap[:heap_eden_slots], :>=, 0
       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
     end
 
     GC.stat_heap(0, stat_heap)
@@ -203,6 +204,7 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L204
     assert_equal stat[:heap_eden_pages], stat_heap_sum[:heap_eden_pages]
     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]
   end
 
   def test_latest_gc_info
-- 
cgit v1.2.1


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

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