0% found this document useful (0 votes)
34 views5 pages

Page Replacement Algorithm Overview

The document discusses various page replacement algorithms including First In First Out (FIFO), Optimal Page Replacement, Least Recently Used (LRU), and Most Recently Used (MRU), outlining their advantages and disadvantages. FIFO is simple but can lead to Belady's anomaly, while LRU and Optimal algorithms provide better performance by considering usage patterns. Each algorithm has its own strengths and weaknesses, making them suitable for different scenarios in memory management.

Uploaded by

Sanskriti Gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

Page Replacement Algorithm Overview

The document discusses various page replacement algorithms including First In First Out (FIFO), Optimal Page Replacement, Least Recently Used (LRU), and Most Recently Used (MRU), outlining their advantages and disadvantages. FIFO is simple but can lead to Belady's anomaly, while LRU and Optimal algorithms provide better performance by considering usage patterns. Each algorithm has its own strengths and weaknesses, making them suitable for different scenarios in memory management.

Uploaded by

Sanskriti Gupta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Page Replacement Algorithms

1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this algorithm, the
operating system keeps track of all pages in the memory in a queue, the oldest page is in the front of
the queue. When a page needs to be replaced page in the front of the queue is selected for removal.

Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page frames.

Find the number of page faults.

Belady’s anomaly proves that it is possible to have more page faults when increasing the number of
page frames while using the First in First Out (FIFO) page replacement algorithm. For example, if we
consider reference strings 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4, and 3 slots, we get 9 total page faults, but if
we increase slots to 4, we get 10-page faults.

2. Optimal Page replacement: In this algorithm, pages are replaced which would not be used for the
longest duration of time in the future.

Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frame. Find


number of page fault.
3. Least Recently Used: In this algorithm, page will be replaced which is least recently used.

Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frames.


Find number of page faults.

4. Most Recently Used (MRU): In this algorithm, page will be replaced which has been used recently.

Advantages and Disadvantages of various Page Replacement algorithms

First In First Out (FIFO):

Advantages –

It is simple and easy to understand & implement.

It is efficiently used for small systems

It does not cause more overheads


Simplicity: FIFO is a simple and easy-to-implement algorithm. It does not require complex data
structures or sophisticated calculations.

Fairness: FIFO algorithm is fair in the sense that all pages have an equal chance of being replaced.
The oldest page is replaced first, regardless of its usage frequency or importance.

No starvation: The FIFO algorithm does not suffer from starvation, which means that a page will
eventually be replaced if it has been in memory for a long time, even if it is frequently used.

Predictability: The FIFO algorithm is predictable in the sense that the order in which pages are
replaced is deterministic and does not depend on the page usage patterns or history.

Low overhead: FIFO requires minimal overhead because it only needs to maintain a simple queue of
pages in memory, making it a good choice for systems with limited resources.

Disadvantages –

The process effectiveness is low.

When we increase the number of frames while using FIFO, we are giving more memory to processes.
So, page fault should decrease, but here the page faults are increasing. This problem is called as
Belady’s Anomaly.

Every frame needs to be taken account off.

It uses an additional data structure.

Poor performance: FIFO may not provide optimal performance because it does not take into account
the usage patterns or importance of the pages. It may result in frequent page faults and unnecessary
disk I/O operations, especially if the workload is complex or memory demands are high.

Inefficient use of memory: FIFO can lead to inefficient use of memory because it replaces the oldest
page, regardless of its usage frequency or importance. As a result, some pages that are rarely used or
not important may occupy memory for a long time, while other more critical pages may be swapped
out frequently.

Susceptibility to thrashing: FIFO may be susceptible to thrashing, which occurs when the system
spends a significant amount of time swapping pages in and out of memory without making progress
on the actual workload. This happens when the number of pages needed by the workload exceeds
the available physical memory, and the FIFO algorithm does not efficiently manage the page
swapping.

Unfairness: Although FIFO is fair in the sense that it treats all pages equally, it may not be fair from
the perspective of the workload or the user. Some pages may be more important than others, and
replacing them first can lead to degraded performance or even application crashes.

No consideration of future usage: FIFO does not consider the future usage of pages, which means
that it may replace a page that will be needed again soon, leading to increased page faults and
decreased performance.
2. Least Recently Used (LRU):

Advantages –

It is open for full analysis.

In this, we replace the page which is least recently used, thus free from Belady’s Anomaly.

Easy to choose page which has faulted and hasn’t been used for a long time.

Good performance: LRU is designed to replace the page that has not been accessed for the longest
time. It is considered a “smart” algorithm because it takes into account the usage history of pages,
and it can lead to fewer page faults and faster application response times.

Efficient use of memory: LRU leads to efficient use of memory because it replaces the page that has
not been used for the longest time. This means that pages that are rarely used or not important are
more likely to be swapped out, freeing up memory for more critical pages.

No thrashing: LRU is less susceptible to thrashing compared to FIFO because it considers the usage
history of pages. It can detect which pages are being used frequently and prioritize them for memory
allocation, reducing the number of page faults and disk I/O operations.

Fairness: LRU is considered a fair algorithm because it takes into account the usage history of pages
and replaces the least recently used page first. This means that pages that are rarely used or not
important are more likely to be swapped out, making room for more frequently used pages.

