The reasons for replacing program pages inside memory frames

  • Fact 1:   re-using memory frames is necessary

    • The number of memory frame is (much) smaller than the number of program pages

    Therefore:  

    • Sooner or later, all memory frame will be used and a page fault will require replacing some program page with a new page

  • Fact 2:   re-suing memory frames is efficient

    • A program often consists of a number of "disjoint" loops

      E.g.:

        loop1; // --> Pages of loop1 in memory frames at one time 
        ...
        loop2; // --> Pages of loop2 in memory frames at a later time
      

    Memory frames can be re-used to store pages from different loops at different time !!

Page requests from the execution of a computer program

  • Consider the following computer program we nested loops:

     
     

Page requests from the execution of a computer program

  • The CPU will first fetch instructions from program page 0 in the program:

  • Instructions that do not use memory variables can be executed without additional memory access operation

Page requests from the execution of a computer program

  • Occasionally, the CPU fetches a ldr/str instruction:

  • Since the variables are stored in a different part in the program, a ldr/str instruction will need to access a different program page

Page requests from the execution of a computer program

  • The execution of a computer program will result in a series of page requests:

  • Notice that there may be consecutive requests for the same page #
     

Page requests from the execution of a computer program

  • Only the first page request in a series for the same page can cause a page fault

  • Because the same pages will remain in memory until another page fault occurs
     

Page requests from the execution of a computer program

  • Hence, to study the page replacement algorithm, we can summarize the page requests:

  • The performance of paging depends on the page replacement policy used.
      next

Commonly used page replacement policies

  • There are 3 effective page replacement policies:

    • First In First Out (FIFO)

      • The policy is simple to implement

      • This policy can result in a high number of page faults

    • Least Recently Used (LRU):

      • This policy has the least number of page fault

      • The run time complexity to find the smallest time stamp is O(n)

    • Second chance:

      • An approximation algorithm for LRU

      • Used today in all operating systems with paging