0% found this document useful (0 votes)
49 views

Page Replacement Algorithms

Uploaded by

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

Page Replacement Algorithms

Uploaded by

saumyas0209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Page Replacement Algorithms

What is Page Replacement?

• In a computer's memory management, page replacement


algorithms are used to decide which page to remove from the main
memory (RAM) when a new page needs to be brought in.

• This is crucial because RAM is limited, and efficient page


replacement can significantly impact system performance.
Key Terms

• Page Fault: Occurs when a required page is not in memory.

• Reference String: A sequence of pages requested by a process.

• Frame: A fixed-size block in memory allocated to hold pages.

• Arrival Time: Tracks when a page was last accessed to determine

the least recently used page.


FIFO (First-In-First-Out) Page Replacement
FIFO (First-In-First-Out) Page Replacement

• FIFO is a simple page replacement algorithm where the oldest page


(the one that has been in memory the longest) is replaced.

• It's like a queue: the first page to arrive is the first one to leave.
Steps:
1. Start with an empty memory (frames).

2. Add pages from the reference string.

3. If a page is already in memory, no replacement occurs.

4. If the memory is full, replace the oldest page (FIFO rule).

5. Track the number of page faults for performance evaluation.


1. WAP in C to implement the FIFO (First-In-First-Out) Page Replacement
Algorithm.

Input : Enter the number of frames: 3


Enter the size of reference string : 8
Enter the reference string : 7 0 1 2 0 3 0 4

Output : Frames after each page request:


7
70
701
012
012
123
123
234
No of page faults: 6
LRU (Least Recently Used) Page Replacement
LRU (Least Recently Used) Page Replacement

• LRU is a page replacement algorithm that replaces the page that


has not been used for the longest period of time in memory.
Steps:
1. Initialization

2. Page Found: If the page is already in memory, update its arrival time.

3. Page Not Found:


1. If there’s space in memory, load the page into an empty frame.

2. If memory is full, find and replace the least recently used page.

4. Least Recently Used: Determined by the minimum arrival time.

5. Display Frames: Prints the current state of memory after each reference.
2. WAP in C to implement the Least Recently Used (LRU) Page Replacement
Algorithm.

Input : Enter the number of frames: 3


Enter the size of reference string : 7
Enter the reference string : 1, 2, 3, 1, 4, 3, 5

Output : Frames after each page request:


1
12
123
123
423
423
523
No of page faults: 5

You might also like