aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/stack.h
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2014-09-17 08:32:15 -0700
committerKeith Randall <khr@golang.org>2014-09-17 08:32:15 -0700
commit6c934238c93f8f60775409f1ab410ce9c9ea2357 (patch)
treeefec42d8353a3e0ff69b6f713fd60adafc8c88d7 /src/runtime/stack.h
parent72a2539c38d06be486b180310d5703700f9f1f5f (diff)
downloadgo-6c934238c93f8f60775409f1ab410ce9c9ea2357.tar.xz
runtime: change minimum stack size to 2K.
It will be 8K on windows because it needs 4K for the OS. Similarly, plan9 will be 4K. On linux/amd64, reduces size of 100,000 goroutines from ~819MB to ~245MB. Update #7514 LGTM=dvyukov R=golang-codereviews, dvyukov, khr, aram CC=golang-codereviews https://golang.org/cl/145790043
Diffstat (limited to 'src/runtime/stack.h')
-rw-r--r--src/runtime/stack.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/runtime/stack.h b/src/runtime/stack.h
index b30e322166..f97dc4ed8d 100644
--- a/src/runtime/stack.h
+++ b/src/runtime/stack.h
@@ -69,16 +69,19 @@ enum {
#endif // Plan 9
#endif // Windows
- // The amount of extra stack to allocate beyond the size
- // needed for the single frame that triggered the split.
- StackExtra = 2048,
+ // The minimum size of stack used by Go code
+ StackMin = 2048,
- // The minimum stack segment size to allocate.
- // If the amount needed for the splitting frame + StackExtra
- // is less than this number, the stack will have this size instead.
- StackMin = 8192,
- StackSystemRounded = StackSystem + (-StackSystem & (StackMin-1)),
- FixedStack = StackMin + StackSystemRounded,
+ // The minimum stack size to allocate.
+ // The hackery here rounds FixedStack0 up to a power of 2.
+ FixedStack0 = StackMin + StackSystem,
+ FixedStack1 = FixedStack0 - 1,
+ FixedStack2 = FixedStack1 | (FixedStack1 >> 1),
+ FixedStack3 = FixedStack2 | (FixedStack2 >> 2),
+ FixedStack4 = FixedStack3 | (FixedStack3 >> 4),
+ FixedStack5 = FixedStack4 | (FixedStack4 >> 8),
+ FixedStack6 = FixedStack5 | (FixedStack5 >> 16),
+ FixedStack = FixedStack6 + 1,
// Functions that need frames bigger than this use an extra
// instruction to do the stack split check, to avoid overflow