jemalloc_ctl 0.1.4 → 0.1.5
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/LICENSE +1 -1
- data/ext/jemalloc_ctl/jemalloc_ctl.c +39 -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: d7be6090c8c75247efea4b0c3448e68d688dd449d13ad7e53a82850b54b5c83c
|
|
4
|
+
data.tar.gz: '08906468b2623758dbcdc3804df5ad24074783f83cb589274e4c5f4d819f952c'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 445148d11c6a400b26fb814ebb0698858a50e7ecceea3a7fce29d3e37efc7f66c75445337179b77c0b3db0d9a80b7a0657d5a09f01c78df0166cf1aa5e6fb844
|
|
7
|
+
data.tar.gz: 8168e928e33be6f7a3234c3a457d99fcae86b65dcd13d4ff4763de992dc9d5fd2b0dd5666e60c654060c252d0d51b1f65934d1dd8bf2458b5872018cf2916636
|
data/LICENSE
CHANGED
|
@@ -40,6 +40,10 @@ static VALUE rb_eJemallocCtlJemallocNotFound;
|
|
|
40
40
|
static VALUE main_thread_val = Qnil;
|
|
41
41
|
static int gc_exit_hook_installed = 0;
|
|
42
42
|
|
|
43
|
+
static int major_gc_purge_hook_installed = 0;
|
|
44
|
+
static size_t last_major_gc_count = 0;
|
|
45
|
+
static VALUE major_gc_count_sym = 0;
|
|
46
|
+
|
|
43
47
|
static VALUE rb_jemalloc_ctl_enabled_p(VALUE self)
|
|
44
48
|
{
|
|
45
49
|
return my_mallctl != NULL ? Qtrue : Qfalse;
|
|
@@ -137,6 +141,40 @@ static VALUE rb_jemalloc_ctl_disable_gc_exit_tcache_flush(VALUE self)
|
|
|
137
141
|
return Qtrue;
|
|
138
142
|
}
|
|
139
143
|
|
|
144
|
+
static void major_gc_arena_purge_hook(rb_event_flag_t flag, VALUE data,
|
|
145
|
+
VALUE self, ID mid, VALUE klass)
|
|
146
|
+
{
|
|
147
|
+
// Runs inside GC: must not allocate Ruby objects or raise.
|
|
148
|
+
if (my_mallctl == NULL) return;
|
|
149
|
+
|
|
150
|
+
size_t current = rb_gc_stat(major_gc_count_sym); // safe
|
|
151
|
+
if (current == last_major_gc_count) return;
|
|
152
|
+
last_major_gc_count = current;
|
|
153
|
+
|
|
154
|
+
char ctl[32];
|
|
155
|
+
snprintf(ctl, sizeof(ctl), "arena.%d.purge", MALLCTL_ARENAS_ALL);
|
|
156
|
+
my_mallctl(ctl, NULL, NULL, NULL, 0);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static VALUE rb_jemalloc_ctl_toggle_major_gc_arena_purge(VALUE self, VALUE onoff)
|
|
160
|
+
{
|
|
161
|
+
if (my_mallctl == NULL)
|
|
162
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
163
|
+
|
|
164
|
+
bool enable = RTEST(onoff);
|
|
165
|
+
if (enable && !major_gc_purge_hook_installed) {
|
|
166
|
+
if (major_gc_count_sym == 0)
|
|
167
|
+
major_gc_count_sym = ID2SYM(rb_intern("major_gc_count"));
|
|
168
|
+
last_major_gc_count = rb_gc_stat(major_gc_count_sym);
|
|
169
|
+
rb_add_event_hook(major_gc_arena_purge_hook, RUBY_INTERNAL_EVENT_GC_EXIT, Qnil);
|
|
170
|
+
major_gc_purge_hook_installed = 1;
|
|
171
|
+
} else if (!enable && major_gc_purge_hook_installed) {
|
|
172
|
+
rb_remove_event_hook(major_gc_arena_purge_hook);
|
|
173
|
+
major_gc_purge_hook_installed = 0;
|
|
174
|
+
}
|
|
175
|
+
return Qtrue;
|
|
176
|
+
}
|
|
177
|
+
|
|
140
178
|
static VALUE rb_jemalloc_ctl_purge_arenas(VALUE self)
|
|
141
179
|
{
|
|
142
180
|
if (my_mallctl == NULL)
|
|
@@ -226,4 +264,5 @@ void Init_jemalloc_ctl(void)
|
|
|
226
264
|
rb_define_singleton_method(rb_mJemallocCtl, "toggle_current_thread_tcache", rb_jemalloc_ctl_toggle_current_thread_tcache, 1);
|
|
227
265
|
rb_define_singleton_method(rb_mJemallocCtl, "enable_gc_exit_tcache_flush!", rb_jemalloc_ctl_enable_gc_exit_tcache_flush, 0);
|
|
228
266
|
rb_define_singleton_method(rb_mJemallocCtl, "disable_gc_exit_tcache_flush!", rb_jemalloc_ctl_disable_gc_exit_tcache_flush, 0);
|
|
267
|
+
rb_define_singleton_method(rb_mJemallocCtl, "toggle_major_gc_arena_purge!", rb_jemalloc_ctl_toggle_major_gc_arena_purge, 1);
|
|
229
268
|
}
|