page_Replacement_practical

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Experiment No.

Aim: Implementing page replacement algorithm.


1) FIFO
2) LRU

Outcome:-
How to divided the program in equal size pages to optimized its execusion by replacing the
pages by considering different page replacement algorithms.

Pre-Lab Requisite:-
1. Explain the concept of virtual memory.
2. Define page replacement algorithm: FIFO & LRU

Post-Lab Requisite:-
1. Explain address translation in paging system.
2. Explain Belady's Anomaly.
3. Solve the following string for FIFO & LRU for frame size 3. Also calculate hit
ratio. 4 3 2 1 4 3 5 4 3 2 1 5

Theory:
Whenever there is a page reference for which the page needed in memory, that event is called
page fault or page fetch or page failure situation. In such case we have to make space in memory for
this new page by replacing any existing page. But we cannot replace any page. We have to replace a
page which is not used currently. There are some algorithms based on them. We can select appropriate
page replacement policy. Designing appropriate algorithms to solve this problem is an important task
because disk I/O is expensive.

There are several algorithms to achieve.


1) First in First out (FIFO)
2) Last recently used
I. FIFO Page replacement:
It is the simplest page replacement algorithm. A FIFO algorithm associates each page with the
time when that page was brought into memory. When a page must be replaced the oldest page is
chosen. We can create a FIFO queue to hold all pages in memory. We replace the page at the head of
the queue. When a page is brought into memory we insert it at the end of queen.
Consider the reference string 7,0,1,2,0,3,4,2,3,0,3,2,1,2,0,1,7,0,1 with memory of three
reference (7,0,1) causes the page faults and are brought in to this memory frames. The next reference
two replaces page 7 because firstly page 7 was brought in to memory. Then 0 is the next string which
is already in memory, so we have no page fault for this reference.
Then next reference two replaces string is three. At this time page 0, is replaced because it was
first at the three pages in memory (0, I , 2) The next string is 0. Now we replace page 1 for this new
string 0.
In this way this process continues until the end of reference string. These are 15 faults
algorithm.

FIFO has key disadvantages:


1) If a page is frequently and continuously used it will eventually becomes the oldest and will
be removed even though it will be needed again immediately.
2) At Some stage side effects can occur.
3) Other algorithms have been found to be more effective.

II. LRU page replacement:


The main difference between FIFO and optimal page replacement is that the FIFO algorithms
uses the time when the page was brought in to memory and the. optimal algorithm uses the time when
a page is to be used. If we use the recent past as an approximation of the future then we will replace
the page that has not been used for the longest period of time. This approach is called as least recently
used (LRU) algorithm.
LRU replacement associates with each page must be replaced. LRU chooses that page that has
not been used for the longest period of time.
Now, consider reference string 7,0,1,2,0,3,4,2,3,0,3 with three memory frames or blocks The
first three reference cases page fault that fill the empty frames.

You might also like