REPLACEMENT ALGORITHMS
COMPUTER ORGANIZATION
TEAM
A LAXMIKANTH - 22071A05C9
A SAHIL - 22071A05D0
B NIHANTH - 22071A05D7
P RAKESH - 22071A05H2
Introduction
•Replacement algorithms are used in
computer organization to determine
which data to remove from a cache or
memory when space is needed.
•These algorithms aim to minimize
cache misses and optimize memory
usage.
•Common replacement algorithms
include LRU (Least Recently Used), FIFO
(First In, First Out), and LFU (Least
Frequently Used).
The Need for Replacement Algorithms
• As computer systems grow more complex, with larger memory and storage
requirements, the need for efficient memory management becomes crucial.
Replacement algorithms play a vital role in optimizing the use of available
memory resources. These algorithms determine which pages or blocks of data
should be removed from memory when new data needs to be loaded, ensuring
the system can continue to function smoothly without running out of memory.
• Without a replacement algorithm, a computer system would quickly become
overwhelmed, unable to handle the constant demand for new data.
Replacement algorithms provide a structured approach to managing memory,
allowing the system to make informed decisions about which data to keep and
which to discard. This enables the computer to maintain optimal performance
and responsiveness, even under heavy workloads.
Types Of Page Replacement
A FIFO (First in First Out) Page Replacement
B Optimal Page Replacement
C LRU (Least Recently Used) Page Replacement
FIFO (First-In, First-Out)
Algorithm
The FIFO (First-In, First-Out) algorithm is a simple and straightforward
replacement algorithm used in memory management. When a new
page needs to be brought into memory, FIFO allocates a new page
frame to the oldest page, evicting the page that has been in memory
the longest. The pages are managed in a queue, with the newest page
added to the end. This ensures that the oldest page is always the first
one to be replaced when memory is full.
EXAMPLE
Optimal Replacement Algorithm
• In operating systems, whenever a new page is referred and not
present in memory, page fault occurs and Operating System
replaces one of the existing pages with newly needed page.
• Different page replacement algorithms
suggest different ways to decide which
page to replace. The target for all
algorithms is to reduce number of page
faults. In this algorithm, OS replaces the
page that will not be used for the longest
period of time in future.
EXAMPLE
1.If referred page is already present, increment hit count.
2.If not present, find if a page that is never referenced in future. If
such a page exists, replace this page with new page. If no such
page exists, find a page that is referenced farthest in future.
Replace this page with new page.
LRU (Least Recently Used)
Algorithm
• LRU replaces the data that has not been accessed for the longest
time.
• It is effective in removing the least useful data and reducing cache
misses.
• Implementing LRU can be more complex and require additional
hardware support.
• LFU replaces the data that has been accessed the
least number of times.
• It can be useful in scenarios where access frequency
matters more than recency.
• However, LFU may struggle in handling sudden
changes in access patterns.
EXAMPLE
Choosing the Right
Algorithm
Consider Performance Understand Workload Weigh Implementation
Goals Characteristics Complexity
Evaluate your specific
performance requirements, Analyze the access patterns Factor in the computational
such as minimizing page of your memory references. overhead and
faults, maximizing hit rates, Certain algorithms like LRU implementation complexity
or ensuring fairness. perform better for of each algorithm. Simpler
Different replacement applications with high algorithms like FIFO may be
algorithms excel in different temporal locality, while easier to implement, while
areas, so choose one that others like LFU are more more sophisticated ones
aligns with your key suitable for workloads with like Second Chance require
objectives. distinct access frequencies. additional bookkeeping and
maintenance.
THANK
YOU