Stack level too deep (SystemStackError)

Hello. If I execute the following code:

ruby -e ‘def t(i) p i;t(i+1) end;t 0’

I get this:


8730
8731
-e:1: stack level too deep (SystemStackError)

Alright, that seems normal. My ulimit settings are as follows:

socket buffer size (bytes, -b) unlimited
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) 33554432
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 11095
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 524288
cpu time (seconds, -t) unlimited
max user processes (-u) 5547
virtual memory (kbytes, -v) unlimited
swap size (kbytes, -w) unlimited

So, in theory if I reduce the stack size, the above number should go
down, right? That’s not what happens. I tried reducing the stack size
from 512MB to 24KB, but I am still able to get 8731 iterations. Does
anyone know why?

Ruby have static stack size for thread - it’s defined in vm_core.h

/* each thread has this size stack : 128KB */
#define RUBY_VM_THREAD_STACK_SIZE (128 * 1024)

System settings have no effect on a ruby thread stack size.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs