CSE 120: Nachos VM Worksheet
In Task 2 in Project 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.
The size of a memory page in Nachos (Processor.pageSize)
is 1024 (0x400) bytes. For the purposes of this worksheet, assume
that 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).
- What is the value of UserProcess.numPages?
- What is the value of Processor.numPhysPages?
- What are the values of the UserProcess.pageTable mappings?
- pageTable[0].vpn =
- pageTable[0].ppn =
- pageTable[1].vpn =
- pageTable[1].ppn =
- pageTable[2].vpn =
- pageTable[2].ppn =
- pageTable[3].vpn =
- pageTable[3].ppn =
- What is the virtual address of virtual page 2 (the start of virtual page 2 in the virtual address space)?
- What is the physical address of virtual page 2? (The physical address will be used as the offset in the Processor.mainMemory array.)
- What physical page does the virtual address 2100 reside in?
- What is the offset of the virtual address 2100?
- What is the physical address of the virtual address 2100?
- 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 1022 (0x3FE) and data.length is 4.)