Hello,
We've pondered establishing some kind of a fork where you specify the stack size, but have yet to really find a really strong use-case to justify the effort. So, for the moment, let's examine the possibilities and the requirements of your task categories.
I think my first, and most important question is: do control tasks block? If not, the actual overhead for using a larger stack for them is minimal, since the stack is only allocated when the task actually executes, and since the stacks are pooled, there is no more (computational) overhead for allocating an 8MB stack than there is for allocating a 2k stack. Further, if they do not block, you may be able to use "simple" tasks for your control tasks instead of standard tasks (see the SPAWN_SIMPLE flag to qthread_spawn()). Simple tasks are (admittedly) not well-documented, but essentially a simple task is treated as a simple function-call from the underlying worker, rather than a context-swap (i.e. it's cheaper and faster to execute as well), and so borrows its stack, rather than receiving its own stack; the only functional restriction being that simple tasks cannot perform blocking operations.
However, if control tasks do block (and frequently), then I agree, large stacks are an unfortunately inefficient route to take. The way the contexts are handled, yes, I think your wrapper would work just fine for "upgrading" a small stack to a bigger one - it's an interesting idea. A little extra overhead for changing stacks, but relatively simple (keep in mind, this won't behave itself (or report correct values) with rlimit). However, I think we can do better by integrating the multiple stack sizes into the concept of a qthread. Since, obviously, we would rather have stacks be specific sizes, let's brainstorm about how to do this in a more generic way. What if we created a fork-with-stack-size option that rounded those sizes into buckets, and then only created memory pools for those buckets on an as-needed basis?
~Kyle
--
Kyle B. Wheeler
Dept. 1423: Scalable System Software
Sandia National Laboratories
505-844-0394