Page 177 - DCAP103_Principle of operating system
P. 177

Principles of Operating Systems



                   Notes         A page fault is a hardware or software interrupt (depending on implementation) which passes
                                 control to the operating system. The OS proceeds to locate the missing page in the swap area and
                                 move it back into a free frame of physical memory. It then binds the addresses by updating the
                                 paging table and, when control returns to the waiting process, the missing page is automatically
                                 restored, as if it had never been gone.
                                 Notice, that the location of the physical frame is completely irrelevant to the user process. A
                                 frame does not have to be moved back into the same place that it was removed from, because
                                 the runtime binding of addresses takes care of its relocation.
                                 5.7.3 Swapping and Paging Algorithms

                                 How does the system decide what pages or processes to swap out? This is another problem in
                                 scheduling. A multitude of schemes is available. Here we shall only consider some examples.
                                 Consider the UNIX system a moment. Before paging was introduced, the only way that memory
                                 segments could increase their size was to:
                                    1.  Try to look for free memory at the end of the current segment and add it to the current
                                      segment.

                                    2.  Try to allocate a new, larger segment, copy the data to the new segment and deallocate
                                      the old one.
                                    3.  Swap out the process, reallocate and swap in again.

                                 In this use of swap space, it is clear that a process is swapped out while it is waiting for a suitable
                                 hole in to appear in the memory. This might take a long time and it might be immediate. Another
                                 case for swapping out a job is if it has been idle (sleeping) for a long time.
                                 On a BSD-like  UNIX  system,  the  first  three  processes  to  be  started  are  the  swapper,  init,
                                 the and the page daemon. The page daemon is responsible for examining the state of the
                                 page-table and deciding which pages are to be moved to disk. Normally the swapper will
                                 not swap out processes unless they have been sleeping for a long time, because the pager
                                 will first strip them of their inactive pages. It will begin to swap out processes however, if
                                 the average load on the system is very high. (The load average is a number based on the
                                 kernel’s  own  internal  accounting  and  is  supposed  to  reflect  the  state  of  system  activity.)
                                 This gives ‘cheap’ processes a chance to establish themselves. It is the page daemon which
                                 makes the paging decisions. By copying read-only segments to the swap area at load time,
                                 the running overhead of paging out read-only data is removed, since the data are always
                                 where we need them in swap space and never change. In modernized versions of UNIX,
                                 such as the Solaris systems by Sun Microsystems, read only pages from the code segment
                                 are thrown away when they are selected for swap out and then read in from the filesystem
                                 if needed again. Moreover, data pages are only allocated swap space when they are forced
                                 out of physical memory. These optimizations reflect the fact that modern systems have more
                                 physical memory than previously; also disks are getting faster.

                                 Let us now look more generally at how paging decisions are made. The most important aspect
                                 of paging is that pages can still be accessed even though they are physically in secondary storage
                                 (the disk). Suppose a page fault occurs and there are no free frames into which the relevant data
                                 can be loaded. Then the OS must select a victim: it must choose a frame and free it so that the
                                 new faulted page can be read in. This is called (obviously) page replacement. The success or
                                 failure of virtual memory rest on its ability to make page replacement decisions. Certain facts
                                 might influence these algorithms. For instance, if a process is receiving I/O from a device, it
                                 would be foolish to page it out — so it would probably I/O locked into RAM. Here are some
                                 viable alternatives for page replacement.





        170                               LOVELY PROFESSIONAL UNIVERSITY
   172   173   174   175   176   177   178   179   180   181   182