Section 12.4: The Principle of Locality (Frame 1)                     [     ][home][next]

If thrashing is a common occurrence, what keeps it from happening all the time? In theory, nothing! However, real programs that do useful work like computing taxes, simulating galaxy collisions, mapping out chromosomes and formatting text exhibit a very useful property: they do not access their memory spaces randomly. There is usually a pattern to how they reference both data memory and instruction memory.

Watching a program in action to count how many times it executes certain statements reveals that programs spend a lot of time in loops, and since most loops are small, programs spin around in a fairly small region of instruction memory. Occasionally, they call subroutines or jump to far-away regions of code. But at any given time, only a small region of instruction memory, or only several small regions, is being used. This is called the principle of locality, because the computer stays in a small, local region. When the region of memory is matched to the working set size, thrashing is unlikely.