Table of Contents
Share this Resource

What is Page Replacement Algorithms in Operating Systems?

What’s In This Blog?

1. Understand how Page Replacement Algorithms help manage limited physical memory efficiently.
2. Learn why page replacement is needed when no free memory frames are available.
3. Explore how different algorithms decide which page should be removed from memory.
4) Compare FIFO, Optimal, LRU, LFU, MFU, MRU, and Second Chance approaches.
5) Discover the key advantages and limitations of each Page Replacement Algorithm.

Ever questioned how your computer juggles multiple tasks without running out of memory? The answer lies in a complex process called Page Replacement Algorithms in Operating System (OS). When your system's memory fills up, it needs to decide what to keep and what to discard.

Understanding these algorithms is crucial for optimising system performance and preventing frustrating slowdowns. Let's dive into the world of memory management and explore how page replacement algorithms in OS keep your computer running smoothly.

What are Page Replacement Algorithms in Operating Systems?

Page Replacement Algorithms in Operating Systems are memory management methods used to determine which page should be removed from physical memory when a new page needs to be loaded and no free frame is available.

Page Replacement Algorithms in Operating Systems

When a process requests a page that is not currently present in physical memory, a page fault occurs. If all available frames are occupied, the Operating System selects an existing page as the victim page, removes or replaces it as required, and loads the requested page into the available frame.

Computer Science Course

Why are Page Replacement Algorithms Needed?

Page Replacement Algorithms are necessary because physical memory has limited capacity. A system may run several processes simultaneously, while each process can require multiple pages of memory.

When all available frames are occupied, the Operating System needs a systematic way to decide which page should be replaced.

Some important reasons for using Page Replacement Algorithms include:

a) Efficient Memory Usage: They help the Operating System make effective use of available physical memory.

b) Managing Page Faults: Selecting appropriate pages for replacement can help reduce unnecessary page faults.

c) Supporting Virtual Memory: Page replacement enables systems to execute processes whose virtual address spaces may exceed available physical memory.

d) Improving Performance: Efficient replacement decisions can reduce unnecessary disk or storage access caused by repeated page faults.

e) Managing Multiple Processes: They help distribute limited memory resources while several processes are running concurrently<

Types of Page Replacement Algorithms

Different Page Replacement Algorithms use different criteria to select a victim page. Some consider how long a page has remained in memory, while others examine recent or frequent page usage.

Different types of Page Replacement Algorithms

The major Page Replacement Algorithms are discussed below.

1) FIFO Page Replacement Algorithm

The First In First Out (FIFO) Page Replacement Algorithm replaces the page that has been present in memory for the longest time.

Pages are maintained according to the order in which they entered memory. When another page needs to be loaded and no free frame is available, the oldest page is removed first.

For example, if pages A, B, and C entered memory in that order, page A would normally be selected first when a replacement is required.

Advantages:

1) Simple to understand and implement

2) Requires relatively little tracking

3) Uses a straightforward queue-based approach

Disadvantages:

1) Does not consider how frequently or recently a page is used

2) May remove an actively used page

3) Can experience Belady's Anomaly, where increasing the number of frames can sometimes result in more page faults

2) Optimal Page Replacement Algorithm

The Optimal Page Replacement Algorithm, also called OPT or MIN, replaces the page whose next use is farthest in the future.

If a page will not be required again for a long time, replacing it gives the system more time before that page causes another fault. As a result, Optimal replacement produces the minimum possible number of page faults for a given reference string and fixed number of frames.

However, an Operating System generally cannot know future memory references in advance. Therefore, Optimal Page Replacement is mainly used as a theoretical benchmark for evaluating other algorithms.

Advantages:

1) Produces the minimum possible page faults for a known reference sequence

2) Useful for comparing the performance of other algorithms

3) Provides a theoretical performance benchmark

Disadvantages:

1) Requires knowledge of future page references

2) Cannot generally be implemented as an online replacement policy in real systems

Elevate your programming expertise with our C++ Programming Course and gain advanced skills.

3) LRU Page Replacement Algorithm

The Least Recently Used (LRU) Page Replacement Algorithm replaces the page that has not been accessed for the longest period.

LRU is based on the principle of temporal locality, where pages used recently are considered more likely to be used again soon than pages that have not been accessed for some time.

For example, if pages A, B, and C are stored in memory and page B was accessed least recently, B would be selected for replacement.

LRU often performs well because it considers actual usage history. However, implementing exact LRU can require considerable tracking. Practical systems may therefore use hardware-supported reference information or approximations to LRU.

Advantages:

1) Uses recent page-access behaviour

2) Usually makes more informed decisions than FIFO

