13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

110 Space Management Chapter 37.6 Second-chance cyclicThe methods mentioned so far do not take into account the extra effort involved in swappingout a dirty page. The second-chance cyclic method tries to avoid such swaps. Oncemore, we cycle through the page table looking for a victim. The best victim is a cleanpage that has not been used in a long time — that is, one for which both Dirty and Usedare false. To keep the algorithm simple, we will ignore the Used field. As we search fora victim, we keep passing dirty pages. As we do so, we reset Dirty to false. We willeventually reach a page with Dirty set false even if we have to come full circle to theplace where the search began. The first such page is the victim.Once the victim is chosen, it still might have to be written out even though it ismarked as clean. The Dirty field is no longer a true indication of whether the page isdirty because our algorithm has reset that field without cleaning the page. Instead, wesave a mirror copy of the Dirty field in the context block. This copy is set to true wheneverwe reset a Dirty field to false. When we decide to swap out a page, we check themirror copy to see if it must be written out.This algorithm not only gives a second chance to dirty pages, but it also continuesto give a reprieve to pages that are being written to frequently. The chances are good thatbetween the time we reset a Dirty field and the time we look at such a page again, theprocess has written in that page, and the Dirty field protects the page from being swappedout.7.7 Global policiesWe are now ready to examine some page-replacement policies that do not forceprocesses to page only against themselves. After all, some processes need more physicalstore than others because their regions of locality are larger. If every process could pageonly against itself, we would have to make initial guesses as to the number of pages aprocess needs, and these guesses would sometimes be too low and at other times toohigh.<strong>An</strong>y of the foregoing policies can be used in a global fashion. To implement theglobal NUR or second-chance cyclic method, the storage manager must be able to scanthrough all the page frames of main store, examining and modifying the Used and Dirtyfields. Unfortunately, few machines are designed with these fields in a hardware pageframetable. Instead, they appear in the page tables for each process, because thehardware must refer to those tables during address translation, and they are therefore theobvious place to store this information. In this case, the storage manager builds asoftware page-frame table that records the correspondence between physical page framesand virtual pages. During a scan of the page-frame table, the storage manager can findthe Used and Dirty fields in the per-process page tables. Here are declarations for asoftware page-frame table:

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

Saved successfully!

Ooh no, something went wrong!