summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-24 20:31:59 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-04-24 20:31:59 +0000
commitacbbf8b0cac188bca76e28dc5e345ce4a799f8b0 (patch)
treea197a151cc22f583f1d54c034a33797ac86cbcbf /eval.c
parent2c8f16e6c0ca8ae886615c048ee14d362bac05f8 (diff)
eval.c (ruby_setup): disable THP on Linux
Transparent Huge Pages (THP) decrease the effectiveness of CoW-friendly GC because it decreases page granularity. That is, a forked process dirtying one bit of CoW-shared memory can trigger a copy of a huge page (2MB on x86-64) instead of a smaller, standard page (4K). * eval.c (ruby_setup): disable THP on Linux [ruby-core:86651] [Feature #14705] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 9fa534f..6bd9e05 100644
--- a/eval.c
+++ b/eval.c
@@ -20,6 +20,9 @@
#include "mjit.h"
#include "probes.h"
#include "probes_helper.h"
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
NORETURN(void rb_raise_jump(VALUE, VALUE));
@@ -52,6 +55,14 @@ ruby_setup(void)
return 0;
ruby_init_stack((void *)&state);
+
+ /*
+ * Disable THP early before mallocs happen because we want this to
+ * affect as many future pages as possible for CoW-friendliness
+ */
+#if defined(__linux__) && defined(PR_SET_THP_DISABLE)
+ prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
+#endif
Init_BareVM();
Init_heap();
Init_vm_objects();