Good balance between complexity and performance: LRU is more complex than FIFO, but it is still
relatively simple and easy to implement compared to other algorithms like optimal page
replacement. It strikes a good balance between complexity and performance, making it a popular
choice for many operating systems.

Disadvantages –

It requires additional Data Structure to be implemented.

Hardware assistance is high.

In LRU error detection is difficult as compared to other algorithms.

It has limited acceptability.

LRU are very costly to operate.

3. Optimal Page Replacement (OPR):

Advantages –

Complexity is less and easy to implement.

Assistance needed is low i.e Data Structure used are easy and light.
Optimal performance: The optimal page replacement algorithm is designed to replace the page that
will not be used for the longest time in the future. It provides the best possible performance because
it minimizes the number of page faults and maximizes the number of hits.

Efficient use of memory: Optimal page replacement leads to efficient use of memory because it
replaces the page that will not be used for the longest time in the future. This means that pages that
are rarely used or not important are more likely to be swapped out, freeing up memory for more
critical pages.

No thrashing: Optimal page replacement is less susceptible to thrashing compared to FIFO or LRU
because it considers the future usage of pages. It can detect which pages are being used frequently
and which pages are likely to be used in the future, prioritizing them for memory allocation and
reducing the number of page faults and disk I/O operations.

Fairness: Optimal page replacement is considered a fair algorithm because it takes into account the
future usage of pages and replaces the page that will not be used for the longest time in the future.
This means that pages that are rarely used or not important are more likely to be swapped out,
making room for more frequently used or critical pages.

Ideal for analysis and simulation: Optimal page replacement is ideal for analysis and simulation
because it provides an upper bound on the performance of other page replacement algorithms. It
can be used to compare the performance of other algorithms and evaluate their effectiveness.

Disadvantages –

It is not possible in practice as the operating system cannot know future requests.

Error handling is tough.

While FIFO and LRU have their share of advantages and disadvantages, OPR is used as a benchmark
to measure the performance of other algorithms. So according to the situation appropriate algorithm
is used.

Common questions

Powered by AI

Thrashing occurs when a system spends excessive time swapping pages due to high memory demand relative to available physical memory. FIFO is susceptible to thrashing because it indiscriminate replaces the oldest page, potentially leading to frequent page faults . LRU mitigates thrashing by prioritizing pages with recent use patterns, thus reducing unnecessary page swaps . Optimal replacement minimizes thrashing by predicting future page requirements, but it's impractical for real-time environments since future usage cannot be known .

FIFO replaces the oldest page in memory, operating on a simple queue structure, without considering the page's recent usage, leading to possible Belady’s anomaly . LRU, on the other hand, replaces the page that has not been used for the longest duration based on the recent usage history, minimizing page faults and reducing susceptibility to thrashing . The Optimal page replacement replaces the page that will not be used for the longest duration in the future, offering minimal page faults and optimal memory utilization, though impractical because future requests are unknown .

LRU addresses the shortcomings of FIFO by taking into account the usage history of pages and replacing the least recently used page, which reduces the number of page faults and avoids Belady’s anomaly. This leads to improved memory efficiency and minimizes thrashing compared to FIFO, which indiscriminately removes the oldest page .

LRU strikes a balance between complexity and performance by offering improved page fault rates without the impractical requirements of predicting future accesses, as seen with the Optimal algorithm. It uses recent usage history to efficiently utilize memory, handling complex workloads better than FIFO, while still being implementable with moderate complexity compared to even more complicated algorithms .

The MRU algorithm diverges from LRU by replacing the most recently used page instead of the least recently used. This counterintuitive approach can be beneficial in specific scenarios where frequently accessed pages are likely to be re-accessed fairly soon, but it can also lead to increased page faults if the recently used pages are needed again shortly after replacement, highlighting its limited general applicability compared to LRU .

FIFO might be preferred over LRU in scenarios with constrained computational resources or simpler system requirements, where the simplicity and low overhead of the FIFO algorithm outweigh the benefits of potentially fewer page faults from LRU. It is also suitable in systems where predictability is more critical than performance optimization, as its deterministic operation avoids the complexity of LRU's page tracking .

The Optimal page replacement algorithm is considered impractical because it requires knowledge of future page requests to determine which page will not be needed for the longest time, a requirement that cannot be met in real-world scenarios where future access patterns are unknown .

Belady’s anomaly in the FIFO algorithm occurs when increasing the number of page frames results in more page faults, contrary to the expectation that more memory should reduce page faults. This anomaly typically occurs when the page reference string is such that newer frames fill memory, displacing ones that will be needed soon, illustrated by the reference string example which shows an increase from 9 to 10 page faults when frames increase from 3 to 4 .

FIFO's simplicity, minimal overhead, and predictability align with its intended use for small-scale systems that do not require complex page management due to possibly lower memory demands and reduced variability in workload. Its simple queue management provides a straightforward implementation without the overhead of tracking page histories or complex decision-making processes .

Predictability in FIFO ensures deterministic page replacement regardless of usage patterns, which is crucial for applications with stable, routine memory usage that benefit from knowing exactly when and how pages will be replaced. This can optimize system performance where memory requirements do not vary unpredictably, though it may result in inefficiencies where page usage is irregular .

You might also like