Implementing the Virtual Memory System in OS 161 - PowerPoint

Document Sample
scope of work template
							Implementing the Virtual
Memory System in OS 161


           CS 170
     Discussion – IV
      25 th May 2007
            Starting the Implementation

 In case of a TLB fault, an exception is raised
 Exception handled in function mips_trap() in file
  trap.c
 vm_fault called from this exception handler
 Deal the fault with respect to the address space of
  current thread
Implementation of functionality in file addressspace.c


 Complete the routine for copying the address
  spaces
 Write the routine to respond to the Address Space
  faults
 Complete the functionality of as_destroy(),
  as_activate(), as_define_region()
 Implement the functions as_sbrk() and sys_sbrk()
             Implementation of coremap

 The physical address space is managed using a
    coremap
   It is basically an inverted page table
   One coremap_entry per page of physical RAM
   Does all the TLB management and handling
   Implements the page replacement policy
   Whenever a lpage fault occurs, a page is requested
    from the coremap
   The coremap keeps track of the pages in the
    physical memory
            Implementation of coremap

 It should keep track of the number of
    maximum number of physical pages

    number of kernel pages

    number of user pages

    number of pages that are free

 Keeps a map between the virtual address and the
  actual physical address
 Maintain information whether a page has been
  pinned for modification
            Implementation Continued

 Implement the locking structure
 You will need to manage the logical pages (lpage)
  as well as the virtual memory objects
 Implement functionality to manage the lpages and
  vm_obj’s
                   Logical Page

 Each distinct page handled by the VM system is
  assigned an lpage structure
 The lpage structure keeps track of where the page is
  in physical memory and where it is kept on disk in
  the swap file
 You can safely assume that lpages are not shared
  between processes
 Evicting a Logical page is straight forward, write
  back to swap if it’s dirty, else simply discard
                   Logical Pages

 A logical page might be accessed by simultaneously
  by two threads, suppose a thread that is accessing
  the page and one that is swapping it out
 You may implement a lock for a logical page
 When there is a fault in the local page (i.e. the
  logical page has not been allocated a frame in
  physical memory), get a frame from coremap and
  map this page to this new frame
                       vm_object

 Data structure associated with a mapped (that is,
    valid) block of process virtual memory
   Should be some kind of an array of lpages
   Simple operations like creating a vm_object,
    destroying it, copying one object to another and so
    on
   This corresponds to the segments within the
    program
   The address space is a collection of these
    vm_objects
          Implementing the Swap Space

 Implement the operations of the swap file
 Bootstrap the swap space by attaching it to the swap
  file
 The last operation during VM initialization
 Implement the functionality to read from and write to
  a specified functionality
 This read/write will be used by the logical page
  structure
            Implementing the Swap Space

 The swap space is used in association with the main
    memory
   The programs are first loaded into the swap space
   When a program makes an access to a location in
    the virtual memory, the virtual address is used to find
    the corresponding lpage entry
   The address space is an array of vm_objects and
    each vm_object is an array of lpage structures
   From virtual address, you determine the
    corresponding vm_object
          Implementation of Swap Space

 In the vm_object, find the index of the corresponding
  lpage structure
 The lpage entry maps the virtual address to the
  address in physical memory and in swap space
 Whenever an lpage is created, a block in the swap
  space is requested (from the system that manages
  the swap space)
 On creation of the lpage, the physical address is set
  to invalid while the swap pointer points to a location
  in the swap space
                      Implementation

 When a program accesses a location that is not in physical
    memory (lpage_fault) -> the phy_addr in the corresponding
    lpage is set to invalid
   But the swap address is where the data resides
   So the lpage_fault routine obtains a page in the physical
    memory (remember that the physical memory is managed by
    coremap)
   The routine then copies that page from the swap space to
    physical memory
   Again, both the swap space and phy_addr are stored in the
    lpage structure
   The TLB is updated to reflect this.
                    Implementation

 The when the page_fault routine requests a physical
    page from the coremap, some page might have to
    be evicted
   The coremap implements the replacement policies
   The swap space is managed by another system that
    allocates and de-allocates the pages within the swap
    space
   Remember the swap space is like a file in the disk
   The VM system maintains the pages between the
    Phy memory and swap space in a way that for the
    programms, it is one contiguous block of memory

						
Related docs