Lectures, Assignments, and Exercises
2.1 proc
2.2 ipc
2.3 vm
2.4 fs
2.5 io
2.6 virt
2.7 sec
2.8 perf
2.9 Paper
2.10 Presentation
2.11 Midterm
2.12 Final

2.3 vm

This exercise is optional. Refer to the exercise policy for details.
Implement a simulation of a virtual memory system. Your simulation should have a fixed amount of physical memory and disk swap space. Your simulation should receive a stream of memory requests of the form:
  • alloc PID SIZE to allocate SIZE bytes for the process PID. This should return a virtual address.

  • use PID VADDR to use a virtual address.

  • free PID VADDR to free memory, assuming VADDR is the addressed returned by an alloc request.

As your simulation runs, it should maintain a page tables and mappings from virtual to physical addresses. Given that the simulation doesn’t actually include read or write operations, you only need to store these tables. You don’t need to actually keep track of any data, so you can run with much larger memories than your computer actually supports. Make sure you account for the space to store your metadata and page tables inside the simulated memory!
When the simulation is over, it should output statistics such as peak memory utilization, the efficiency of the paging system, and so on.
Consider implementing a second variant that looks at an entire set of request upfront and computes the optimal allocation and page replacement policy.