Module: MallocTrim
- Defined in:
- lib/malloc_trim.rb,
lib/malloc_trim/version.rb,
ext/malloc_trim/malloc_trim.c
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.disable_trimming ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'ext/malloc_trim/malloc_trim.c', line 50
static VALUE disable_trimming(VALUE self) {
#ifndef HAVE_MALLOC_TRIM
return Qnil;
#endif
if (RB_TEST(objtracer)) {
rb_tracepoint_disable(objtracer);
}
objtracer = Qnil;
return Qtrue;
}
|
.enable_trimming ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'ext/malloc_trim/malloc_trim.c', line 38
static VALUE enable_trimming(VALUE self) {
#ifndef HAVE_MALLOC_TRIM
return Qnil;
#endif
if (!RB_TEST(objtracer)) {
objtracer = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_GC_END_MARK, malloc_trim_gc_end_handler, 0);
}
rb_tracepoint_enable(objtracer);
return Qtrue;
}
|
.trim ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'ext/malloc_trim/malloc_trim.c', line 7
static VALUE do_malloc_trim(VALUE self) {
/* [Experimental] Explicitly free all eligible pages to the kernel. See:
*
* - https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html
* - https://bugs.ruby-lang.org/issues/15667
* - http://man7.org/linux/man-pages/man3/malloc_trim.3.html
*/
#ifdef HAVE_MALLOC_TRIM
if (malloc_trim(0) == 1) {
return Qtrue; // it could return some memory
} else {
return Qfalse; // no memory was returned
};
#endif
return Qnil;
}
|
.trimming_possible? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'ext/malloc_trim/malloc_trim.c', line 24 static VALUE has_malloc_trim(VALUE self) { #ifdef HAVE_MALLOC_TRIM return Qtrue; #else return Qfalse; #endif } |