summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-02-03 11:45:37 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-02-03 15:06:55 -0500
commita9221406aa3177f98be507ff5474f2f7d78b481a (patch)
tree9b8e828a1d10ee33dab06282e8794c79c67665ee
parent424374d3302d8d25165007e7afedf14b1a76d23e (diff)
Move total_allocated_pages to size pool
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5523
-rw-r--r--gc.c23
-rw-r--r--test/ruby/test_gc.rb2
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 {
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 {
size_t allocated_size;
size_t allocations;
#endif
+
} malloc_params;
struct {
@@ -805,7 +809,6 @@ typedef struct rb_objspace {
/* 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)
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)
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)
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 {
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)
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)
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
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
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