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

PageReplacementAlgorithmsinComputerArchitecture-StudyGuide

Page replacement algorithms are essential for managing memory in operating systems using virtual memory, deciding which page to replace during a page fault. Common algorithms include FIFO, LRU, and OPT, each with different strategies for minimizing page faults. Key considerations for their effectiveness include locality of reference and the number of frames allocated to processes.

Uploaded by

venkatasai012345
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)
2 views

PageReplacementAlgorithmsinComputerArchitecture-StudyGuide

Page replacement algorithms are essential for managing memory in operating systems using virtual memory, deciding which page to replace during a page fault. Common algorithms include FIFO, LRU, and OPT, each with different strategies for minimizing page faults. Key considerations for their effectiveness include locality of reference and the number of frames allocated to processes.

Uploaded by

venkatasai012345
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/ 4

Page Replacement Algorithms

Introduction to Page Replacement


Page replacement algorithms are crucial in operating systems that use paging and virtual
memory management. Their primary function is to decide which page in memory should be
replaced when a new page needs to be loaded, and the memory is full.

The scenario:

CPU tries to access a page (let's say page 4).


Page 4 is not currently in memory.
This triggers a "page fault."

Page Fault
A page fault occurs when the CPU tries to access a page that is not present in the main memory.
In such cases, the operating system needs to:

1. Locate the required page in virtual memory (e.g., on the hard drive).
2. Find a page in main memory to replace.
3. Swap the page from virtual memory into main memory.
4. Update the page table to reflect the new page in memory.

If the required page is present in memory, this is not a page fault.

Page Replacement Algorithms: The Selection


Process
Page replacement algorithms determine which page to remove from memory to make space for
the new page. The goal is to minimize the number of page faults. Common algorithms include:

1. FIFO (First-In, First-Out)


2. LRU (Least Recently Used)
3. OPT (Optimal)

The selection of a page to be replaced is critical for performance. The chosen page is swapped
out (moved from main memory to secondary storage), and the requested page is swapped in
(moved from secondary storage to main memory).
Common Page Replacement Algorithms
FIFO (First-In, First-Out)
Concept: The oldest page in memory is replaced, regardless of how frequently it is being
used.
Mechanism: Pages are treated as if they are in a queue. The first page that entered the queue
is the first to be removed.

Example: Consider a reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 3 frames.

1. 7, 0, 1 (3 page faults)
2. 2 replaces 7: 2, 0, 1 (1 page fault)
3. 0 (No page fault)
4. 3 replaces 0: 2, 3, 1 (1 page fault)
5. 0 replaces 2: 0, 3, 1 (1 page fault)
6. 4 replaces 3: 0, 4, 1 (1 page fault)
7. 2 replaces 0: 2, 4, 1 (1 page fault)
8. 3 replaces 4: 2, 3, 1 (1 page fault)
9. 0 replaces 2: 0, 3, 1 (1 page fault)
10. 3 (No page fault)
11. 2 replaces 3: 0, 2, 1 (1 page fault)
12. 1 (No page fault)
13. 2 (No page fault)
14. 0 (No page fault)
15. 1 (No page fault)
16. 7 replaces 0: 7, 2, 1 (1 page fault)
17. 0 replaces 2: 7, 0, 1 (1 page fault)
18. 1 (No page fault)

Total page faults: 15

LRU (Least Recently Used)


Concept: Replaces the page that has not been used for the longest period.
Mechanism: Requires tracking when each page was last accessed.
Goal: Aims to remove pages that are least likely to be used in the near future.

Example: Using the same reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 3


frames.

1. 7, 0, 1 (3 page faults)
2. 2 replaces 7: 2, 0, 1 (1 page fault)
3. 0 (No page fault)
4. 3 replaces 1: 2, 0, 3 (1 page fault)
5. 0 (No page fault)
6. 4 replaces 2: 0, 4, 3 (1 page fault)
7. 2 replaces 0: 2, 4, 3 (1 page fault)
8. 3 (No page fault)
9. 0 replaces 4: 2, 0, 3 (1 page fault)
10. 3 (No page fault)
11. 2 (No page fault)
12. 1 replaces 0: 2, 1, 3 (1 page fault)
13. 2 (No page fault)
14. 0 replaces 3: 2, 1, 0 (1 page fault)
15. 1 (No page fault)
16. 7 replaces 2: 7, 1, 0 (1 page fault)
17. 0 (No page fault)
18. 1 (No page fault)

Total page faults: 12

OPT (Optimal)
Concept: Replaces the page that will not be used for the longest time in the future.
Mechanism: Requires knowledge of the entire future sequence of page requests.
Practicality: Not implementable in a real-time operating system because it's impossible to
predict the future. Used primarily for benchmarking other algorithms.

Example: Using the same reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 3


frames.

1. 7, 0, 1 (3 page faults)
2. 2 replaces 7: 2, 0, 1 (1 page fault)
3. 0 (No page fault)
4. 3 replaces 1: 2, 0, 3 (1 page fault)
5. 0 (No page fault)
6. 4 replaces 2: 0, 4, 3 (1 page fault)
7. 2 replaces 3: 0, 4, 2 (1 page fault)
8. 3 replaces 4: 0, 3, 2 (1 page fault)
9. 0 (No page fault)
10. 3 (No page fault)
11. 2 (No page fault)
12. 1 replaces 0: 1, 3, 2 (1 page fault)
13. 2 (No page fault)
14. 0 replaces 3: 1, 0, 2 (1 page fault)
15. 1 (No page fault)
16. 7 replaces 2: 1, 0, 7 (1 page fault)
17. 0 (No page fault)
18. 1 (No page fault)

Total page faults: 9

Key Considerations
Locality of Reference: Programs tend to access memory locations that are near each other in
time. This principle is the basis for the effectiveness of many page replacement algorithms.
Number of Frames: Increasing the number of frames (memory allocated to a process)
typically reduces the page fault rate.

You might also like