ruby - Why the large difference between stack memory limit systems? -
i wrote implementation of algorithm course ruby 2.1 running in ubuntu. algorithm easiest express utilising recursion. ruby raising "stack level deep systemstack" exception due large memory requirements of problem , implementation. allow algorithm complete used following commands increase allowable stack size:
export ruby_thread_vm_stack_size=16000000 ulimit -s 128000
note both commands above have run. units of ruby_thread_vm_stack_size bytes , units of ulimit kbytes. ruby_thread_vm_stack_size limit ~16mbytes , ulimit limit ~128mbytes. if reduce either limit half it's value shown here algorithm won't finish without exception.
can please explain why these limits differ factor of ~8?
i've checked i'm able , doesn't seem because 1 of units kbits instead of kbytes. thanks!
i believe ulimit needs bigger due ruby's boilerplate around function calls.
in /vm_eval.c see this:
rb_call0
- used execute ruby's functions. accepts 6 arguments.- this in turn calls
vm_call0
, accepts 7 arguments. - this in turn calls
vm_call0_body
accepts 3 arguments. - this in turn calls
vm_exec
(located invm.c
) accepts 1 argument. - at point i'm bit lost, calls
vm_exec_core
, lot of other things.
nonetheless hierarchy see ruby pushed quite bit on stack 1 function call: addresses @ least 5 functions , @ least 17 arguments. that's 88 bytes.
that system stack. ruby's vm stack different , belongs ruby's executable rather being managed system. holds structures ruby needs maintain in order execute functions, without incidental boilerplate gets pushed on sytem stack resulting ruby's code structure.
Comments
Post a Comment