-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase stack size limit to 8 MB? #54998
Comments
It seems like increasing the default stack size could cause performance regressions for code using many
#55005 🙏 |
Thanks for posting the issue! Regarding performance, the only direct effect would be reserving more virtual memory for the stack. Performance would not inherently be affected because the stack is allocated in virtual memory, not physical – only when you use that allocated space for the stack does it allocate memory. i.e., the only direct effect would be less available virtual memory, as each task would take up more of the virtual address space. (using virtual memory itself is only an issue on 32-bit systems = 4 gigabytes in total; but 64-bit has a ton of virtual address space = 16 exabytes) However, if you were to now use that larger stack, and have deeper function calls, then one could encounter performance regressions due to the greater memory usage. But the limit itself doesn't affect performance, only available virtual memory (of which, on modern 64-bit systems, it’s basically limitless). The practical concern of overly large stack sizes is users may start to use deep stacks. Since 8 MB is the default at the operating system I think it’s reasonable, especially given how composable the Julia ecosystem is, and it’s useful considering how AD tools can get quite deep call stacks. |
Is this something we could enable on 1.12-dev and observe if there is a meaningful impact on performance? Seems like a nice easy win if we can have it. |
Sounds good to me. I made a PR #55185 |
Fixes JuliaLang#55005 and helps work around issues discussed in JuliaLang#54998.
The default stack size limit is 4 MB on 64-bit systems and 2 MB on 32-bit systems:
julia/src/options.h
Lines 112 to 120 in f2558c4
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
julia/src/signals-unix.c
Lines 40 to 41 in 1193997
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
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.The text was updated successfully, but these errors were encountered: