Page 268 - DCAP403_Operating System
P. 268

Unit 13: Case Study: Linux




          Swap Cache                                                                            Notes


          Only modified (or dirty) pages are saved in the swap fi le.

          So long as these pages are not modified after they have been written to the swap file then the next


          time the page is swapped out there is no need to write it to the swap file as the page is already in
          the swap file. Instead the page can simply be discarded. In a heavily swapping system this saves

          many unnecessary and costly disk operations.
          Hardware Caches
          One commonly implemented hardware cache is in the processor; a cache of Page Table Entries. In
          this case, the processor does not always read the page table directly but instead caches translations
          for pages as it needs them. These are the Translation Look-aside Buffers and contain cached
          copies of the page table entries from one or more processes in the system.
          When the reference to the virtual address is made, the processor will attempt to find a matching


          TLB entry. If it finds one, it can directly translate the virtual address into a physical one and

          perform the correct operation on the data. If the processor cannot find a matching TLB entry
          then it must get the operating system to help. It does this by signaling the operating system that
          a TLB miss has occurred. A system specific mechanism is used to deliver that exception to the

          operating system code that can fi x things up. The operating system generates a new TLB entry
          for the address mapping. When the exception has been cleared, the processor will make another
          attempt to translate the virtual address. This time it will work because there is now a valid entry
          in the TLB for that address.
          The drawback of using caches, hardware or otherwise, is that in order to save effort Linux must
          use more time and space maintaining these caches and, if the caches become corrupted, the
          system will crash.

          13.5.7  Linux Page Tables

          Linux assumes that there are three levels of page tables. Each Page Table accessed contains the
          page frame number of the next level of Page Table. Figure 13.4 shows how a virtual address can

          be broken into a number of fi elds; each field providing an offset into a particular Page Table. To
          translate a virtual address into a physical one, the processor must take the contents of each level

          field, convert it into an offset into the physical page containing the Page Table and read the page
          frame number of the next level of Page Table. This is repeated three times until the page frame
          number of the physical page containing the virtual address is found. Now the fi nal fi eld in the
          virtual address, the byte offset, is used to find the data inside the page.

                                   Figure 13.4: Three Level Page Tables
                                      VIRTUAL ADDRESS
                                Level 1      Level 2     Level 3    Byte within page


                     Level 1          Level 2         Level 3         Physical
                     Page Table       Page Table      Page Table      Page





                     PFN             PFN              PFN


              PGP




                                           LOVELY PROFESSIONAL UNIVERSITY                                   261
   263   264   265   266   267   268   269   270   271   272   273