For working professionals
For fresh graduates
More
OS Tutorial: Learn Operating S…
1. Introduction to Operating System
2. Types of Operating Systems
3. Linux Operating System
4. An Introduction To Unix Operating System
5. Ubuntu Operating System
6. MS DOS Operating System
7. Mobile Operating System
8. Understanding Functions of Operating System
9. Components of Operating System
10. Understanding the Kernel in Operating Systems
11. Structure of Operating System
12. Process in Operating System
13. What is Bios
14. What is Booting in Computer
15. What is Interrupt in Operating System?
16. Process Control Block in Operating Systems
17. Threads in Operating System
18. Process Synchronization in OS
19. Critical Section in OS
20. Semaphore in Operating System
21. Deadlock in Operating System
22. Deadlock Prevention in OS
23. Paging in Operating System
24. Segmentation in Operating System
25. Virtual Memory in Operating System
26. File System in Operating Systems
27. Page Table in OS
28. Round Robin Scheduling in Operating System
29. Shortest Job First Scheduling Algorithm
30. Priority Scheduling in OS
31. Page Replacement Algorithms in Operating System
Now Reading
32. Race Condition in OS
33. Distributed Operating System
34. Navigating Contiguous Memory Allocation in Operating Systems
35. Fragmentation in Operating System
36. Banker’s Algorithm in OS
37. Context Switching in OS
38. First Come First Serve (FCFS) Scheduling Algorithm in Operating System
39. Understanding Inter Process Communication in OS
40. Multiprogramming Operating System
41. Python OS Module
42. Preemptive Priority Scheduling Algorithm
43. Resource Allocation Graph in OS
44. Scheduling Algorithms in OS
45. System Calls In Operating System
46. Thrashing in Operating Systems: A Deep Dive
47. Time Sharing Operating System
Understanding the process of page replacement in OS is extremely important for someone who manages various types of operating systems. An Operating System that uses demand paging requires a page replacement algorithm. The procedure of calling a page from the visual memory to the primary memory is called demand paging. But what next? How will you identify which page must be eliminated in the primary memory?
Worry not!
With my years of experience in this field, I will try my best to guide you with all my knowledge. Keep reading to understand better!
In my opinion, if you want to learn about page replacement algorithms in OS, you must first know about virtual memory. This is a secondary memory of a computer system that gives the impression to the user that there is more memory available to store data. Virtual memory can easily hold a large-sized program even though the primary memory can not hold it.
The Operating System usually avoids storing any sort of large process in the primary memory, instead, plenty of small processes are stored in primary memory. This procedure of using primary memory and virtual memory increases the consumption by the CPU and improves multi-programming. There are two main functions of virtual memory.
The first function of virtual memory is frame allocation. Whereas, the second function is page replacement. Now let's discuss and explain the page replacement algorithm to enhance your understanding.
A visual memory that uses demand paging requires the page replacement technique when there is a page fault. When there is a requirement to replace an existing page in the main memory with a new page from the visual memory, page replacement comes in to solve this problem.
It decides which page should be discarded so that the new demanding page can be accommodated in the primary memory. This process is also applicable for multiprogramming OSs.
You might be wondering why page replacement algorithms are important for your computer. So, allow me to explain their importance in detail. RAM, the primary memory of a computer does not have an extended memory like the visual memory therefore page faults often occur. In such a scenario the Operating system changes the old page with the new page with the assistance of the page replacement algorithm.
The page replacement algorithm also decides which page should be replaced with the new page and reduces the rate of page faults.
The optimal page replacement algorithm in OS has one of the lowest number of page faults. In this algorithm, the unused pages that have not been used for the longest periods are replaced with new pages. In this manner, almost all unused pages get replaced with time in the future.
Here are some optimal page replacement algorithms in OS examples you can study to get a better comprehension:
Let’s consider the page reference string as 7,0,1,2,0,3,0 with a main memory of three slots. Now I will help you calculate the number of page faults with the help of a table:
Sl No. | 7 | 0 | 1 | 2 | 0 | 3 | 0 |
F3 | 1 | 1 | 1 | 3 | 3 | ||
F2 | 0 | 0 | 0 | 0 | 0 | 0 | |
F1 | 7 | 7 | 7 | 2 | 2 | 2 | 2 |
Hit (H)/ Fault (M) | M | M | M | M | H | M | H |
Explanation: Here I have vividly explained the mentioned optimal page replacement algorithm example:
The next important page replacement algorithm is FIFO (First In First Out). In this algorithm, the oldest page is placed at the front end of the frame, whereas the latest page is placed at the back end or rear end. When there is any page fault the oldest page is removed from the front end and a new memory gets inserted at the back end.
Here’s an example:
Suppose the string variable to be 2,3,5,2,8,9,4,5 in five-page frames. Here are the tables below:
Sl No. | 2 | 3 | 5 | 2 | 8 | 9 | 4 | 5 |
F5 | 9 | 9 | 9 | |||||
F4 | 8 | 8 | 8 | 8 | ||||
F3 | 5 | 5 | 5 | 5 | 5 | 5 | ||
F2 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | |
F1 | 2 | 2 | 2 | 2 | 2 | 2 | 4 | 4 |
Hit (H)/ Fault (M) | M | M | M | H | M | M | M | H |
Explanation: Here is the complete explanation of the example of the FIFO algorithm:
The Least Recently Used (LRU) page replacement algorithm is the last page replacement in OS. According to this algorithm, a page that has been frequently used will be used in the future as well. Therefore, this algorithm replaces the new page in demand with an old page that has not been used for the longest period.
Let's say that the string variable is 7,0,1,2,0,3,0,4,2 in a 4-frame page.
Sl No | 7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 |
F4 | 2 | 2 | 2 | 2 | 2 | 2 | |||
F3 | 1 | 1 | 1 | 1 | 1 | 4 | 4 | ||
F2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
F1 | 7 | 7 | 7 | 7 | 7 | 3 | 3 | 3 | 3 |
Hit (H)/ Fault (M) | M | M | M | M | H | M | H | M | H |
Explanation: Here is the explanation of the above table:
As I have stated, different types of page replacement algorithms come with their advantages and disadvantages. The choice is up to you and your requirements.
If you are willing to commence a career in this field I would recommend you to pursue some online courses like the ones upGrad offers. These well-executed courses will not only enhance your knowledge but also expand your skills.
Page replacement in OS is a procedure where a page from the secondary memory is replaced with a page from the primary memory when any page fault occurs.
The best algorithm for page replacement is the Optimal page replacement algorithm. This is because it has the minimum amount of page faults.
The first come first out (FIFO) algorithm in OS replaces the oldest page at the front end with the latest page in demand.
The page replacement algorithm used by Mac OS is the First come first out (FIFO) algorithm.
Page replacement in OS is a procedure where a page from the secondary memory is replaced with a page from the primary memory. There are three types of page replacement: Optimal Page Replacement, First in first out (FIFO) Page Replacement, and Least Recently Used (LRU) Page Replacement.
The page replacement algorithm in OS is mainly used to decrease the frequency of page faults.
Least Recently Used (LRU) page replacement is the least used page replacement algorithm in OS.
Swapping is the basic step that is used in a page replacement algorithm.
Author
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.