The process stack for a process can vary in size significantly during the execution of the process. Each time a process enters a procedure, the system adds a storage area called an activation record on top of the process stack. In turn, the system removes an activation record from the process stack when a procedure is exited. The size of the activation record, in turn, is affected by the number and type of objects that are declared in a procedure, as well as by the nature of the computations made in the procedure.
The process stack resides entirely in a contiguous region of save memory. To leave room for the process stack to grow, the system sets aside a region of memory larger than the initial size of the process stack. The amount of memory set aside is based on the stack memory estimate or the STACKSIZE task attribute value, as described under Controlling Process Scheduling earlier in this section.
In addition to its effects on scheduling, the stack estimate has implications on the performance of the process. If the process stack grows to a greater size than the stack estimate, the system must stretch the process stack. The stack stretch is an expensive operation because it requires moving the entire process stack to a different location and updating all ASD table entries that are used by the process.
You can tell if stack stretches occurred for a process by checking the job summary or, in some cases, the system log. (By default, stack stretches are recorded in the job summary under major type 3, minor type 4, and in the SUMLOG under major type 14, minor type 4.) If a stack stretch occurred, an entry such as the following appears:
18:01:19 3211 STACK EXTENDED FROM 511 TO 704 WORDS
If a process experiences stack stretches, the system changes the stack estimate in the object code file to the average of the previous estimate and the final stack area allocated in the current run. Thus, if the program is fairly consistent in the amount of stack space it needs, then the stack estimate can become very accurate after several runs. The result is that stack stretches are no longer necessary and the program executes faster.
You can consider making STACKSIZE assignments to improve performance in the same situations where you might want to use STACKSIZE assignments to regulate scheduling, that is, for newly compiled programs, programs stored on read-only disk units, or programs whose memory usage varies widely from one run to the next. You can help decide on an appropriate STACKSIZE value by observing the STACK EXTENDED log entries for various program runs.
Note that you can assign values to the STACKSIZE only before process initiation (for example, through task equations). You cannot use STACKSIZE to change the stack space allocated for an in-use process.

