6 Nachos Memory Management

As discussed in Section 3, the processor provides registers and physical memory, and supports virtual memory.

The physical memory is byte-addressable and organized into 1-kilobyte pages. A reference to the main memory array is returned by getMemory(). Memory corresponding to physical address m can be accessed in Nachos at Machine.processor().getMemory()[m]. The number of pages of physical memory is returned by getNumPhysPages().

When it comes to virtual memory for multi-programming, there are two key aspects that need to be addressed in the implementation. First, how is the physical memory allocated among user processes? Since virtual memory allows the size of the address space of a user process to be larger than that of the physical memory, naturally, questions like which part of the address space should be in the physical memory and what happens in presence of a page fault arise. In the class, we have discussed types of page faults and various strategies for page replacement including FIFO, LRU, etc. The second question is how to map virtual addresses to physical addresses. Users should only be concerned with virtual addresses. However, actual memory references should be with respect to physical addresses. In what follows, we will investigate how the two aspects are implemented in the default Nachos.

 6.1 Memory allocation
 6.2 Address translation
  6.2.1 Software-managed TLB
  6.2.2 Per-process page table
 Exercise