Question: For this project, you much be working independently. This project consists of writing a program that translates logical to physical addresses for a virtual address
For this project, you much be working independently. This project consists of writing a program that translates logical to physical addresses for a virtual address space of size 216 = 65,536 bytes. Your program will read from a file containing logical addresses and, using a TLB as well as a page table, will translate each logical address to its corresponding physical address and output the value of the byte stored at the translated physical address. The goal behind this project is to simulate the steps involved in translating logical to physical addresses.
Your program will read the file addresses.txt containing logical addresses ranging from 0 - 65535. Each logical address can be represented as a 16-bit integer number with an 8-bit page number and 8-bit page offset. Your program will implement demand paging. The backing store is represented by the file BACKING_STORE.bin, a binary file of size 65,536 bytes. When a page fault occurs, you will read in a 256-byte page from the file BACKING_STORE and store it in an available page frame in physical memory. For example, if a logical address with page number 15 resulted in a page fault, your program would read in page 15 from BACKING_STORE (remember that pages begin at 0 and are 256 bytes in size) and store it in a page frame in physical memory. Once this frame is stored (and the page table and TLB are updated), subsequent accesses to page 15 will be resolved by either the TLB or the page table. You will need to treat BACKING_STORE.bin as a random-access file so that you can randomly seek to certain positions of the file for reading. You may use either a FIFO or an LRU policy for updating your TLB and page table.
Specifics:
physical memory size: 128 page frames
TLB size: 30 entries
Your program should output the following values:
1. The logical address being translated (the integer value being read from addresses.txt).
2. The corresponding physical address (what your program translates the logical address to).
3. The signed byte value stored at the translated physical address.
After completion, your program should report the following statistics:
1. Page-fault rateThe percentage of address references that resulted in page faults.
2. TLB hit rateThe percentage of address references that were resolved in the TLB.
Hint:
Example code for reading logical address file:
FILE *input_fp = fopen(input_filename, "r");
while (fgets(buffer, BUFFER_SIZE, input_fp) != NULL) {
int logical_address = atoi(buffer);
}
Example code for mapping backing store file to memory:
int backing_fd = open(backing_filename, O_RDONLY);
backing = mmap(0, MEMORY_SIZE, PROT_READ, MAP_PRIVATE, backing_fd, 0);
Example code for copying page from backing store file into physical memory
memcpy(main_memory + physical_page * PAGE_SIZE, backing + logical_page * PAGE_SIZE, PAGE_SIZE);
More details about functions, fopen, fget, mmap, memcpy, are available online.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
