From 9b16f906922fcb63a35c41b57bcec91f5791ad66 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 3 Sep 2014 03:06:17 +0000 Subject: * process.c (retry_fork_async_signal_safe): Use vfork() if available. vfork() is still faster than fork() especially when the parent process uses big memory. ruby -rbenchmark -e 'a = "a" * 1_000_000_000; puts Benchmark.measure { system("true") }' fork: 0.000000 0.010000 0.010000 ( 0.014968) vfork: 0.000000 0.000000 0.000000 ( 0.000912) on Debian sid. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'process.c') diff --git a/process.c b/process.c index 89f829c846..503e73923d 100644 --- a/process.c +++ b/process.c @@ -50,6 +50,9 @@ #ifdef HAVE_SYS_RESOURCE_H # include #endif +#ifdef HAVE_VFORK_H +# include +#endif #ifdef HAVE_SYS_PARAM_H # include #endif @@ -3291,7 +3294,11 @@ retry_fork_async_signal_safe(int *status, int *ep, while (1) { prefork(); +#ifdef HAVE_WORKING_VFORK + pid = vfork(); +#else pid = fork(); +#endif if (pid == 0) {/* fork succeed, child process */ int ret; forked_child = 1; @@ -3305,6 +3312,7 @@ retry_fork_async_signal_safe(int *status, int *ep, _exit(127); #endif } + forked_child = 0; /* for vfork(). */ if (0 < pid) /* fork succeed, parent process */ return pid; /* fork failed */ -- cgit v1.2.3