#include <stdio.h>
#include <string.h>
#include <stdbool.h>
// 1
int process_page_access_fifo(struct PTE page_table[TABLEMAX],int *table_cnt, int page_number, int frame_pool[POOLMAX],int *frame_cnt, int current_timestamp) { // first checks if the page being referenced is already in memory (i.e., the page-table entry has the valid bit true) if (page_table[page_number].is_valid == true) { // modifies the last_access_timestamp page_table[page_number].last_access_timestamp = current_timestamp; // and the reference_count fields of the page-table entry page_table[page_number].reference_count += 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // checks if there are any free frames (i.e., the process frame pool is not empty) } else if ((page_table[page_number].is_valid == false) && (*frame_cnt > 0)) { // a frame is removed from the process frame pool *frame_cnt -= 1; // the frame number is inserted into the page-table entry corresponding to the logical page number page_table[page_number].frame_number = frame_pool[*frame_cnt-1]; // the other fields of the page-table entry are set appropriately page_table[page_number].is_valid = true; page_table[page_number].last_access_timestamp = current_timestamp; page_table[page_number].reference_count = 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // If the page being referenced is not in memory and there are no free frames for the process, a page needs to be replaced. } else { bool temp_flag = false; int temp_index = 0; int temp_frame = 0; int temp_arrival_stemp = 0; // The function selects among all the pages of the process that are currently
in memory (i.e., they have valid bits as true) // the page that has the smallest arrival_timestamp. for (int index = 0; index < *table_cnt ; index++) { if ((page_table[index].is_valid == true) && (temp_flag== false)) { temp_index = index; temp_frame = page_table[index].frame_number; temp_arrival_stemp = page_table[index].arrival_timestamp; temp_flag = true; } else if ((page_table[index].is_valid == true) && (temp_arrival_stemp > page_table[index].arrival_timestamp) && (temp_flag== true)) { temp_arrival_stemp = page_table[index].arrival_timestamp; temp_index = index; temp_frame = page_table[index].frame_number; } } // It marks that page-table entry as invalid, along with setting the arrival_timestamp, last_access_timestamp and reference_count to 0. // It then sets the frame_number of the page-table entry of the newly-This study source was downloaded by 100000857840091 from CourseHero.com on 12-07-2022 03:27:51 GMT -06:00
https://www.coursehero.com/file/102607567/virtualc/ referenced page to the newly freed frame. // It also sets the arrival_timestamp, the last_access_timestamp and the reference_count fields of the page-table entry appropriately. if (temp_flag == true) { page_table[temp_index].is_valid = false; page_table[temp_index].arrival_timestamp = 0; page_table[temp_index].last_access_timestamp = 0; page_table[temp_index].reference_count = 0; page_table[temp_index].frame_number = -1; page_table[page_number].arrival_timestamp = current_timestamp; page_table[page_number].last_access_timestamp = current_timestamp; page_table[page_number].frame_number = temp_frame; page_table[page_number].reference_count = 1; page_table[page_number].is_valid = true; } // returns the total number of page faults encountered in the simulation return temp_frame; }
}
// 2 - determines the memory frame number for the logical page and returns this number
int count_page_faults_fifo(struct PTE page_table[TABLEMAX],int table_cnt, int refrence_string[REFERENCEMAX],int reference_cnt,int frame_pool[POOLMAX],int frame_cnt) { // set timestamp and frame number int timestamp = 1, page_fault = 0; for (int i = 0; i < reference_cnt; i++) { // checks if the page being referenced is already in memory (i.e., the page-
table entry has the valid bit true) if (page_table[refrence_string[i]].is_valid == true) { // returns the frame number, after modifying the last_access_timestamp and
the reference_count fields of the page-table entry page_table[refrence_string[i]].last_access_timestamp = timestamp; page_table[refrence_string[i]].reference_count += 1; // If the page being referenced is not in memory, the function checks if there are any free frames (i.e., the process frame pool is not empty) } else if ((page_table[refrence_string[i]].is_valid == false) && (frame_cnt >
0)) { // a frame is removed from the process frame pool frame_cnt -= 1; page_fault += 1; // and the frame number is inserted into the page-table entry corresponding to the logical page number page_table[refrence_string[i]].frame_number = frame_pool[frame_cnt-1]; // the other fields of the page-table entry are set appropriately page_table[refrence_string[i]].is_valid = true; page_table[refrence_string[i]].last_access_timestamp = timestamp; page_table[refrence_string[i]].reference_count += 1; // If the page being referenced is not in memory and there are no free frames
for the process, a page needs to be replaced } else if ((page_table[refrence_string[i]].is_valid == false) && (frame_cnt == 0)) { page_fault += 1; bool temp_flag = false; int temp_index = 0; int temp_frame = 0;This study source was downloaded by 100000857840091 from CourseHero.com on 12-07-2022 03:27:51 GMT -06:00
https://www.coursehero.com/file/102607567/virtualc/