aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-04-05 08:40:07 +0200
committerJean Boussier <jean.boussier@gmail.com>2023-07-17 11:20:15 +0200
commitfa30b99c34291cde7b17cc709552bc5681729a12 (patch)
tree84add14f8a2b05fcd00ca0ee3b6b1980b52e9540 /process.c
parentd3bcff01583abce2fb095fc67f47e86fa7005755 (diff)
downloadruby-fa30b99c34291cde7b17cc709552bc5681729a12.tar.gz
Implement Process.warmup
[Feature #18885] For now, the optimizations performed are: - Run a major GC - Compact the heap - Promote all surviving objects to oldgen Other optimizations may follow.
Diffstat (limited to 'process.c')
-rw-r--r--process.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/process.c b/process.c
index fe9c0a31d7..5761aea718 100644
--- a/process.c
+++ b/process.c
@@ -116,6 +116,7 @@ int initgroups(const char *, rb_gid_t);
#include "ruby/thread.h"
#include "ruby/util.h"
#include "vm_core.h"
+#include "vm_sync.h"
#include "ruby/ractor.h"
/* define system APIs */
@@ -8534,6 +8535,37 @@ static VALUE rb_mProcUID;
static VALUE rb_mProcGID;
static VALUE rb_mProcID_Syscall;
+/*
+ * call-seq:
+ * Process.warmup -> true
+ *
+ * Notify the Ruby virtual machine that the boot sequence is finished,
+ * and that now is a good time to optimize the application. This is useful
+ * for long running applications.
+ *
+ * This method is expected to be called at the end of the application boot.
+ * If the application is deployed using a pre-forking model, +Process.warmup+
+ * should be called in the original process before the first fork.
+ *
+ * The actual optimizations performed are entirely implementation specific
+ * and may change in the future without notice.
+ *
+ * On CRuby, +Process.warmup+:
+ *
+ * * Perform a major GC.
+ * * Compacts the heap.
+ * * Promotes all surviving objects to the old generation.
+ */
+
+static VALUE
+proc_warmup(VALUE _)
+{
+ RB_VM_LOCK_ENTER();
+ rb_gc_prepare_heap();
+ RB_VM_LOCK_LEAVE();
+ return Qtrue;
+}
+
/*
* Document-module: Process
@@ -8651,6 +8683,8 @@ InitVM_process(void)
rb_define_module_function(rb_mProcess, "getpriority", proc_getpriority, 2);
rb_define_module_function(rb_mProcess, "setpriority", proc_setpriority, 3);
+ rb_define_module_function(rb_mProcess, "warmup", proc_warmup, 0);
+
#ifdef HAVE_GETPRIORITY
/* see Process.setpriority */
rb_define_const(rb_mProcess, "PRIO_PROCESS", INT2FIX(PRIO_PROCESS));