summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2022-01-11 12:47:22 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2022-01-21 14:34:53 -0800
commitfc6fd4c31e957a4b15ba2c03cbd1cea0a8af6513 (patch)
treeec1681ac98d098f35d2751fd4d33138d3141f8a0 /vm.c
parent5e3a32021849718ae483eaaa9fbf155f91828039 (diff)
Accurately report VM memsize
Currently the calculation only counts the size of the struct. This commit adds the size of the associated st tables, id tables, and linked lists. Still missing is the size of the ractors and (potentially) the size of the object space.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5428
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c56
1 files changed, 52 insertions, 4 deletions
diff --git a/vm.c b/vm.c
index 634ed15884..cb7007ac13 100644
--- a/vm.c
+++ b/vm.c
@@ -2731,17 +2731,65 @@ ruby_vm_destruct(rb_vm_t *vm)
return 0;
}
+size_t rb_vm_memsize_waiting_list(struct list_head *waiting_list); // process.c
+size_t rb_vm_memsize_waiting_fds(struct list_head *waiting_fds); // thread.c
+size_t rb_vm_memsize_postponed_job_buffer(); // vm_trace.c
+size_t rb_vm_memsize_workqueue(struct list_head *workqueue); // vm_trace.c
+
+// Used for VM memsize reporting. Returns the size of the at_exit list by
+// looping through the linked list and adding up the size of the structs.
static size_t
-vm_memsize(const void *ptr)
+vm_memsize_at_exit_list(rb_at_exit_list *at_exit)
{
- size_t size = sizeof(rb_vm_t);
+ size_t size = 0;
- // TODO
- // size += vmobj->ractor_num * sizeof(rb_ractor_t);
+ while (at_exit) {
+ size += sizeof(rb_at_exit_list);
+ at_exit = at_exit->next;
+ }
return size;
}
+// Used for VM memsize reporting. Returns the size of the builtin function
+// table if it has been defined.
+static size_t
+vm_memsize_builtin_function_table(const struct rb_builtin_function *builtin_function_table)
+{
+ return builtin_function_table == NULL ? 0 : sizeof(struct rb_builtin_function);
+}
+
+// Reports the memsize of the VM struct object and the structs that are
+// associated with it.
+static size_t
+vm_memsize(const void *ptr)
+{
+ rb_vm_t *vm = GET_VM();
+
+ return (
+ sizeof(rb_vm_t) +
+ rb_vm_memsize_waiting_list(&vm->waiting_pids) +
+ rb_vm_memsize_waiting_list(&vm->waiting_grps) +
+ rb_vm_memsize_waiting_fds(&vm->waiting_fds) +
+ rb_st_memsize(vm->loaded_features_index) +
+ rb_st_memsize(vm->loading_table) +
+ rb_st_memsize(vm->ensure_rollback_table) +
+ rb_vm_memsize_postponed_job_buffer() +
+ rb_vm_memsize_workqueue(&vm->workqueue) +
+ rb_st_memsize(vm->defined_module_hash) +
+ vm_memsize_at_exit_list(vm->at_exit) +
+ rb_st_memsize(vm->frozen_strings) +
+ vm_memsize_builtin_function_table(vm->builtin_function_table) +
+ rb_id_table_memsize(vm->negative_cme_table) +
+ rb_st_memsize(vm->overloaded_cme_table)
+ );
+
+ // TODO
+ // struct { struct list_head set; } ractor;
+ // void *main_altstack; #ifdef USE_SIGALTSTACK
+ // struct rb_objspace *objspace;
+}
+
static const rb_data_type_t vm_data_type = {
"VM",
{0, 0, vm_memsize,},