








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
CS 245 Lab Documentation with textbook links
Typology: Exercises
1 / 14
This page cannot be seen from the preview
Don't miss anything!
This lab project addresses the implementation of page-replacement algorithms in a demand-paging system. Reference Textbook : Garrido, José M., and Richard Schlesinger. Principles of modern operating systems. Jones & Bartlett Learning, (any edition 2 - 4) Each process in a demand-paging system has a page table that contains a list of entries. For each logical page of the process, there is an entry in the table that indicates if the page is in memory. If the page is in memory, the memory frame number that page is resident in is indicated. Also, for each page, the time at which the page has arrived in memory, the time at which it has been last referenced, and the number of times the page has been referenced since the page arrived in memory are maintained. The page table data structure is a simple array of page-table entries (PTEs). Each PTE contains five fields as defined below: PTE = { is_valid:False, frame_number:-1, arrival_timestamp: -1, Last_access_timestamp: -1, Reference_count: - } Each process in the system has a page table that is simply an array of PTEs. Each process also has a pool of frames that is allocated. The frame pool for a process is represented as an array of integers, where each Integer represents the frame number of a frame that is free and is available for use by the process. Note that in order to get the frame number in the pool, you first need to access the integer in the array. This lab project aims to exercise the various policies for page replacement. In particular, we study the following three page-replacement policies:
determine the memory frame number for the logical page. Also, the functions should modify the page table and the free frame pool appropriately. The details of the functions with respect to the different policies are described below. You need to develop code for these functions that implement the specifications. Place the code in a file called virtual.py. A starting place for the file would be: def process_page_access_fifo(page_table, page_number, frame_pool, current_timestamp): pass def count_page_faults_fifo(page_table, page_references, frame_pool): pass def process_page_access_lru(page_table, page_number, frame_pool, current_timestamp): pass def count_page_faults_lru(page_table, page_references, frame_pool): pass def process_page_access_lfu(page_table, page_number, frame_pool, current_timestamp): pass def count_page_faults_lfu(page_table, page_references, frame_pool): pass
[IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:20,ATS:2,LATS:4,RC:2] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:30,ATS:1,LATS:1,RC:1] input table_cnt 8 input page_number 0 input frame_pool EMPTY input frame_cnt 0 input current_timestamp 12 output page_table [IV:true,FN:30,ATS:12,LATS:12,RC:1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:10,ATS:3,LATS:3,RC:1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:20,ATS:2,LATS:4,RC:2] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] output table_cnt 8 output frame_pool EMPTY output frame_cnt 0 output int 30 Please refer to Section 3.4 of the Modern Operating Systems book for a detailed discussion of the First-In First-Out algorithm.
This function simulates the processing of a sequence of page references in a system that uses the First-In-First-Out (FIFO) policy for page replacement. Specifically, it takes three inputs:
This function implements the logic to process a page access in a system that uses the Least-Recently-Used (LRU) policy for page replacement. Specifically, it takes four inputs:
[IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:20,ATS:2,LATS:4,RC:2] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:30,ATS:1,LATS:1,RC:1] input table_cnt 8 input page_number 0 input frame_pool EMPTY input frame_cnt 0 input current_timestamp 12 output page_table [IV:true,FN:30,ATS:12,LATS:12,RC:1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:10,ATS:3,LATS:3,RC:1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:20,ATS:2,LATS:4,RC:2] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:0,LATS:0,RC:0] output table_cnt 8 output int 30 Please refer to Section 3.4 from the Modern Operating Systems book for a detailed discussion of the Least-Recently-Used algorithm.
A sample execution input and output: input/output parameter value input page_table [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] input table_cnt 8 input reference_string [0, 3, 2, 6, 3, 4, 5, 2, 4, 6, 5] input reference_cnt 11 input frame_pool [0, 1, 2] input frame_cnt 3 output faults 9 Please refer to Section 3.4 of the Modern Operating Systems book for a detailed discussion of the Least-Recently-Used algorithm.
This function implements the logic to process a page access in a system that uses the Least-Frequently-Used (LFU, also known as Not-Frequently-Used) policy for page replacement. Specifically, it takes four inputs: 1) process page table, 2) logical page number, 3) process frame pool, and 4) current timestamp. The function determines the memory frame number for the logical page and returns this number. First the function checks if the page being referenced is already in memory (i.e., the page-table entry has the valid bit true). If so, it returns the frame number, after modifying the last_access_timestamp and the reference_count fields of the page-table entry. 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). If so, a frame is removed from the process frame pool and the frame number is inserted into the page-table entry corresponding to the logical page number. In addition, the other fields of the page-table entry are set appropriately. The function returns the frame number associated with the page-table entry. If the page being referenced is not in memory and there are no free frames for the process, a page needs to be replaced. 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 reference_count. If multiple pages have the smallest reference_count, the one with the smallest arrival_timestamp among these is selected. After selecting the page for replacement, the function marks that page-table entry as invalid, and sets the frame_number, arrival_timestamp, last_access_timestamp and reference_count to -1. It then sets the frame_number of the page-table entry of the newly-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. Finally, the function returns this frame number. The signature of the method is as follows: process_page_access_lfu(page_table, page_number,frame_pool, current_timestamp) A sample execution input and output: input/output parameter value input page_table [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:true,FN:10,ATS:3,LATS:3,RC:1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1]
This function simulates the processing of a sequence of page references in a system that uses the Least-Frequently-Used (LFU, also known as Not-Frequently-Used) policy for page replacement. Specifically, it takes three inputs:
The signature of the method is as follows: count_page_faults_lfu(page_table, refrence_list, frame_pool) A sample execution input and output: input/output parameter value input page_table [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] [IV:false,FN:-1,ATS:-1,LATS:-1,RC:-1] input table_cnt 8 input reference_string [0, 3, 2, 6, 3, 4, 5, 2, 6, 4, 5] input reference_cnt 11 input frame_pool [0, 1, 2] input frame_cnt 3 output faults 10 Please refer to Section 3.4 of the Modern Operating Systems book for a detailed discussion of the Not-Frequently-Used algorithm.