Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/exec: "fork/exec ... cannot allocate memory" on linux,!amd64 #31936

Open
4a6f656c opened this issue May 9, 2019 · 2 comments

Comments

@4a6f656c
Copy link
Contributor

commented May 9, 2019

What version of Go are you using (go version)?

$ go version
go version devel +5286b2a Thu May 9 14:58:03 2019 +0000 linux/s390x

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux/s390x

What did you do?

On a linux/s390x LPAR with 12GB of RAM:

package main

import (
        "log"
        "os/exec"
)

func main() {
        c := 8 * 1024 * 1024 * 1024
        a := make([]byte, c, c)
        for i := range a {
                a[i] = byte(i % 255)
        }

        log.Print(exec.Command("sleep", "1").Run())
}
$ go build -o fork fork.go

What did you expect to see?

$ ./fork
2019/05/07 04:21:46 <nil>

What did you see instead?

$ ./fork
2019/05/07 03:59:54 fork/exec /bin/sleep: cannot allocate memory

This causes a production impact since various Go programs cannot fork/exec (including the Go compiler at times).

This is reproducable under Linux on most architectures aside from linux/amd64, where the problem has been addressed via issue #5838. The memory consumption will need to be altered depending on the available host memory.

@bradfitz bradfitz added the NeedsFix label May 9, 2019

@bradfitz bradfitz added this to the Go1.14 milestone May 9, 2019

@gopherbot

This comment has been minimized.

Copy link

commented May 9, 2019

Change https://golang.org/cl/175697 mentions this issue: syscall: implement rawVforkSyscall for remaining linux platforms

gopherbot pushed a commit that referenced this issue May 15, 2019
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot

This comment has been minimized.

Copy link

commented Aug 8, 2019

Change https://golang.org/cl/189418 mentions this issue: syscall: implement rawVforkSyscall for linux/arm64

gopherbot pushed a commit that referenced this issue Sep 11, 2019
syscall: implement rawVforkSyscall for linux/arm64
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 linux/arm64.

With CLONE_VM the child process shares the same memory with the parent
process. On its own this would lead to conflicting use of the same
memory, so CLONE_VFORK is used to suspend the parent process until the
child releases the memory when switching to the new program binary
via the exec syscall. When the parent process continues to run, one
has to consider the changes to memory that the child process did,
namely the return address of the syscall function needs to be restored
from a register.

exec.Command() callers can start in a faster manner, as child process who
do exec commands job can be cloned faster via vfork than via fork on arm64.

The same problem was addressed on linux/amd64 via issue #5838.

Updates #31936
Contributed by Howard Zhang <howard.zhang@arm.com> and Bin Lu <bin.lu@arm.com>

Change-Id: Ia99d81d877f564ec60d19f17e596276836576eaf
Reviewed-on: https://go-review.googlesource.com/c/go/+/189418
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.