3 ms·
> We need to fix GC being deeply recursive once and for all. Tweaking stack sizes on various platforms and trying to spot-fix GC for the occasional deeply recur
by kazinator 9y ago
> We need to fix GC being deeply recursive once and for all. Tweaking stack sizes on various platforms and trying to spot-fix GC for the occasional deeply recursive structure is annoying. Here's my proposal:
There is still a default stack size limit of 8 megabytes on Linux,
even though consumer machines nowadays have RAM measured in double-digit gigabytes.
On an Ubuntu 16.x machine:
$ ulimit -a | grep stack
stack size (kbytes, -s) 8192
$ free -h
total used free shared buff/cache available
Mem: 15G 4.1G 2.8G 600M 8.7G 10G
Swap: 14G 626M 13G
This 8192 kbytes has not changed in at least 15 years, unlike that 15G. Slight disconnect there.
This 8192 is just the soft limit; applications can raise it up to the root-imposed hard limit.
Unfortunately, that tends to be only 4X larger than the 8192:
$ ulimit -s 32769
bash: ulimit: stack size: cannot modify limit: Operation not permitted
$ ulimit -s 32768
$ # OK
Clearly, the hard limit needs revision too.
Threads are another issue; if you have a "can run in any thread" garbage collector, it has to live within a thread stack. You can't have huge stacks for each of a large number of threads. A thread's stack cannot be temporarily extended; there may be something in the address space preventing it, since it's just another mmap. (Don't think Emacs has this problem. :)
- quotemstr 9y ago> There is still a default stack size limit of 8 megabytes on Linux, even though consumer machines nowadays have RAM measured in double-digit gigabytes. Current stack sizes are fine; storing large amounts of information on the stack usually isn't a good idea anyway, and makes tools like debuggers and perf(1) slow and awkward. Besides, the ulimit means nothing. If you really want, you can allocate your own "stack", as large as you want, and switch to it. I just wouldn't recommend it. > A thread's stack cannot be temporarily extended; there may be something in the address space preventing it, since it's just another mmap. You might be interested in the split stack model, described here [1]. You definitely can grow a thread's stack as needed. The approach has various issues (which is why Rust eventually went with conventional stacks), but it certainly works. [1] https://gcc.gnu.org/wiki/SplitStacks https://gcc.gnu.org/wiki/SplitStacks
- avar 9y agoCurrent limits are fine, but also meaningless since you can trivially bypass them? If so why not raise the limits if they're only serving to have everyone implement their own bespoke stacks.
- quotemstr 9y agoThe ulimit serves as a good reminder that excessive stack use is undesired.
- avar 9y agoIt's not a reminder if Linux's default configuration is to hard limit it at 32768, that means that if you need 32769 of stack you need to hack your own implementation for your program to be portable, or otherwise the user must be able to "sudo".
- BeeOnRope 9y agoHow does big stacks slow down perf? I agree putting large amounts of data on the stack isn't a great idea, but I think it's mostly because (a) default stack sizes are quite small (b) they vary by distribution and even local configuration and (c) if you happen to be on any thread other than the main thread, it's the pthread stack size that matters and this is even usually smaller than the default main thread stack. I never heard of it causing any problems for perf. Yes, perf unwinds the stack if you ask it to, but all the mechanisms will don't depend (AFAIK) on the stack size.