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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6358746cbb29a35a956a8b738a3b52f2dd643256d48cb76d5ae5e55ff9c093ae
4
- data.tar.gz: 135a5d7a5e9ef51bac5709cb99d9fdacbd2f6d0245b72e49405becc270cbc3bb
3
+ metadata.gz: d7be6090c8c75247efea4b0c3448e68d688dd449d13ad7e53a82850b54b5c83c
4
+ data.tar.gz: '08906468b2623758dbcdc3804df5ad24074783f83cb589274e4c5f4d819f952c'
5
5
  SHA512:
6
- metadata.gz: 24b769826c3f509efc442aeca2ee62ce768b27f86b2f9f6ee12e8a624b01420042d0ee2d7b420b73e19e7704e4f6f2172f607e47638d7d7c15377215386b8827
7
- data.tar.gz: 7e8ab5599ff137fb5b8fe8efd9e96eda75e9bb1cab439a39bea39d7fb6e9f9f179e8b21b6b239e83c0143383c4b4fc8a4ce01cacca49e9eee5a851a156efbfbc
6
+ metadata.gz: 445148d11c6a400b26fb814ebb0698858a50e7ecceea3a7fce29d3e37efc7f66c75445337179b77c0b3db0d9a80b7a0657d5a09f01c78df0166cf1aa5e6fb844
7
+ data.tar.gz: 8168e928e33be6f7a3234c3a457d99fcae86b65dcd13d4ff4763de992dc9d5fd2b0dd5666e60c654060c252d0d51b1f65934d1dd8bf2458b5872018cf2916636
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Luke Gruber
3
+ Copyright (c) Shopify Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -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
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jemalloc_ctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Gruber