3 ms·
Depends on your codebase. Userspace C libraries and programs, including libc, often store surprisingly large buffers on the stack. For example, try setting 'u
by loeg 7y ago
Depends on your codebase. Userspace C libraries and programs, including libc, often store surprisingly large buffers on the stack.
For example, try setting 'ulimit -s 128' (128kB stack limit) and see how many C programs crash. Then try, say, 16. Go's default is 8 kB, raised from 4 kB in 1.2: https://golang.org/doc/go1.2#stack_size https://golang.org/doc/go1.2#stack_size
Linux's default userspace stack limit is 8 megabytes for a reason — programs really do use it.
- masklinn 7y ago> for a reason Not really, the 8MB limit was added back in '95 from a previous limit of "essentially none"[0] with a justification of > Limit the stack by to some sane default: root can always increase this limit if needed.. 8MB seems reasonable. Developers don't generally think about their stack size, especially for single-threaded programs[1] so the defaults need to be a sweet spot of not unnecessarily big (such that you can catch unbounded recursion) but not so small that you'd segfault more than a very small fraction of all programs. [0] https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/diff/include/linux/sched.h?h=1.3.7&id=2d52d174c910808b03474c786fc42c7c7e869bd5 https://git.kernel.org/pub/scm/linux/kernel/git/history/hist... [1] which would be why e.g. OSX has a large main thread stack (8MB) and a relatively puny secondary thread stack (512k).