add ruby_gc_malloc_trim.patch

rvm install 2.7.6 -C --with-jemalloc --patch ruby_gc_malloc_trim.patch
This commit is contained in:
邱博亞 2023-12-23 11:11:23 +08:00
parent 78f1100319
commit 224705bae7
1 changed files with 33 additions and 0 deletions

33
ruby_gc_malloc_trim.patch Normal file
View File

@ -0,0 +1,33 @@
diff --git a/configure.ac b/configure.ac
index d251da9915..5e2a67db1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1825,6 +1825,7 @@ AC_CHECK_FUNCS(lstat)
AC_CHECK_FUNCS(lutimes)
AC_CHECK_FUNCS(malloc_usable_size)
AC_CHECK_FUNCS(malloc_size)
+AC_CHECK_FUNCS(malloc_trim)
AC_CHECK_FUNCS(mblen)
AC_CHECK_FUNCS(memalign)
AC_CHECK_FUNCS(memset_s)
diff --git a/gc.c b/gc.c
index 1331ef21dc..12caa162e7 100644
--- a/gc.c
+++ b/gc.c
@@ -6660,7 +6660,15 @@ gc_start(rb_objspace_t *objspace, int reason)
gc_prof_timer_start(objspace);
{
- gc_marks(objspace, do_full_mark);
+ gc_marks(objspace, do_full_mark);
+#ifdef HAVE_MALLOC_TRIM
+ /* [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
+ */
+ if (do_full_mark) malloc_trim(0);
+#endif
}
gc_prof_timer_stop(objspace);