Program Structure and Behavior

The inherent behavior of programs impacts the efficiency of virtual memory systems. Simulations of program behavior show that during processing time, a program will exhibit phases -- or periods of little change in the contents of main memory -- alternating with transitions -- or periods of significant change in the contents of main memory. This graphic demonstrates a program's effect on main memory during execution.

A higher concentration of page faults occurs during transitions, creating a significant cost to the system. Phases have the opposite effect by providing the system extended periods of processing time with relatively few page faults. While phases occupy more of the virtual time of a program, the effect of transitions cannot be discounted [D3]. Transitions are responsible for a large amount of the time spent handling page faults. Reference strings can be used to observe program activity.

The phase/transition behavior occurs naturally in programs, but efforts to optimize the behavior can result in more efficient programs. One method of optimization, program reorganization, focuses on how the compiler assigns logical segments of a program to pages in the address space [D3]. Consider these two examples of code.

What do you observe about the program behavior, as exhibited in the reference strings? How would you identify the phases and transitions in each example? Which would appear to be more efficient in a virtual memory system? It is evident that knowing how the compiler assigns elements of the matrix in memory can help a programmer write efficient code.