Page 272 - DCAP403_Operating System
P. 272

Unit 13: Case Study: Linux




          When an executable image is mapped into a processes virtual address a set of vm_area_struct data   Notes
          structures is generated. Each vm_area_struct data structure represents a part of the executable
          image; the executable code, initialized data (variables), unitialized data and so on. Linux supports
          a number of standard virtual memory operations and as the vm_area_struct data structures are
          created, the correct set of virtual memory operations are associated with them.

          13.5.10 Demand Paging

          Once an executable image has been memory mapped into a processes virtual memory it can
          start to execute. As only the very start of the image is physically pulled into memory it will soon
          access an area of virtual memory that is not yet in physical memory. When a process accesses a
          virtual address that does not have a valid page table entry, the processor will report a page fault
          to Linux.
          The page fault describes the virtual address where the page fault occurred and the type of
          memory access that caused.


          Linux must  find the vm_area_struct that represents the area of memory that the page fault
          occurred in. As searching through the vm_area_struct data structures is critical to the effi cient
          handling of page faults, these are linked together in an AVL (Adelson-Velskii and Landis) tree
          structure. If there is no vm_area_struct data structure for this faulting virtual address, this process
          has accessed an illegal virtual address. Linux will signal the process, sending a SIGSEGV signal,
          and if the process does not have a handler for that signal it will be terminated.
          Linux next checks the type of page fault that occurred against the types of accesses allowed for
          this area of virtual memory. If the process is accessing the memory in an illegal way, say writing
          to an area that it is only allowed to read from, it is also signalled with a memory error.
          Now that Linux has determined that the page fault is legal, it must deal with it.

          Linux must differentiate between pages that are in the swap file and those that are part of an
          executable image on a disk somewhere. It does this by using the page table entry for this faulting
          virtual address.
          If the page’s page table entry is invalid but not empty, the page fault is for a page currently being

          held in the swap file. For Alpha AXP page table entries, these are entries which do not have their

          valid bit set but which have a non-zero value in their PFN field. In this case the PFN fi eld holds

          information about where in the swap (and which swap file) the page is being held. How pages in

          the swap file are handled is described later in this unit.
          Not all vm_area_struct data structures have a set of virtual memory operations and even those

          that do may not have a nopage operation. This is because by default Linux will fix up the access
          by allocating a new physical page and creating a valid page table entry for it. If there is a nopage
          operation for this area of virtual memory, Linux will use it.
          The generic Linux nopage operation is used for memory mapped executable images and it uses
          the page cache to bring the required image page into physical memory.
          However the required page is brought into physical memory, the processes page tables are
          updated. It may be necessary for hardware specific actions to update those entries, particularly

          if the processor uses translation look aside buffers. Now that the page fault has been handled
          it can be dismissed and the process is restarted at the instruction that made the faulting virtual
          memory access.

          13.5.11  The Linux Page Cache


          The role of the Linux page cache is to speed up access to files on disk. Memory mapped fi les are
          read a page at a time and these pages are stored in the page cache. Figure 13.7 shows that the
          page cache consists of the page_hash_table, a vector of pointers to mem_map_t data structures.



                                           LOVELY PROFESSIONAL UNIVERSITY                                   265
   267   268   269   270   271   272   273   274   275   276   277