From ab242dcbc92803788b135816823536c4007137e3 Mon Sep 17 00:00:00 2001 From: Joel Sing Date: Tue, 7 May 2019 17:56:49 +1000 Subject: syscall: implement rawVforkSyscall for linux/ppc64x and linux/s390x This allows the use of CLONE_VFORK and CLONE_VM for fork/exec, preventing "fork/exec ...: cannot allocate memory" failures from occuring when attempting to execute commands from a Go process that has a large memory footprint. Additionally, this should reduce the latency of fork/exec on these platforms. The same problem was addressed on linux/amd64 via issue #5838. Updates #31936 Change-Id: I7ae0fbbeaa29cab944a49a11272a380d497eb2d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/175697 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/syscall/exec_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/syscall/exec_linux.go') diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 3493f4b32b..a2242b2057 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -196,12 +196,14 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att } } + hasRawVforkSyscall := runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "s390x" + // About to call fork. // No more allocation or calls of non-assembly functions. runtime_BeforeFork() locked = true switch { - case runtime.GOARCH == "amd64" && (sys.Cloneflags&CLONE_NEWUSER == 0 && sys.Unshareflags&CLONE_NEWUSER == 0): + case hasRawVforkSyscall && (sys.Cloneflags&CLONE_NEWUSER == 0 && sys.Unshareflags&CLONE_NEWUSER == 0): r1, err1 = rawVforkSyscall(SYS_CLONE, uintptr(SIGCHLD|CLONE_VFORK|CLONE_VM)|sys.Cloneflags) case runtime.GOARCH == "s390x": r1, _, err1 = RawSyscall6(SYS_CLONE, 0, uintptr(SIGCHLD)|sys.Cloneflags, 0, 0, 0, 0) -- cgit v1.3-5-g45d5