From 8304907db07a4c6f7ef3164be77c1bacc94d6d51 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 19 Jul 2019 09:51:07 +0200 Subject: tools/syz-env: restrict Makefile parallelism based on RAM Ensure that we have at least 1GB per Makefile job. Go compiler/linker can consume significant amount of memory (observed to consume at least 600MB). See #1276 for context. Update #1276 --- tools/syz-env/env.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/syz-env/env.go b/tools/syz-env/env.go index cae88c5a9..aa0143ab9 100644 --- a/tools/syz-env/env.go +++ b/tools/syz-env/env.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" + "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/sys/targets" ) @@ -29,6 +30,16 @@ func main() { Name string Val string } + parallelism := runtime.NumCPU() + if mem := osutil.SystemMemorySize(); mem != 0 { + // Ensure that we have at least 1GB per Makefile job. + // Go compiler/linker can consume significant amount of memory + // (observed to consume at least 600MB). See #1276 for context. + memLimit := int(mem / (1 << 30)) + if parallelism > memLimit { + parallelism = memLimit + } + } vars := []Var{ {"BUILDOS", runtime.GOOS}, {"NATIVEBUILDOS", target.BuildOS}, @@ -39,7 +50,7 @@ func main() { {"TARGETVMARCH", targetVMArch}, {"CC", target.CCompiler}, {"ADDCFLAGS", strings.Join(target.CrossCFlags, " ")}, - {"NCORES", strconv.Itoa(runtime.NumCPU())}, + {"NCORES", strconv.Itoa(parallelism)}, {"EXE", target.ExeExtension}, {"NATIVEBUILDOS", target.BuildOS}, } -- cgit mrf-deployment