Question: Write a program in C that runs FIFO and LRU page replacement algorithms. Use the page reference sequence in an input file to drive your
Write a program in C that runs FIFO and LRU page replacement algorithms. Use the page reference sequence in an input file to drive your program. Report the number of page faults and time costs incurred by the page faults. The number of available page frames should be set according to an input of your program. In your program, we assume that demand paging is used. All the memory page frames are unallocated initially, and all the referenced pages are initially in the swap space. Each page is associated with a modify bit MB which indicates whether the page has been modified in memory and needs to be swapped out if being evicted.
The program should accept the following input parameters to specify:
a The selected replacement algorithm FIFO or LRU
b The memory size the number of available page frames
c Time cost for swapin time needed to swap in a page from swap space into memory
d Time cost for swapout time needed to swap out a page from memory to swap space
e The input page reference file that contains the page references reference see the format
details below
f The output trace file that contains detailed output info for each page reference.
Example: $replace LRU pageref.txt tracelru.txt
This example command means that the system uses the LRU replacement algorithm, has free physical page frames in memory, swapping in a page takes time units, swapping out a page takes time units, use page references in pagereftxt as input, and generate an output file tracelru.txt
Input Page Reference File Format: Each line contains two fields. The first field is either R or W meaning a read or a write to the page, respectively. The second field is the page number. Each line of the input file thus specifies a page reference.
: R
: W
: R
: R
: R
In the above example, the first line means a read reference to Page # and the second line means a write reference to Page # Two sample input reference files pagereftxt and pagerefsmall.txt are provided online as examples. Output Trace File Format: The program should generate a trace file as output. Each line should contain fields, following the record line number. The first field is either R or W meaning a read or a write to the page, respectively. The second field is the page number, specifying the page being referenced. The third field specifies whether this page reference incurs a page fault denoted as F or not ie a page hit in memory, denoted as H The fourth field specifies the victim page number, if a victim page is evicted. If no victim page being evicted, use to indicate that. The last two fields are the swapin time and swapout time for servicing this page reference, respectively.
: R F
: W H
: R F
: R F
: R F
In the above example, the first line records a read reference to Page # which is a miss in memory, causing a page fault. There is no victim page being evicted, and it takes time units to swap in the target page, but it does not incur any time cost for swapping out a page. The second line records a write reference to Page # which is a hit in memory, which does not incur swapin or swapout. The third line records a read reference to page # which is a miss in memory and incurs a swapin cost of time units. The fourth line records a read reference to Page # which is a miss in memory and triggers eviction of Page # which incurs a swapin operation for loading Page # and a swapout operation for writing the modified Page # back to the swap space.
Upon completion of the execution, the program should generate the following output summary information to the standard output.
a The total number of page references.
b The total number of page faults on read references.
c The total number of page faults on write references.
d The total number of time units for swapping in pages from swap space.
e The total number of time units for swapping out pages to swap space.
Page fault costs: The program needs to calculate the cost of page faults in terms of time units. In the example above, upon a page miss the target page is not found in memory it takes time units to swap in the page to memory. In the case that needs to evict a victim page, if the victim page has been modified written in memory since it was loaded into memory, it takes time units to swap out the modified victim page to the swap space; If the victim page is unmodified unwritten there is no need to swap it out. Thus, a modify bit MB is needed for each page frame to keep track of the page status. We assume that all memory page frames are unallocated initially, all pages are initially in the swap space, and either read or write to a page that is not resident in memory incurs a page fault and needs to swap in the page first.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
