Replacing syscall(_NR_fork) on linux with syscall(_NR_clone) (original) (raw)

Martin Buchholz martinrb at google.com
Fri Apr 10 14:19:02 UTC 2015


At Google, we also had trouble with syscall(__NR_fork). We switched to simply calling fork despite the ominous warnings and have had no trouble since. We avoid calling clone - see my old failures with it in UNIXProcess_md.c. Although if we follow the successful precedent of UNIXProcess_md.c we should call vfork instead, but we haven't yet had the need.

@@ -6012,8 +6689,15 @@ // separate process to execve. Make a direct syscall to fork process. // On IA64 there's no fork syscall, we have to use fork() and hope for // the best...

@@ -6029,10 +6713,16 @@ // in the new process, so make a system call directly. // IA64 should use normal execve() from glibc to match the glibc fork() // above.

execve

errno %d: %s",

On Fri, Apr 10, 2015 at 12:47 AM, David Holmes <david.holmes at oracle.com> wrote:

In os::forkandexec we provide a per platform fork/exec implementation for use by the OnError and OnOutOfMemory JVM options.

On linux this is implemented with direct syscalls to NRfork (sysfork) and NRexecve. We already encountered a problem on linux-sparc: http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/ 2015-February/013811.html due to a different register usage for the return value, which is so far restricted to the 7u train but will need addressing in 8u and 9. Further it seems that the fork syscall has actually been deprecated for quite some time and we are now seeing kernels on some platforms which are no longer providing any of the deprecated syscalls - we simply get an error ENOSYS. The fork() library was updated to use clone a long time ago, but as I understand it we can't use the fork() library call because we might be executing in a signal-handling context within the error handler. So I'm considering switching to use the clone syscall for all linux systems. Thoughts/comments? David



More information about the hotspot-dev mailing list