jemalloc_ctl 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/jemalloc_ctl/jemalloc_ctl.c +42 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6358746cbb29a35a956a8b738a3b52f2dd643256d48cb76d5ae5e55ff9c093ae
|
|
4
|
+
data.tar.gz: 135a5d7a5e9ef51bac5709cb99d9fdacbd2f6d0245b72e49405becc270cbc3bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24b769826c3f509efc442aeca2ee62ce768b27f86b2f9f6ee12e8a624b01420042d0ee2d7b420b73e19e7704e4f6f2172f607e47638d7d7c15377215386b8827
|
|
7
|
+
data.tar.gz: 7e8ab5599ff137fb5b8fe8efd9e96eda75e9bb1cab439a39bea39d7fb6e9f9f179e8b21b6b239e83c0143383c4b4fc8a4ce01cacca49e9eee5a851a156efbfbc
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
|
+
#include <ruby/debug.h>
|
|
2
3
|
#include <dlfcn.h>
|
|
3
4
|
#include <stdbool.h>
|
|
4
5
|
|
|
@@ -36,6 +37,9 @@ static VALUE rb_mJemallocCtl;
|
|
|
36
37
|
static VALUE rb_eJemallocCtlError;
|
|
37
38
|
static VALUE rb_eJemallocCtlJemallocNotFound;
|
|
38
39
|
|
|
40
|
+
static VALUE main_thread_val = Qnil;
|
|
41
|
+
static int gc_exit_hook_installed = 0;
|
|
42
|
+
|
|
39
43
|
static VALUE rb_jemalloc_ctl_enabled_p(VALUE self)
|
|
40
44
|
{
|
|
41
45
|
return my_mallctl != NULL ? Qtrue : Qfalse;
|
|
@@ -97,6 +101,42 @@ static VALUE rb_jemalloc_ctl_flush_current_thread_tcache(VALUE self)
|
|
|
97
101
|
return Qtrue;
|
|
98
102
|
}
|
|
99
103
|
|
|
104
|
+
static void gc_exit_tcache_flush_hook(rb_event_flag_t flag, VALUE data,
|
|
105
|
+
VALUE self, ID mid, VALUE klass)
|
|
106
|
+
{
|
|
107
|
+
// Runs inside GC: must not allocate Ruby objects or raise.
|
|
108
|
+
if (my_mallctl == NULL) return;
|
|
109
|
+
if (rb_thread_current() == main_thread_val) return;
|
|
110
|
+
my_mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE rb_jemalloc_ctl_enable_gc_exit_tcache_flush(VALUE self)
|
|
114
|
+
{
|
|
115
|
+
if (my_mallctl == NULL)
|
|
116
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
117
|
+
|
|
118
|
+
if (gc_exit_hook_installed)
|
|
119
|
+
return Qfalse;
|
|
120
|
+
|
|
121
|
+
if (main_thread_val == Qnil) {
|
|
122
|
+
main_thread_val = rb_thread_main();
|
|
123
|
+
rb_gc_register_address(&main_thread_val);
|
|
124
|
+
}
|
|
125
|
+
rb_add_event_hook(gc_exit_tcache_flush_hook, RUBY_INTERNAL_EVENT_GC_EXIT, Qnil);
|
|
126
|
+
gc_exit_hook_installed = 1;
|
|
127
|
+
return Qtrue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static VALUE rb_jemalloc_ctl_disable_gc_exit_tcache_flush(VALUE self)
|
|
131
|
+
{
|
|
132
|
+
if (!gc_exit_hook_installed)
|
|
133
|
+
return Qfalse;
|
|
134
|
+
|
|
135
|
+
rb_remove_event_hook(gc_exit_tcache_flush_hook);
|
|
136
|
+
gc_exit_hook_installed = 0;
|
|
137
|
+
return Qtrue;
|
|
138
|
+
}
|
|
139
|
+
|
|
100
140
|
static VALUE rb_jemalloc_ctl_purge_arenas(VALUE self)
|
|
101
141
|
{
|
|
102
142
|
if (my_mallctl == NULL)
|
|
@@ -184,4 +224,6 @@ void Init_jemalloc_ctl(void)
|
|
|
184
224
|
rb_define_singleton_method(rb_mJemallocCtl, "purge_arenas", rb_jemalloc_ctl_purge_arenas, 0);
|
|
185
225
|
rb_define_singleton_method(rb_mJemallocCtl, "flush_current_thread_tcache", rb_jemalloc_ctl_flush_current_thread_tcache, 0);
|
|
186
226
|
rb_define_singleton_method(rb_mJemallocCtl, "toggle_current_thread_tcache", rb_jemalloc_ctl_toggle_current_thread_tcache, 1);
|
|
227
|
+
rb_define_singleton_method(rb_mJemallocCtl, "enable_gc_exit_tcache_flush!", rb_jemalloc_ctl_enable_gc_exit_tcache_flush, 0);
|
|
228
|
+
rb_define_singleton_method(rb_mJemallocCtl, "disable_gc_exit_tcache_flush!", rb_jemalloc_ctl_disable_gc_exit_tcache_flush, 0);
|
|
187
229
|
}
|