Section 12.2: Virtual Memory in Action (Frame 3)                     [prev][home][next]

Suppose page 2 is referenced but all frames are in use, so a victim must be selected. At this stage, the operating system could make a good choice or a stupid choice of victim. The best choice would be to throw out the page that will never be used again or will be used farther in the future than all other pages. A stupid choice would be the page that was modified since that will require both a disk write and a disk read, or a page that will be needed right away. Of course, the operating system doesn't know if a page will be needed again soon, unless it can read the future. Don't laugh! Some systems do precisely that, by running a program, like a payroll program, that is used over and over again, keeping a history of addresses.

Victim selection is an extremely complicated topic and has been researched heavily in order to squeeze the best performance out of virtual memory systems. The most commonly used algorithms are variations on one called LRU for Least Recently Used which keeps a time stamp on each frame. Whenever a frame is referenced, i.e. whenever an address within the page that currently occupies that frame is generated during the instruction cycle, the current time is copied into a register associated with that frame. Then, when a victim is needed, the operating system looks at the time number on each frame and finds the oldest. It is a good bet that this frame, which was used farthest in the past, will not be needed again, so it is selected as the victim. This bet could be wrong, but it is frequently right.