Page 138 - DCAP403_Operating System
P. 138

Unit 7: Memory Management




          only load virtual pages that are currently being used by the executing program. For example, a   Notes
          database program may be run to query a database. In this case not the entire database needs to be
          loaded into memory, just those data records that are being examined. Also, if the database query
          is a search query then it does not make sense to load the code from the database program that
          deals with adding new records. This technique of only loading virtual pages into memory as they
          are accessed is known as demand paging.

                       Figure 7.11: Abstract Model of Virtual to Physical Address Mapping
               Process X                                               Process Y
                VPFN 7                                                  VPFN 7

                VPFN 6       Process X                   Process Y      VPFN 6
                             Page Tables                 Page Tables
                VPFN 5                                                  VPFN 5

                VPFN 4                        PFN 4                     VPFN 4
                VPFN 3                        PFN 3                     VPFN 3

                VPFN 2                        PFN 2                     VPFN 2

                VPFN 1                        PFN 1                     VPFN 1
                VPFN 0                        PFN 0                     VPFN 0

           VIRTUAL MEMORY                PHYSICAL MEMORY            VIRTUAL MEMORY

          When a process attempts to access a virtual address that is not currently in memory the CPU
          cannot find a page table entry for the virtual page referenced. For example, in Figure 7.11 there

          is no entry in Process X’s page table for virtual PFN 2 and so if Process X attempts to read from
          an address within virtual PFN 2 the CPU cannot translate the address into a physical one. At

          this point the CPU cannot cope and needs the operating system to fix things up. It notifi es the
          operating system that a page fault has occurred and the operating system makes the process
          wait whilst it fixes things up. The CPU must bring the appropriate page into memory from the

          image on disk. Disk access takes a long time, relatively speaking, and so the process must wait
          quite a while until the page has been fetched. If there are other processes that could run then the
          operating system will select one of them to run. The fetched page is written into a free physical
          page frame and an entry for the virtual PFN is added to the processes page table. The process
          is then restarted at the point where the memory fault occurred. This time the virtual memory
          access is made, the CPU can make the address translation and so the process continues to run.
          This is known as demand paging and occurs when the system is busy but also when an image is

          first loaded into memory. This mechanism means that a process can execute an image that only
          partially resides in physical memory at any one time.
          7.10 Page Replacement


          When the number of available real memory frames on the free list becomes low, a page stealer is
          invoked. A page stealer moves through the Page Frame Table (PFT), looking for pages to steal.


          The PFT includes flags to signal which pages have been referenced and which have been modifi ed.
          If the page stealer encounters a page that has been referenced, it does not steal that page, but
          instead, resets the reference flag for that page. The next time the clock hand (page stealer) passes

          that page and the reference bit is still off, that page is stolen. A page that was not referenced in

          the first pass is immediately stolen.



                                           LOVELY PROFESSIONAL UNIVERSITY                                   131
   133   134   135   136   137   138   139   140   141   142   143