Project 5: Frequently Asked Questions

  1. When a page fault occurs, how can I tell if it is a read or a write?

    The page fault handler does not tell you directly. What you need to do is look at the existing permissions on the page, and conclude that the fault is due to the missing permission. If the page has no permissions, you should add the PROT_READ permissions and return. If the page has PROT_READ, then you should add PROT_WRITE and continue. (PROT_EXEC shouldn't happen in this assignment.)

  2. How can I tell if a given page is written on disk or in memory?

    Call page_table_get_entry(page,&frame,&bits). If the given page has non-zero permission bits, then it resides in the indicated frame number. If the permission bits are zero, then it is not in memory, and the frame number is irrelevant.

  3. Am I responsible for keeping track of which frames are free?

    Yes, you should create a frame table that keeps track of the state of each frame. That will make it easy to find a free frame for replacement, and determine what page was previously stored there.

  4. What should the contents of a page be when it is read in from disk in the first time?

    In a real operating system, the contents of a page should initially be all zeroes. As it turns out, it does not matter for this project, since each program fills in each page with its own data before attempting to read it.

  5. Why does my program get stuck in an infinite loop when there is only one page of physical memory?

    It is possible for an instruction to touch more than one page of memory. For example, MOV a, b could touch three pages of memory if a and b are in different pages, and the executable instruction is in a third page. If there is only one page of physical memory, you will get an endless number of page faults as you switch between the desired pages. Just start your testing at a minimum of three pages.

  6. What is the correct output for the programs alpha, beta, etc...?

    For a specific number of pages, a program should give the same result, no matter how many frames you give it, or what page replacement algorithm is used. You can easily determine the correct output value for each program by running it with the trivial page fault handler suggested at the beginning of the assignment. Here are some sample values for 10 and 100 pages:

           10 pages     100 pages
    alpha  315081       318220 
    beta   5232896      52292377
    gamma  2220835000   695710910
    delta  104448000    1044480000	
    
    A good correctness test is to run your program with a fixed number of pages and vary the frames If you always get the same number, then your virtual memory system is working. If the number changes, then there is some mistake in how you are handling page faults.