13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Page-replacement policies 107There are only 2 accesses without fault.<strong>An</strong>omalies are possible only in page-replacement algorithms that lack the stackproperty. <strong>An</strong> algorithm has this property if at each point in any page-reference string,the set of pages that would be in an n -page-frame main store is a subset of those thatwould be in an (n +1)-page-frame main store. FIFO and Random lack this property. Inour example, after the first reference to page 4, FIFO would have pages 0, 1, and 4 inmain store with three page frames but would not have 0 with four page frames. The nextmethods we will see have the stack property, and they also perform better than FIFO.7.4 Least recently used (LRU)The most common technique in use is the LRU method, or some variation on it. The ideabehind this method is that the past is a mirror, albeit an imperfect one, of the future. TheMin algorithm cannot be implemented because it requires looking into the future. LRUapplies the same algorithm in the past:LRUSelect the page frame containing the page that has not beenaccessed for the longest period of time.This method is based on the assumption that the page-reference pattern in the recent pastis a mirror of the pattern in the near future. Pages that have been accessed recently arelikely to continue to be accessed and ought to be kept in main store.This assumption works fairly well. As Figure 3.21 shows, LRU is significantlybetter than FIFO. Its characteristic number, 94159, is about 10 percent lower than thecharacteristic number for FIFO.In a humorous vein, we might attempt to find the pessimal page-replacement strategy.MRU, Most Recently Used, ought to behave pretty poorly. It discards the pagethat has been accessed most recently. The theoretical pessimum is Max, which replacesthe very page that will be needed soonest in the future. Just like Min, the Max methodrequires knowledge of the future, so it is not a feasible method. Figure 3.22 shows Max,MRU, and Min, along with their characteristic numbers, for our synthetic page-referencestring. It is not surprising that Max is terrible. Although MRU is bad, it behaves betterthan one might expect.Unfortunately, LRU is expensive to implement exactly. To find the page leastrecently used, either a list of pages must be maintained in use order or each page must bemarked with the time it was last accessed. Hardware could certainly be designed andbuilt to accomplish either, but it would be quite expensive. Luckily, an exact implementationis not needed because a simple variant works almost as well.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!