CSE 120: Nachos VM Worksheet

In Project #2, part 2, you will be creating and initializing the page tables used by user-level processes running on Nachos. This worksheet is intended to give you practice with Nachos page tables so that you are comfortable understanding how virtual memory works in Nachos. The page table for a user-level process is represented by the TranslationEntry[] pageTable array in the UserProcess class. In the UserProcess constructor, you will be initializing each TranslationEntry in the array to have each virtual page point to an allocated physical page.

For the purposes of this worksheet, assume that Processor.PageSize is 128 bytes (0x80), the program being loaded requires 4 pages, and physical memory has 8 pages. In the diagram below, we have assigned a set of physical pages (from Processor.mainMemory) to virtual pages (in UserProcess.pageTable).

  1. What is the value of UserProcess.numPages?

  2. What is the value of Processor.numPhysPages?

  3. What are the values of the UserProcess.pageTable mappings?

  4. What is the virtual address of virtual page 2 (the start of virtual page 2 in the virtual address space)?

  5. What is the physical address of virtual page 2? (The physical address will be used as the offset in the Processor.mainMemory array.)

  6. What physical page does the virtual address 298 reside in?

  7. What is the offset of the virtual address 298?

  8. What is the physical address of the virtual address 298?

  9. You will be modifying the implementations of UserProcess.readVirtualMemory and UserProcess.writeVirtualMemory. The initial implementations use System.arraycopy to copy the data bytes between the kernel and the process virtual address space. In the general case that your implementation has to handle, why does the simple System.arraycopy no longer work? (Hint: Given the page table above, consider the case for readVirtualMemory when vaddr is 0x7E and data.length is 4.)