System-Managed Stack Attributes
Solaris native and POSIX API supports user-specification of the reserve size for a system-managed stack, but provides no support for controlling the commitment of physical memory and page-file space to such a stack.
Stack Reserve Size. Solaris supports the stack reserve size attribute for a system-managed stack.
The minimum stack size necessary to execute a null function is returned by the getMinStackSize() member. The Threads Module uses the thr_min_stack() function to determine this value. To ensure that each thread’s stack size is always greater than the minimum allowable stack size, the Threads Module adds the minimum stack size value to any reserve size value retrieved from a thread attribute at the time a thread is created.
The Threads Module imposes no upper limit for stack reserve size; the maximum stack size is effectively limited by available virtual memory space and pagefile size. If the stack reserve size specified is too large for the available resources, an exception will be produced at the time a thread is created using the thread attribute instance with the offending reserve size value. Any such exception is thrown by the start() function invocation that attempted to create the thread.
Solaris uses allocation on demand even when the user specifies the amount of stack size to reserve. When Solaris allocates stack space, it maps the space as anonymous, zeroed memory, but does not allocate real memory until the memory is accessed. Solaris reserves an inaccessible page at the end of each stack area, called a red zone, that is used to produce a segmentation fault should the stack overflow. The stack address space is mapped using the MAP_NORESERVE attribute to delay the cost of reserving swap space until the memory is used. The only resource consumed by reserving space is addresses in the virtual address space of your process; no memory or pagefile space is allocated until the memory is committed. Therefore, there is little harm in reserving a large area if it might be needed.
The default stack reserve size for a 32-bit image used by Solaris and returned by getStackReserveSize() is 1MB. The value for a 64-bit minage is 2MB. This stack is allocated on demand, and starts with 1 page committed to memory.
A call to setUserStack() replaces or nullifies the attribute settings produced by any previous call to setStackReserveSize() and vice versa.
Stack Commit Size. The stack commit size attribute is not supported in the Solaris implementation of the Threads Module. Attempts to get or set this attribute value will result in exceptions.