Page Replacement Algorithms
Page Replacement Algorithms
Replacement Algorithms
Prepared By:
Dr. Sanjeev Gangwar
Assistant Professor,
Department of Computer Applications,
VBS Purvanchal University, Jaunpur
PAGE REPLACEMENT ALGORITHMS
In an operating system that uses paging for memory management, a page replacement algorithm
is needed to decide which page needs to be replaced when new page comes in.
2. Or, remove some other process completely from the memory to free frames.
3. Or, find some pages that are not being used right now, move them to the disk to get free
Frames.
Page Fault – A page fault happens when a running program accesses a memory page that is
mapped into the virtual address space, but not loaded in physical memory.
Since actual physical memory is much smaller than virtual memory, page faults happen. In case
of page fault, Operating System might have to replace one of the existing pages with the newly
needed page. Different page replacement algorithms suggest different ways to decide which page
to replace. The target for all algorithms is to reduce the number of page faults.
Page Replacement Algorithm
There are many different page replacement algorithms. We evaluate an algorithm by running it
on a particular string of memory reference and computing the number of page faults. The string
of memory references is called reference string. Reference strings are generated artificially or by
tracing a given system and recording the address of each memory reference.
To determine the number of page faults for a particular reference string and page replacement
algorithm, we also need to know the number of page frames available. As the number of frames
available increase, the number of page faults will decrease.
We shall use the following page reference string to explain the page replacement algorithm
5, 0, 1, 0, 2, 3, 0, 2, 4, 3, 3, 2, 0, 2, 1, 2, 7, 0, 1, 1, 0
for a memory with three frames.
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1
0 0 0 0 3 3 3 3 3 3 2 2 2 2 2 2 0 0 0 0
5 5 5 5 2 2 2 2 4 4 4 4 4 4 4 4 7 7 7 7 7
H H H H H H H H H H
Case 1: Frame=3
2 2 2 1 1 1 1 1 3 3
1 1 1 0 0 0 0 0 2 2 2
0 0 0 3 3 3 4 4 4 4 4 4
H H H
Fig (a)
Page Fault= 9
Case 2: Frame=4
3 3 3 3 3 3 2 2 2
2 2 2 2 2 2 1 1 1 1
1 1 1 1 1 1 0 0 0 0 4
0 0 0 0 0 0 4 4 4 4 3 3
H H
Fig (b)
Page Fault= 10
Advantages:
In this algorithm, the page that has been not used for longest period of time is selected for
replacement.
5, 0, 1, 0, 2, 3, 0, 2, 4, 3, 3, 2, 0, 2, 1, 2, 7, 0, 1, 1, 0
1 1 1 3 3 3 4 4 4 4 0 0 0 0 7 7 7 7 7
0 0 0 0 0 0 0 0 3 3 3 3 3 1 1 1 0 0 0 0
5 5 5 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1
H H H H H H H H H
Disadvantages:
This algorithm state that: replace that page which will not be used for longest period of time i.e.
future knowledge of reference string is required.
Example: Reference string is
5, 0, 1, 0, 2, 3, 0, 2, 4, 3, 3, 2, 0, 2, 1, 2, 7, 0, 1, 1, 0
1 1 1 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1
0 0 0 0 0 0 0 4 4 4 4 0 0 0 0 0 0 0 0 0
5 5 5 5 2 2 2 2 2 2 2 2 2 2 2 2 7 7 7 7 7
H H H H H H H H H H H H
Disadvantages:
➢ Optimal page replacement algorithm is perfect, but not possible in practice as the
operating system cannot know future requests.
➢ Error handling is tough.
4 4 4 4 4 4 1 1 1 1 1 1 2 2 2 2 2
3 3 3 3 3 3 2 2 2 2 2 6 6 6 6 6 6 6
2 2 2 2 2 2 6 6 6 6 6 7 7 7 7 7 7 3 3
1 1 1 1 1 1 5 5 5 5 5 3 3 3 3 3 1 1 1 1
H H H H H H
4 4 4 4 6 6 6 6 6 7 7 7 7 1 1 1 1
3 3 3 3 5 5 5 5 5 3 3 3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 6 6
H H H H H H H H H H
4 4 4 5 6 6 6 6 6 6 6 6 6 6 6 6 6
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7 1 1 1 1
H H H H H H H H H H H H
References:
(1) Abraham Silberschatz, Galvin & Gagne, Operating System Concepts, John Wiley &
Sons, INC.
(2) Harvay M.Deital, Introduction to Operating System, Addition Wesley Publication
Company.
(3) Andrew S.Tanenbaum, Operating System Design and Implementation, PHI