Skip to main content

Page Replacement Algorithms In O/S

There are many different page-replacement algorithms. Every operating system probably has its own replacement scheme.  Let us watch various types of page replacement algorithms in this post. There are following types of page replacement algorithms :-
  1. FIFO page replacement.
  2. Optimal page replacement.
  3. LRU page replacement.

In general, we want the algorithm which have the lowest page-fault rate. We evaluate an algorithm by running it on a particular string of memory references and computing the number of page faults. The string of memory references is called a reference string. We can generate reference strings artificially by using a random-number generator. 

We use the reference string as follows for a memory with three frames :-
     7 0 1 2 0 3 4 2 3 0 3 2 0 1 7 0 1

1. FIFO page replacement :-
   It is the simplest page replacement algorithm. Its full form is First-In-First-Out. A FIFO page replacement associates with each page the time when page was brought into memory. When a page must be replaced, the oldest page is chosen. Notice that it is not necssary to record the time when a page is brought in. 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 tail of the queue.
  For example. our three frams are initially empty.
The first three frames are initially empty. The first three references ( 7, 0, 1) cause page fault and are brought into these empty frames. The next reference (2) replace page 7, because 7 was brought at first. Since ) is the next reference and is present already in memory, we have no page fault there. And so on this algorithm works.

The  FIFO page replacement algorithm is easy to understand and program. However, its performance is not always good.
  Notice that, even if we select fot replacement a page that is in active use, everything still works correctly. After we replace an active pafe with a new one, a fault occurs almost immidiately to retrive the active page. Thus, a bad replacement choice increase the page fault rate and slows process execution.


2. Optimal page replacement :-
      It is a type of page replacement algorithm. This algoritm has the lowest has the lowest page fault rate among all algorithms. This algorithm is also known as OPT or MIN. Its rule is simple as replace the page that will not be used for the longest period of time.
   
Use of this page replacement algorithm guaramtees the lowest possible page fault rate for a fixed number of frames.
   Unfortunately, the optimal page replacement algorithm is difficult to implement, because it requres future knowledge of the refrence string. For example. our three frams are initially empty.
The first three frames are initially empty. The first three references ( 7, 0, 1) cause page fault and are brought into these empty frames. The reference to page 2 replaces page 7, because page 7 will not be used untill refrence 18, where as 0 will be used at 5, and page 1 at 14. The refrence to page 3 replaces page 1, as page 1 will be the last of the three pages in memory to be refrenced. again and so on..
  


3. LRU page replacement :-
      It is a type of page replacement algorithm. Its full form is Least Recently Used. If the optimal algorithm is not feasible, perhaps an approximation of the optimal algorithm is possible. This algorithm is used. If we use recent past as an approximation of the near future, then we can replace the page that has not been used for the long period of time. This approach is the least recently used algorithm.

LRU replacement associates with each page the time of page's last use.When a page must be replaced, LRU chooses tha page that has not been used for the longest period of time. We can think of this strategy as the optimal page replacement algorithm looking backward in time, rather then forward. 
  For example. our three frams are initially empty.
The first three frames are initially empty. The first three references ( 7, 0, 1) cause page fault and are brought into these empty frames. The reference to page 2 is replaced by page 7 because 7 ius used least recently among 7, 0 ,1. and so on..


Comments

Popular posts from this blog

Process Scheduling And Types of Process Schedular :-

        ⇰ PROCESS SCHEDULING Process Scheduling  is a task  of Operating System that schedules processes of different states like new, ready, waiting, terminated  and running.This scheduling helps in allocation of CPU time for each process, and Operating System allocates the CPU time for each procss. And the process scheduling plays important role to keep the CPU busy all the time.  ⏩   Followings are some objectives of Process Scheduling :-  i > To increase the amount of users within acceptable response times.  ii > To maintain the balance between response and utilization of system. iii > To decrease the enforce priorities and  give reference to the processes holding the key resources.      ⇰  PROCESS SCHEDULAR A scheduler carries out the pro cess scheduling work. Schedulers are often implemented so they keep all computer resources busy and  allows multiple users to shar...

Process & Its state And process control block :-

                ⇰  PROCESS :- A process can be thought of as a program in execution. Means when any program is executed it becomes process. A processwill need certain resources such as CPU time , memory, files and I/O devices to complete its task. These resources are allocated to the process either when it is created or at the time of execution.             A process is the unit of work in most systems. A system consistes of a collection of processes. All these processes may execute concurrently. Traditionally a process contained only a single thread. Most modern operating ststems now supports processes that have multiple threads.         The operating system is responsible for several important works of process management as - the creation and deletion of process, the schrduling of process, communication and deadlock handling of process. Process is broudly divided into two ...

Logical VS Physical Address Space In Operating System

Basically an address generated by the CPU is commonly referred  as a logical address, whereas an address seen by the memory unit is commonly referred as a physical address.The compile-time and load-time address-binding methods generate identical logical and physical addresses. However, the execution-time address binding scheme results in differing logical and physical addresses. In this case, we usually refer to the logical address as a virtual address. The set of all logical addresses generated by a program is a logical address space. The set of all physical addresses corresponding to these logical addresses is a physical address space. Thus, in the execution-time address-binding scheme, the logical and physical address spaces differ. The run-time mapping from virtual to physical addresses is done by a hardware device called the memory-management unit (MMU). The user program generates only logical addresses and thinks tha...