Replacement Algorithms In Minimizing Page Faults Computer Science Essay

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

MUNMUN GHOSH

BHARAT ELECTRONICS LIMITED

M.Tech Scholar

Abstract: A number of page replacement algorithms are explored in this paper. In a computer system the virtual memory involves the separation of user’s logical memory from physical memory. This separation allows programmers to have a logical address space that is much larger the available physical address space. Implementation of the virtual memory is commonly done by using the concept of paging and determines which is the most optimal. A number of page replacement algorithms are used to decide which memory pages to swap out when a memory page needs to be allocated. This paper evaluates the performances of various page replacement algorithms used in order to reduce page faults and help in efficient memory management and determines which is the most optimal.

INTRODUCTION

In a computer system the virtual memory involves the separation of user’s logical memory from physical memory. This separation allows programmers to have a logical address space that is much larger than the available physical address space using a combination of various software and hardware components. Implementation of the virtual memory is commonly done by using the concept of paging. It involves dividing the physical memory into fixed-sized blocks called frames and breaking logical memory into same-sized blocks called pages. As the virtual memory is generally larger in size than the available physical memory space therefore only a subset of the virtual pages are mapped onto the physical memory rest being stored in the available secondary memory.

To run a program of size ‘n’ pages, the requirement arises to find ‘n’ free frames, so that the program can be loaded for execution. If a process makes a reference to a page that is unmapped, the first reference will cause the CPU to trap to the operating system and a page fault occurs.

Sometimes referred as #pf or pf a page fault is basically a trap to the software which is raised by the hardware when a process tries to access a page that is not loaded in the main memory but mapped in the virtual memory. In order to handle this page fault the operating system tries to make the required page available at a particular location in the physical memory or kills the program in case of an illegal access. The operating system fetches the page just referenced into a freely available frame before restarting the trapped instruction. The hardware device that maps virtual to physical address is the memory management unit.

A number of page replacement algorithms are used to decide which memory pages to swap out when a memory page needs to be allocated. A free page simply cannot be used to satisfy the allocation, either because there are none or because the numbers of available free pages are less than some threshold. This paper evaluates the performances of various page replacement algorithms used in order to reduce page faults and help in efficient memory management.

Page Replacement Algorithms

Assuming a normal page table, when a process requires a page that is not in the main memory then a page fault occurs. The page replacement algorithm which is used selects a page from among the available pages of user program’s virtual address space. The algorithm removes the page from the frame. If the page has been modified, it must be written back to disk by using dirty bit concept. The aim of page replacement is to reduce the total waiting time for memory, taking into accounts memory requirements. The most commonly used page replacement algorithms are discussed below.

Algorithms can be local or global.

A replacement algorithm can be global or local. When a process has to deal with a page fault, a local replacement algorithm will select a page that either belongs to the same process or a group of processes sharing a partition of memory which enhances scalability, whereas global replacement algorithm can select a page from anywhere in memory.

First In First Out (FIFO)

It is the simplest among all the replacement algorithms. The pages in memory are kept in a linked list, with the earlier arrived ones in front whereas recently arrived ones at the end of list. When a replacement is required, the page that has been in the memory for the longest time is selected for replacement. FIFO is cheap, intuitive and its implementation is fast and easier but performs poorly in practical applications. FIFO faces Belady’s anomaly. As the number of frames increases the page fault also increases. It has to face a disadvantage i.e., some pages may be important and the oldest ones may be required soon but replacing may cause an immediate page fault.

Second Chance Page Replacement Algorithm

It is a modification done to FIFO, where the pages are paced in a linked list having the oldest ones at the front. If the referenced bit of an oldest page is 0, then it is selected for replacement else it was used recently. So if don’t want its replacement its referenced bit is cleared and the page is moved at the end of the list. Eventually we get back to this page and if its reference bit is zero, we select it for replacement.

It works by looking at the front of the queue as FIFO does, but instead of immediately paging out that page, it checks to see if its referenced bit is set. If it is not set, the page is swapped out. Otherwise, the referenced bit is cleared, the page is inserted at the back of the queue (as if it was a new page) and this process is repeated. This can also be thought of as a circular queue. If all the pages have their referenced bit set, on the second encounter of the first page in the list, that page will be swapped out, as it now has its referenced bit cleared. If all the pages have their reference bit set then second chance algorithm degenerates into pure FIFO. As the name indicates, Second-Chance algorithm gives every page a second-chance

Clock Page Replacement Algorithm

This algorithm is a more efficient version of FIFO than the previous algorithm as the pages are not required to be pushed back constantly at the end of the list but performs the same basic functions as Second-Chance. This algorithm keeps a circular list of pages in memory along with the iterator pointing to the last examined page frame in the list. On occurrence of a page fault when no more empty frames exist, then the reference bit is examined at the iterator location. If the bit is 0, a new page is put in position of the page at the iterator location otherwise the bit is cleared. The clock is afterwards incremented and the process is repeated until a page gets replaced.

Least Recently Used (LRU)

This algorithm keeps a track of pages used over a short period of time. It uses the idea that the pages which have been used most heavily in the past instructions are most likely to be used heavily in the next coming instructions as well. Although it can provide performance near to optimal, its implementation is expensive in practical situation. This algorithm keeps track of the time when a page is used and replaces the page that has been used least recently. A link list of all the pages is kept, on each memory reference the page is moved to the beginning of the list. The page at the end of the list is replaced. This implementation is very expensive as items in the list will have to be moved with every memory reference, which is really time-consuming. The memory management unit maintains a counter which incremented with every clock cycle, each time a page table entry is used the MMU writes the value to the entry "Timestamp". On occurrence of fault software looks through the table and identifies the entry with the oldest timestamp. LRU is advantageous as it is amenable to full statistical analysis. It has a disadvantage as well i.e. its performance degrades under many quite common reference patterns.

Not Frequently Used

A counter is associated with each page. On every interrupt of the timer the OS looks at the reference bit of each page. If the bit is set the counter of that page is incremented and the bit is cleared. The page with the lowest counter is chosen for replacement. It keeps track of the page usage in the last clock interval. The implementation of this algorithm is not possible in general purpose operating system as it is difficult to compute when the next page will be needed. The OS keeps a track of all the pages referred by the program and uses the data for deciding which page to bring in the memory and which page to swap out.

Optimal Page Replacement Algorithm

This algorithm selects the page that will not be needed for the longest time. When a page needs to be swapped in, the operating system swaps out the page whose next use will occur farthest in the future. For example, a page that is not going to be used for the next 6 seconds will be swapped out over a page that is going to be used within the next 0.4 seconds.

Working Set Page Replacement

The set of pages expected to be used by that process during certain time interval constitutes its working set. If the working set of a process is already in memory then no page fault will occur.

The size of the working set:

k (the time interval)

Demand Paging

Pages are brought in the memory only when they are required. When a process starts, all pages are marked invalid.

Performance Evaluation of Various Page Replacement Algorithms

The FIFO may throw out some important pages. Although Second-Chance and Clock replacement algorithms are a great improvement over FIFO, Clock algorithm is more realistic. LRU although it is difficult to implement exactly, is excellent. NFU is fairly a crude approximation to LRU. Optimal page replacement algorithm though it is not implementable but it is useful as a benchmark for other algorithms. The working set page replacement algorithm has an expensive implementation.

CONCLUSION

In this paper, some of the major page replacement algorithms are discussed. The performances of these algorithms are also evaluated. Based on performance it has been seen that the optimal algorithm give less page faults. Although it is not implemented in practice it is used as a benchmark for other algorithms and helps in efficient memory management.



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now