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 · 1 comment

Comments

Projects
None yet
3 participants
@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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.