* [PATCH] gc.c (Init_GC): clamp M_ARENA_MAX=2 for glibc malloc
@ 2018-05-15 8:10 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2018-05-15 8:10 UTC (permalink / raw)
To: spew
glibc malloc creates too many arenas and leads to fragmentation.
Given the existence of the GVL, clamping to two arenas seems
to be a reasonable trade-off for performance and memory usage.
Some users (including myself for several years, now) prefer only
one arena, now, so continue to respect users' wishes when
MALLOC_ARENA_MAX is set.
Thanks to Mike Perham for the reminder [ruby-core:86843]
---
configure.ac | 1 +
gc.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/configure.ac b/configure.ac
index c1f6525634..c9c24c6bc6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1788,6 +1788,7 @@ AC_CHECK_FUNCS(lstat)
AC_CHECK_FUNCS(lutimes)
AC_CHECK_FUNCS(malloc_usable_size)
AC_CHECK_FUNCS(malloc_size)
+AC_CHECK_FUNCS(mallopt)
AC_CHECK_FUNCS(mblen)
AC_CHECK_FUNCS(memalign)
AC_CHECK_FUNCS(memset_s)
diff --git a/gc.c b/gc.c
index bd52966bf1..613c184083 100644
--- a/gc.c
+++ b/gc.c
@@ -9755,4 +9755,14 @@ Init_GC(void)
#undef OPT
OBJ_FREEZE(opts);
}
+
+#if defined(HAVE_MALLOPT) && defined(M_ARENA_MAX)
+ /*
+ * Ruby doesn't benefit from many glibc malloc arenas due to GVL,
+ * remove or increase when we get Guilds
+ */
+ if (!getenv("MALLOC_ARENA_MAX")) {
+ mallopt(M_ARENA_MAX, 2);
+ }
+#endif
}
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-05-15 8:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-15 8:10 [PATCH] gc.c (Init_GC): clamp M_ARENA_MAX=2 for glibc malloc Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).