Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
When the processor needs to execute a particular page, which is not available in the main memory, this is a page fault. The page replacement is required When a page fault happens. Page replacement means selecting a victim page in the main memory and replacing that page with the required page from the backing store(disk). The page replacement algorithm sets the victim page.
When an application tries to access data, that is a body of its functioning set, and it's not loading.
It can be either hard or soft.
Hard page faults happen when the page is located inside the page file on the hard disk.
Soft page faults occur when the page is found somewhere else in memory.
Preventions to reduce high page fault rate
One method to prevent page faults is using a memory allocator that knows about allocating memory and is utilized only on the same pages.
For example, at the application level, bucket allocators (example) permit an application to ask for a bunch of memory that the application will then allocate.
Page Replacement Algorithms
There are various page replacement algorithms, some of the popular page replacement algorithms are given below:
1. FIFO Page Replacement: The most straightforward page-replacement algorithm is a FIFO algorithm. A FIFO replacement algorithm connects with us to bring each page into memory.
For example , consider a reference string as : 7, 0, 1, 2, 0, 3, 0, 4,
2, 3, 0,3,2,1,2,0,1,7,0,1. Suppose we have three initially empty frames. For our example string, our three frames are empty initially.
The first three references cause page faults, i.e. (7, 0, 1); therefore, we put these into empty frames. The following reference (2) replaces page 7 because we bring page 7 first. Since 0 is the following reference, and 0 is already in memory, we do not consider fault for this reference.
7
0
1
2
0
3
0
4
2
3
0
3
2
1
2
0
1
7
0
1
7
7
7
2
2
2
4
4
4
0
0
0
7
7
7
0
0
0
3
3
3
2
2
2
1
1
1
0
0
1
1
1
1
0
0
3
3
3
2
2
2
1
To demonstrate the possible problems with a FIFO page replacement algorithm, we consider the string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. We notice that the number of faults for four frames (ten) is greater than for three frames (nine). This most unexpected result is Belady's anomaly: The page-fault rate may increase as the number of allocated frames increases for some page replacement algorithms. We would expect to give more memory to a process to improve its performance.
2. Optimal page-replacement algorithm: Optimal page-replacement algorithm: An optimal page replacement algorithm has the lowest page-fault rate of each algorithm and will never come under Belady's anomaly as well. Such an algorithm has been called OPT or MIN. It is simply this: if we do not use the page, we can replace it for the most extended period. This page-replacement algorithm ensures the lowest possible page-fault rate for a fixed number of frames.
For example, the optimal page replacement algorithm would yield nine-page faults on our sample reference string, as shown in the following figure. The first three references are responsible for faults covering the three vacant frames. Page 2 replaces page 7 because it will not be used until reference 18, whereas we can use page 0 at 5 and page 1 at 14. Page 3 returns to page 1 because page 1 will be the last of the three pages in memory to be referenced again. With only nine-page faults, optimal replacement is much better than a FIFO algorithm with 15 faults.
7
0
1
2
0
3
0
4
2
3
0
3
2
1
2
0
1
7
0
1
7
7
7
2
2
2
2
2
7
0
0
0
0
4
0
0
0
1
1
3
3
3
1
1
3. Least recently used Page replacement: If the optimal algorithm is not feasible, perhaps an approximation of the optimal algorithm is possible. LRU replacement associates the time of that page's last use with each page. When a page has to be replaced, LRU chooses the page that has not been utilized for the most prolonged period. For example, The LRU algorithm produces 12 faults. Notice that the first five faults are the same as an optimal replacement. When the reference to page 4 occurs, however, LRU replacement sees that, of the three frames in memory, page 2 was used least recently. Thus, the LRU algorithm replaces page 2, not knowing that page 2 will be used. When it faults for page 2, the LRU algorithm returns to page 3 since it is now the least recently used of the three pages in memory. Despite these problems, LRU replacement with 12 faults is still much better than FIFO replacement with 15 faults.
What happens when the page fault rate becomes too high or too low?
If the page fault rate is too high, it ensures that the process has too few frames allocated to it. Boundaries can be eradicated from the process if the page fault rate falls down the lower limit. Similarly, if the page fault rate surpasses the upper limit, more frames can be allocated to the process.
Which page replacement algorithm is best?
The Optimal Page Replacement algorithm is the best page replacement algorithm as it gives the least number of page faults.
What is the goal of the page replacement algorithms?
Page replacement algorithms are a vital part of virtual memory management. It supports the operating system to decide whether the memory page can be moved out or make space for that required page. However, the long-run objective of all page replacement algorithms is to reduce the number of page faults.
Conclusion
We learned about how page fault is handled, the main reasons for page faults, and the calculation.We also learned how to reduce a high page fault rate and different page Replacement algorithms. In FIFO Page Replacement, we came to know about Belady's anomaly. At last, we understood possible problems when the page fault rate becomes too high or too low, which page replacement algorithm is best, and the goal of the page replacement algorithms.