Programming Assignment Virtual Memory
What Will We Do?
• In this project we will implement a simple virtual memory system.
vmem
Memory Access File
Page Size
# mem accesses after which R-bit
is cleared
Stats on screen
Please review slides
14 and 15 from
“Memory Management 3”
./vmem filename page num
Assumptions • Virtual address is 16 bits
• Physical address is 10 bits
Your Source Code
• vm.c
• compile with:
gcc –Wall –o vmem –std=c99 vm.c -lm
Input File Format
address read/write
Example:
abcd 0 123a 1 a345 0 3456 1
You are provided with a file that can generate input files for you.
Input File:
abcd 0 123a 1 a345 0 3456 1
Example
./vmref example.in 64 2
num reads = 2
num writes = 2
percentage of page faults 1.00
mem[0]: 2af
mem[1]: 48
mem[2]: 28d
mem[3]: d1
mem[4]: ffffffff
mem[5]: ffffffff
mem[6]: ffffffff
mem[7]: ffffffff
mem[8]: ffffffff
mem[9]: ffffffff
mem[10]: ffffffff
mem[11]: ffffffff
mem[12]: ffffffff
mem[13]: ffffffff
mem[14]: ffffffff
mem[15]: ffffffff
page = 64 bytes→offset = 6 bits abcd→1010 1011 1100 1101
Remove offset:
1010 1011 1100 1101
→1010 1011 11→2af
Notes About Input • page size: 32, 64, or 128 only
• Number of memory accesses after which R bit is cleared cannot be 0 or negative.
• We will not test your program with wrong inputs.
The Big Picture
• Read entry from the file: virtual address and op
• virtual address→virtual page number (VPN)
• Access page table using VPN – Page exists in physical memory
• Update R & M bits
– Page fault
• Physical memory has empty slot
• Physical memory is full
– Apply NRU (slides 14 and 15 in “Memory Management 3”)
– Update Page Table AccordinglyVery important step
Regarding NRU
• Start from the beginning of physical memory (i.e. address 0) and go downward.
• Victimize the page with lowest RM.
• If more than one page have the lowest RM, then victimize the page in the lowest address of them.
What To Submit
Your source code: single file with the name vm.c Do not submit anything else.
Avoid The Following Mistakes (Penalty applied for each)
• Late submission (-10% for each day for up to three days)
• Output with different format (-10)
• The work is not your own (zero!)
• The code works on your machine but not on CIMS machines (zero!)
– Test your code on one of the crunchy machines. That is, you need to ssh to access then to crunchy.
Excuses not Accepted • I submitted the wrong file.
• I submitted a bit after the deadline.
– We highly suggest that you upload a version, even if not yet complete, each time you implement something and do not wait till you finish the whole program.
– You are provided with one hour grace period.
One last thing
-
To help you start, we are proving you with a binary file that works as a reference.
– execute with: ./vmref filename page num
-
We are also providing you with another executable:
genfile that can generate input files for you. – execute with: ./genfile filename #entries
-
Important: These executable files will not run on your laptop. To use them, do the following:
– Copy them to the crunchy machines
– execute the following command first: • chmod777./vmref
• chmod 777 ./genfile
All the Best!