Question
this program has assumed that physical memory is he same size as the virtual address space edit this program to use smaller physical address space
this program has assumed that physical memory is he same size as the virtual address space edit this program to use smaller physical address space with 128 page frames rather than 256 you must implement a page-replacement policy using FIFO
input addresses: 16919 62493 30198
output: 20 285 758 my program :
import java.io.*; import java.util.*;
public class CPCS361CS3 {
public static void main(String[] args) {
int page_table[] = new int[256]; int memory[] = new int[(256 * 256)]; int tlb_index = 0; TLB tlb = new TLB(new int[16], new int[16], tlb_index); int page_fault_rate = 0; int frames = 0; int tlb_hit_rate = 0;
for (int i = 0; i < 256; i++) { page_table[i] = -1; }
try { Scanner input_data = new Scanner(new File("addresses.txt")); RandomAccessFile backing_store = new RandomAccessFile(new File("BACKING_STORE.bin"), "r"); int line = 0;
while (input_data.hasNext()) { String input_line = input_data.nextLine(); int logical_address = Integer.valueOf(input_line); int physical_address = 0; int page_number = (logical_address / 256 ); //get page number from input line int offset = logical_address % 256; //get offset from input_line int frame = -1; //if the frame still reads -1 then we can go to the next method of checking
frame = tlb.find(page_number); //attempt to find the page in TLB
if (frame != -1) {
tlb_hit_rate++; //if we get here that means the page was found in the TLB and the frame was returned
physical_address = frame * 256 + offset; } else {
frame = page_table[page_number]; //check to see if its in the page table if (frame == -1) //load from bin file {
page_fault_rate++; byte page[] = new byte[256]; backing_store.seek(page_number * 256); //jump to the page location backing_store.read(page); //read in a page of 256 bytes frame = frames % 256; //set the new frame frames++; page_table[page_number] = frame; //update the page table int start = frame * 256; for (int i = 0; i < 256; i++) { memory[(start + i)] = page[i]; //add it to memory
} } physical_address = frame * 256 + offset; //get physical address from the new frame and read in offset tlb.update(page_number, frame); //update the TLB with page number and the new frame } //below is the printout of virtual address / physical address and the value stored in memory
System.out.println(memory[physical_address]); line++; //increment line read in }
System.out.println("Page Faults = " + page_fault_rate); System.out.println("TLB Hits = " + ++tlb_hit_rate);
backing_store.close(); input_data.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started