diff options
| author | Russ Cox <rsc@golang.org> | 2013-08-15 22:34:06 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-08-15 22:34:06 -0400 |
| commit | 757e0de89f80e89626cc8b7d6e670c0e5ea7f192 (patch) | |
| tree | 42b7768f368edc26299146007ebf0777618fa677 /src/pkg/runtime/debug/garbage.go | |
| parent | 205329aaf2ec9aff13c4052f6dfa552e65760ea9 (diff) | |
| download | go-757e0de89f80e89626cc8b7d6e670c0e5ea7f192.tar.xz | |
runtime: impose stack size limit
The goal is to stop only those programs that would keep
going and run the machine out of memory, but before they do that.
1 GB on 64-bit, 250 MB on 32-bit.
That seems implausibly large, and it can be adjusted.
Fixes #2556.
Fixes #4494.
Fixes #5173.
R=khr, r, dvyukov
CC=golang-dev
https://golang.org/cl/12541052
Diffstat (limited to 'src/pkg/runtime/debug/garbage.go')
| -rw-r--r-- | src/pkg/runtime/debug/garbage.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/pkg/runtime/debug/garbage.go b/src/pkg/runtime/debug/garbage.go index 8f30264264..3658feaaf8 100644 --- a/src/pkg/runtime/debug/garbage.go +++ b/src/pkg/runtime/debug/garbage.go @@ -24,6 +24,7 @@ func readGCStats(*[]time.Duration) func enableGC(bool) bool func setGCPercent(int) int func freeOSMemory() +func setMaxStack(int) int // ReadGCStats reads statistics about garbage collection into stats. // The number of entries in the pause history is system-dependent; @@ -99,3 +100,17 @@ func SetGCPercent(percent int) int { func FreeOSMemory() { freeOSMemory() } + +// SetMaxStack sets the maximum amount of memory that +// can be used by a single goroutine stack. +// If any goroutine exceeds this limit while growing its stack, +// the program crashes. +// SetMaxStack returns the previous setting. +// The initial setting is 1 GB on 64-bit systems, 250 MB on 32-bit systems. +// +// SetMaxStack is useful mainly for limiting the damage done by +// goroutines that enter an infinite recursion. It only limits future +// stack growth. +func SetMaxStack(bytes int) int { + return setMaxStack(bytes) +} |