3) Does not suffer from Belady's Anomaly because LRU is a stack algorithm

Disadvantages:

1) Exact implementation can require additional hardware or bookkeeping

2) Tracking every memory reference can create overhead

Trainer's Tip

When solving LRU problems manually, record the most recent use of every page after each reference. This helps prevent mistakes when choosing the least recently accessed page.

4) LFU Page Replacement Algorithm

The Least Frequently Used (LFU) Page Replacement Algorithm replaces the page with the lowest access count.

Each page is associated with a counter that records how often it has been referenced. When replacement becomes necessary, the page with the smallest reference count is selected.

LFU assumes that pages used frequently in the past are more likely to remain useful.

However, an old page that was accessed heavily earlier can retain a high count even if it is no longer actively required. Techniques such as ageing can be used to reduce the influence of old references.

Advantages:

1) Takes page-access frequency into account

2) Can preserve frequently referenced pages

3) May perform well when access frequencies remain relatively stable

Disadvantages:

1) Requires maintaining reference counters

2) Older historical usage can distort replacement decisions

3) Requires a tie-breaking method when multiple pages have equal counts

5) MFU Page Replacement Algorithm

The Most Frequently Used (MFU) Page Replacement Algorithm takes the opposite approach to LFU. It replaces the page with the highest reference count.

MFU is based on the assumption that a page with a low reference count may have only recently entered memory and could therefore be required again soon. A page with a high count may have already completed much of its useful activity.

For example, if three pages have reference counts of 2, 5, and 8, MFU would normally select the page with a count of 8.

Advantages:

1) Considers page-reference frequency

2) Can be useful for certain specialised access patterns

3) Provides an alternative to LFU when newly loaded pages need protection

Disadvantages:

1) Frequently used pages may still be important and needed again

2) Requires maintaining reference counters

3) Usually requires a tie-breaking mechanism

6) MRU Page Replacement Algorithm

The Most Recently Used (MRU) Page Replacement Algorithm replaces the page that was accessed most recently.

This approach is effectively the opposite of LRU. MRU assumes that, for certain access patterns, the most recently used page may not be required again immediately.

MRU can be useful in some sequential or cyclic access workloads, particularly where retaining older pages provides better reuse opportunities. However, it is less suitable when recently accessed pages are likely to be referenced again soon.

Advantages:

1) Can perform well for particular sequential or cyclic access patterns

2) Uses recent page-access information

3) Relatively easy to understand conceptually

Disadvantages:

1) Performs poorly when recently used pages are likely to be reused soon

2) Less widely applicable than LRU

3) Requires tracking recent page usage

7) Second Chance Page Replacement Algorithm

The Second Chance Page Replacement Algorithm is an enhancement of FIFO that prevents recently referenced pages from being immediately replaced.

Pages are arranged in FIFO order, but each page also has a reference bit. When the algorithm examines the oldest page:

1) If its reference bit is 0, the page can be replaced.

2) If its reference bit is 1, the bit is cleared and the page is given another chance while the search continues.

A common implementation uses a circular queue and is often called the Clock Algorithm.

Second Chance improves basic FIFO by considering whether a page has been used recently.

Advantages:

1) Usually makes better replacement decisions than basic FIFO

2) Requires less overhead than exact LRU

3) Protects recently referenced pages from immediate replacement

Disadvantages:

1) Does not maintain an exact order of recent usage

2) May require examining several pages before finding a victim

3) Performance depends on memory-access patterns

Unlock your potential in programming with our C Programming Course - Join now!

Quick Assessment

Test your understanding before you finish:

1. What is the purpose of a Page Replacement Algorithm? 
2. Which algorithm replaces the page that entered memory first? 
3. Why is the Optimal Page Replacement Algorithm mainly used as a benchmark? 
4. How does LRU decide which page to replace? 
5. What happens when a required page is not currently available in physical memory? 
6. Why can frequent page faults reduce system performance?
Nilotpal Sarmah
Nilotpal Sarmah

Senior Content Writer

Nilotpal Sarmah is a Senior Content Writer with 11+ years of overall experience spanning engineering, operations and content development. His technical knowledge and extensive writing experience enable him to simplify specialised topics across IT and Tech, Business Skills, Project Management, Health and Safety, and ISO and Compliance.

View Detail icon
cross

Upgrade Your Skills. Save More Today.

superSale Unlock up to 40% off today!

* WHO WILL BE FUNDING THE COURSE?

close

close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.

close

close

Press esc to close

close close

Back to course information

Thank you for your enquiry!

One of our training experts will be in touch shortly to go overy your training requirements.

close close

Thank you for your enquiry!

One of our training experts will be in touch shortly to go over your training requirements.