-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
The default stack size limit is 4 MB on 64-bit systems and 2 MB on 32-bit systems:
Lines 112 to 120 in f2558c4
| #if !defined(JL_STACK_SIZE) | |
| #if defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_MSAN_ENABLED_) | |
| #define JL_STACK_SIZE (64*1024*1024) | |
| #elif defined(_P64) | |
| #define JL_STACK_SIZE (4*1024*1024) | |
| #else | |
| #define JL_STACK_SIZE (2*1024*1024) | |
| #endif | |
| #endif |
This can be a bit small for some applications. Since Julia favours building multiple dispatch interfaces with a lot of function aliases, I think a larger stack size is useful – for example, I ran into a stack overflow error here for a Enzyme differentiation of my codebase: EnzymeAD/Enzyme.jl#1156 (comment) which went away when I manually increased it to 8 MB with Task(f, 8 * 1024 * 1024). Apparently an AbstractGP maintainer had a similar issue when applying AD to some GPs.
I am wondering if the default stack size for 64-bit OSes could be increased to 8 MB, to match glibc? I don't know how easy it is to set it based on ulimit -s, which seems to be what other languages do (at runtime, rather than compiling it).
Seems like parts of Julia also reference an 8 MB stack size as being the default
Lines 40 to 41 in 1193997
| // 8M signal stack, same as default stack size (though we barely use this) | |
| static const size_t sig_stack_size = 8 * 1024 * 1024; |
For glibc, the default is roughly 7.4 MB. Here are the defaults for C across systems according to this old post: https://lists.gnu.org/archive/html/bug-coreutils/2009-10/msg00262.html
The default thread stack size is:
- glibc i386, x86_64 7.4 MB
- Tru64 5.1 5.2 MB
- Cygwin 1.8 MB
- Solaris 7..10 1 MB
- MacOS X 10.5 460 KB
- AIX 5 98 KB
- OpenBSD 4.0 64 KB
- HP-UX 11 16 KB
And the default stack size for sigaltstack, SIGSTKSZ, is
- only 16 KB on some platforms: IRIX, OSF/1, Haiku.
- only 8 KB on some platforms: glibc, NetBSD, OpenBSD, HP-UX, Solaris.
- only 4 KB on some platforms: AIX.
Bruno
P.S., could the Task(f, n) API be documented? Regardless of interest in changing the stack size, I think it would be useful to have an official way of changing it manually for specific tasks.