OCAMLRUNPARAM does not affect stack size

I would like to resize the stack so that a project with many non-recursive functions runs on big data. To do this, I tried to set OCAMLRUNPARAM="l=xxx" for different xxx values ​​(in the range from 0 to 10G), but this had no effect. Is OCAMLRUNPARAM even the right approach?

In case it matters: the project that interests me is built using OCamlMakefile, target native-code .

Here is a minimal example where just a large list is created without tail recursion. To quickly check if the OCAMLRUNPARAM effect has an effect, I compiled the stacktest.ml program:

 let rec create l = match l with | 0 -> [] | _ -> "00"::(create (l-1)) let l = create (int_of_string (Sys.argv.(1))) let _ = print_endline("List of size " ^ string_of_int (List.length l) ^ " created.") 

using the command

 ocamlbuild stacktest.native 

and found out roughly how long the list overflows the stack overflow (more or less) a binary search with the following bash script foo.sh :

 #!/bin/bash export OCAMLRUNPARAM="l=$1" increment=1000000 length=1 while [[ $increment > 0 ]] ; do while [[ $(./stacktest.native $length) ]]; do length=$(($length+$increment)) done length=$(($length-$increment)) increment=$(($increment/2)) length=$(($length+$increment)) done length=$(($length-$increment)) echo "Largest list without overflow: $length" echo $OCAMLRUNPARAM 

The results vary between runs of this script (and the intermediate results are not even consistent for one run, but let them ignore it at the moment), but they are similar, regardless of whether I call

 bash foo.sh 1 

or

 bash foo.sh 1G 

i.e. whether the stack size is set to 1 or 2 ^ 30 words.

+5
source share
1 answer

Changing the stack limit through OCAMLRUNPARAM only works for executable bytecode files that are executed by the OCaml interpreter. The native program is processed by the operating system and executed directly on the processor. Thus, in order to change the stack limit, you need to use the funds provided by your operating system.

For example, on Linux, there is a ulimit command that processes many process parameters, including a stack limit. Add to your script

 ulimit -s $1 

And you will see that the result is changing.

+6
source

All Articles