0% found this document useful (0 votes)
40 views14 pages

Computer Architecture: Virtual Memory

This document summarizes different algorithms for virtual memory page replacement in computer systems. It describes 7 common page replacement algorithms: Optimal Page Replacement, First-In First-Out (FIFO), Last-In First-Out (LIFO), Least Recently Used (LRU), Not Recently Used (NRU), Clock, and Second Chance. Examples are provided to illustrate how each algorithm works on sample reference strings. The document concludes with two assignment questions asking the reader to calculate page faults for different reference strings using FIFO and LRU with varying number of frames.

Uploaded by

Hussain Jehl
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)
40 views14 pages

Computer Architecture: Virtual Memory

This document summarizes different algorithms for virtual memory page replacement in computer systems. It describes 7 common page replacement algorithms: Optimal Page Replacement, First-In First-Out (FIFO), Last-In First-Out (LIFO), Least Recently Used (LRU), Not Recently Used (NRU), Clock, and Second Chance. Examples are provided to illustrate how each algorithm works on sample reference strings. The document concludes with two assignment questions asking the reader to calculate page faults for different reference strings using FIFO and LRU with varying number of frames.

Uploaded by

Hussain Jehl
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/ 14

Computer Architecture

Virtual Memory

Dr. Falah Hassan Ali


University of Toronto
Computer to compensate for shortages of physical memory by temporarily
transferring pages of data from random access memory (RAM) to disk
storage. If your computer lacks the random access memory (RAM) needed
to run a program or operation, Windows uses virtual memory to
compensate. Virtual memory combines computer's RAM with temporary
space on hard disk. When RAM runs low, virtual memory moves data from
RAM to a space called a paging file.
Page Replacement flowchart
Replacement Algorithms
1- Optimal Page Replacement (OPT).
2- First-In First-Out Replacement (FIFO).
3- Last-In First-Out Replacement (LIFO).
4- Least Recently Used Pages Replacement (LRU).
5- Not Recently Used Replacement (NRU).
6- Clock Page Replacement (CLK).
7- The Second Chance Replacement (SCH).

Optimal Page Replacement


Replace the page that won’t be needed for the longest time in the
future.

Example (1):
Page fault: (7, 0, 1, 2, 3, 4, 0, 1, 7)

Example (2):

Page fault: (e, d)

FIFO Replacement Algorithm


Replace the page that entered first in the stack

Example: FIFO replacement on reference string (c, a, d, b, e, b, a, b, c, d)


using four frames.
Page fault: (e, a, b, c, d)

Example: FIFO replacement on reference string (0 1 2 3 0 1 4 0 1 2 3 4)


using three frames.

Page fault: (0, 1, 2, 3, 0, 1, 4, 2, 3)

Example: FIFO replacement on reference string (0 1 2 3 0 1 4 0 1 2 3 4)


using four frames.

Page fault: (0, 1, 2, 3, 4, 0, 1, 2, 3, 4)


Last-In First-Out Replacement Algorithm
Replace the page that entered last in the stack

Example: LIFO replacement on reference string (c, a, d, b, e, b, a, b, c, d)


using four frames.

Least Recently Used Pages Replacement Algorithm

Example: LRU replacement on reference string (c a d b e b a b c d) using


four frames.
Page fault: (e, c, d)

Example: LRU replacement on reference string (7 0 1 2 0 3 0 4 2 3 0 3 2 1 2


0 1 7 0 1) using four frames.

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
----------------------------------------------------------------------
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0
7 0 1 2 2 3 0 4 2 2 0 3 3 1 2 0 1 7
Page out 7 1 2 30 4 0 3 2
Page fault: (2, 3, 4, 2, 3, 0, 1, 0, 7)
Not Recently Used Replacement Algorithm
Replace the page that is not used recently.

Clock Page Replacement Algorithm


OS circulates through pages, clearing reference bits and finding a page with
reference bit set to 0. Keep pages in a circular list = clock. Pointer to next
victim = clock hand
Example: CLK replacement on reference string (1 2 3 4 1 2 5 1 2 3 4 5)
using four frames.
Example: CLK replacement on reference string (c a d b e b a b c d) using
four frames.

Page fault: (e, a, c, d)

The Second chance Replacement Algorithm


Replace the first old, the second old, the third old and so on
Assignment
Q1) Consider a system that has no pages loaded and that uses the FIFO
PRU.
Consider the following reference string (sequences of pages referenced).

0 1 2 3 0 1 4 0 1 2 3 4

If we have 3 frames this generates 9 page faults (do it).

If we have 4 frames this generates 10 page faults (do it).

Repeat the above calculations for LRU.

Q2) Determine the type of the following algorithms:

You might also like