User-visible ability to set the pthread stack size
Motivation
Presently, the runtime system of GHC uses the default stack size when creating pthreads. This default is different for both different architectures as well as different operating systems. The net result is that imported foreign functions that require large stacks may run on some operating systems and not others.
In my own experience tracking this down, I have discovered that macOS 12.6 ignores what is set by ulimit -s
and always sets the default to be 512kB. Under Linux, the documentation states that it will use what is set by ulimit -s
as the default except when it is set to unlimited
, in which case there is a table that maps the architecture to a default. For example, in x86, that would be 2MB.
Proposal
I propose that we have a user visible way of setting the pthread stack size to accommodate imported foreign functions that require large stack sizes. I suggest that a minimum implementation would be to allow it be set in the RTS options for all threads.
A more advanced implementation may be to set individual thread's stack sizes, but I recognize that could be a substantial amount of work when mapping Haskell threads to OS threads.
I would also suggest that GHC sets its own default to ensure that there is sufficient stack size for the RTS to operate in addition to what an imported foreign function may require. As it stands now, this is not an issue, but may become an issue later for future RTS versions, architectures, or operating systems. A sensible default option is to force pthreads to use what is set by ulimit -s
when it is not unlimited
and use the same table as Linux.