Virtual memory allows a process of P pages to run in F frames, even if F < P. This is achieved by use of a page table, which records which pages are in RAM in which frames, and a page fault mechanism by which the memory management unit (MMU) can ask the operating system (OS) to bring in a page from disk. The page table must be accessible by both the MMU and the OS, and an IPC facility is needed for communication between the MMU and OS. Given the MMU simulator below, write a program that does the work of the OS to maintain a process' use of RAM and the page table. The page table is held in shared memory, and signals are used for IPC. You do not need to simulate the RAM, only the page table maintenance. However, to make things realistic, your OS process must sleep(1) whenever a disk access (write out page to disk, read in page from disk) would be necessary in a real implementation.
The MMU attaches to the shared memory (using the OS PID on the command line as the key), then runs through the reference string. For each memory access, the MMU:
After creating and initializing the page table in the shared memory, the OS must sit in a loop waiting for a SIGUSR1 signal from the MMU. When it receives a signal, it must:
> OS 5 2
The shared memory key (PID) is 78801
Initialized page table
> MMU 5 W2 R3 W3 R4 78801
Initialized page table:
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=0 Frame=-1 Dirty=0 Requested=0
3: Valid=0 Frame=-1 Dirty=0 Requested=0
4: Valid=0 Frame=-1 Dirty=0 Requested=0
Request for page 2 in W mode
It's not in RAM - page fault
Process 78803 has requested page 2
Put it in free frame 0
Unblock MMU
Set the dirty bit for page 2
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=1 Frame= 0 Dirty=1 Requested=0
3: Valid=0 Frame=-1 Dirty=0 Requested=0
4: Valid=0 Frame=-1 Dirty=0 Requested=0
Request for page 3 in R mode
It's not in RAM - page fault
Process 78803 has requested page 3
Put it in free frame 1
Unblock MMU
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=1 Frame= 0 Dirty=1 Requested=0
3: Valid=1 Frame= 1 Dirty=0 Requested=0
4: Valid=0 Frame=-1 Dirty=0 Requested=0
Request for page 3 in W mode
It's in RAM
Set the dirty bit for page 3
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=1 Frame= 0 Dirty=1 Requested=0
3: Valid=1 Frame= 1 Dirty=1 Requested=0
4: Valid=0 Frame=-1 Dirty=0 Requested=0
Request for page 4 in R mode
It's not in RAM - page fault
Process 78803 has requested page 4
Chose a victim page 2
Victim is dirty, write out
Put in victim's frame 0
Unblock MMU
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=0 Frame=-1 Dirty=0 Requested=0
3: Valid=1 Frame= 1 Dirty=1 Requested=0
4: Valid=1 Frame= 0 Dirty=0 Requested=0
Tell OS that I'm finished
The MMU has finished
0: Valid=0 Frame=-1 Dirty=0 Requested=0
1: Valid=0 Frame=-1 Dirty=0 Requested=0
2: Valid=0 Frame=-1 Dirty=0 Requested=0
3: Valid=1 Frame= 1 Dirty=1 Requested=0
4: Valid=1 Frame= 0 Dirty=0 Requested=0
4 disk accesses required
~csc521/bin/submit2 csc521 VirtualMemory <your file names>
Your program will be assessed on:
Solution
~geoff/CSC521/VirtualMemory/OS.