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.

114 Space Management Chapter 3When is a page swapped in?The first issue, surprisingly, concerns whena swapped-out page should be swapped in. We have concentrated on demand paging sofar, in which a page is brought in only when it is accessed by a process. Demand paginghas the advantage that it never brings in a page that is not needed. Other techniques canreduce page faults by anticipating them before they happen.The first method is prefetching, which we touched on earlier. When a process isplaced on the ready list after a long residence in a transput or main-store wait list, thekernel restores the pages that the process had before it became blocked. Prefetchingworks on the reasonable assumption that until the process is given back its working set, itwill not be able to make much progress. Instead of encountering a number of page faultsimmediately, the kernel can save effort by scheduling all the working set to be brought inbefore the process is placed back on the ready list.Prefetching also applies the first time a process is started; instead of letting pagefaults bring in the necessary pages, a selection of pages can be brought in initially.Unfortunately, any guess about the correct number and identity of prefetched pages islikely to be inaccurate to some degree. Sometimes, useless pages will be prefetched andwill waste main store until they are thrown out during normal replacement.<strong>An</strong>other method is advised paging, in which the process may inform the storagemanager through a service call that a particular page is about to be accessed and thusshould be swapped in or that a particular page will not be used again for a long time andmight as well be swapped out. Such a call would have this form: PageAdvice(starting address, ending address,direction). This call tells thestorage manager that the process is about to use the region in virtual space betweenthe two addresses, so it might swap the relevant pages in (if direction is ‘‘in’’) orthat this region will not be accessed for a considerable period (if direction is‘‘out’’).Advised paging takes advantage of the programmer’s or compiler’s knowledge of howthe program works, knowledge that can be more accurate than the storage manager’s.However, the programmer has no knowledge at all of the other processes that are competingin the ready list, but the storage manager does know. It would be foolhardy for thestorage manager to put too much credence in advice. At most, the storage manager mightturn off the Used field for a page that the process claims will not be used for a while,making it a candidate for swap-out. For swapping in, the advice should most likely beignored.The method called clustering swaps in additional pages beyond the ones broughtin by demand paging. Not only the required page but the next few pages as well arebrought in at the same time. If adjacent pages in virtual store are placed in adjacent locationson backing store, the cost of bringing in a group of pages might be only slightlyhigher than bringing in just one. We will see the source of this efficiency when we discussfile storage in Chapter 6. Once a particular page is accessed, the pages nearby havea higher probability of being accessed soon. If they are not needed, they will soon beswapped out. Since they have not been touched, swapping out requires no work at all.Which page should be swapped out?We have already seen severalspecific techniques for choosing a victim page to swap out. These methods can beclassified as local or global methods, depending on whether they pick pages from onlythe process whose page fault requires finding a victim or from any process. Global

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

Saved successfully!

Ooh no, something went wrong!