Monday, June 24, 2013
- Paging is used by most of the computer operating systems for the purpose of virtual memory management.
- Whenever a page fault occurs, some pages are swapped in and swapped out. Who decides which pages are to be replaced and how?
- This purpose is served by the page replacement algorithms.
- Page replacement algorithms only decide which pages are to be page out or written to the disk when a page of the memory has to be allocated.
- Paging takes place only upon the occurrence of a page fault.
- In such situations a free cannot suffice because either one is not available or because the number of available pages is less than threshold.
- If a previously paged out page is reference again, then it has to be read in from the disk again.
- But for doing this, the operating system has to wait for the completion of the input/ output operation.
- The quality of a page replacement algorithm is denoted by the time it takes for a page in.
- The lesser it is, the better the algorithm is.
- The information about the access to page as provided by the hardware is studied by the page replacement algorithm and then it decides which pages should be replaced so that the number of page faults can be minimized.
In this article we shall see about some of the page replacement algorithms.
FIFO (first – in, first – out):
- This one being the simplest of all the page replacement algorithms has the lowest overhead and works by book – keeping in place of the OS.
- All pages are stored in a queue in the memory by the operating system.
- The ones that have recently arrived are kept at the back while the old ones stand at the front end of the queue.
- While making replacement, the oldest page is selected and replaced.
- Even though this replacement algorithm is cheap as well as intuitive, practically it does not perform well.
- Therefore, it is rarely used in its original form.
- VAX/ VMS operating systems make use of the FIFO replacement algorithm after making some modifications.
- If a limited number of entries are skipped you get a partial second chance.
Least recently used (LRU):
- This replacement algorithm bears resemblance in name with the NRU.
- However, difference is there which is that this algorithm follows that the page usage is tracked for a certain period of time.
- It is based on the idea that the pages being used many times in current set of instructions will be used heavily in the next set of the instructions also.
- Near optimal performance is provided by LRU algorithm in the theory however in practical it is quite expensive to be implemented.
- For reducing the costs of the implementation of this algorithm, few implementation methods have been devised.
- Out of these the linked list method proves to be the costliest.
- This algorithm is so expensive because it involves moving the items about the memory which is indeed a very time consuming task.
- There is another method that requires hardware support.
Optimal page replacement algorithm:
- This is also known as the clairvoyant replacement algorithm.
- The page that has to be swapped in, it is placed in place of the page which according to the operating system will be used in future after a very long time. - In practical, this algorithm is impossible to be implemented in case of the general purpose OS because approximate time when a page will be used is difficult to be predicted.