pratima page replacement

12
Page Replacement Algorithms BY PRATIMA SHARMA ASSISTANT PROFESSOR ww.advanced.edu.in

Upload: pratima-sharma

Post on 11-Jan-2017

124 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Pratima  page replacement

Page Replacement AlgorithmsBYPRATIMA SHARMAASSISTANT PROFESSOR

www.advanced.edu.in

Page 2: Pratima  page replacement

When ever a page is searched in main memory and it is not found there a page fault occurs, so to bring that page in memory we have to remove some other page(victim). Page replacement algorithms selects which page to remove from the existing pages.

www.advanced.edu.in

Page Replacement Policy

Page 3: Pratima  page replacement

Basic Page Replacement If the desired page is not in the memory, then we have to make the space for that page by replacing some other page or allotting it free frame if available.

1. Find the location of the desired page on the disk.

2. Find a free frame

(a) If there is a free frame, use it.

(b) If there is no free frame, use page replacement algorithm to select a victim.

(c) Write the victim frame to the disk and update the page table accordingly.

3. Read the desired page into the new frame and change the page table.

4. Restart the process.

www.advanced.edu.in

Page 4: Pratima  page replacement

Page ReplacementDiagram shows how page replacement takes place.

www.advanced.edu.in

Page 5: Pratima  page replacement

Types of Page Replacement 1. FIFO Page Replacement

2. Optimal Page Replacement

3. LRU Page Replacement

www.advanced.edu.in

Page 6: Pratima  page replacement

First In First Out (FIFO)page replacement

www.advanced.edu.in

This is the simplest page replacement algorithm.

1. The page which come first is replaced first.

2. In this we have some frames ,if all the frames are occupied and a request to access new page comes then the oldest page is chosen.

3. Here we are taking 3 frames (3 pages can be in memory at a time).

4. We have created a FIFO Queue to hold all pages in memory.

5. A reference string used is 7 0 1 2 0 3 0 4 2 3 0 3 0 3 2 1 2 0 1 7 0 1

Page 7: Pratima  page replacement

Reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

www.advanced.edu.in

7 70

770

1

2

0

1

2

3

1

2

3

0

4

3

0

4

2

0

4

2

3

0

2

3

0

1

3

0

1

2

7

1

2

7

0

2

7

0

1

Page in green colour is replaced

Total number of Page Fault= 15 (count the number of queues)

In FIFO we have Belady’s anomaly if we increase number of frames page fault also increasesTry it with reference string 1 2 3 4 1 2 5 1 2 3 4 5

Page 8: Pratima  page replacement

Optimal Page Replacement

www.advanced.edu.in

1. The Optimal policy selects for replacement the page that will not be used in future for longest period of time. You have to see reference string towards right hand side.

2. This is the best type of Page Replacement Algorithm.

3. But predicting the future is difficult so this is practically not possible.

Page 9: Pratima  page replacement

Reference string

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 17 7

0

7

0

1

2

0

1

2

0

3

2

4

3

2

0

3

2

0

1

7

0

1

The page with green colour is Replaced

Total Number of Page Fault = 9.

Page 10: Pratima  page replacement

Least Recently Used1. Least recently Used algorithm replace the page that has not been used for the longest period of

time.

2. You have to see past string in this(Means Left hand side of the string is considered.)

For example from the string 7 0 1 we will replace 7 as it was least recently used.

A reference string used is 7 0 1 2 0 3 0 4 2 3 0 3 0 3 2 1 2 0 1 7 0 1

Page 11: Pratima  page replacement

Reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1

7 7

0

7

0

1

2

0

1

2

0

3

4

0

3

4

0

2

4

3

2

0

3

2

1

3

2

1

0

2

1

0

7

Total number of Page Fault= 12

Page 12: Pratima  page replacement

Pratima SharmaAssistant Professor

[email protected]

Advanced Educational Institutions,70 km Milestone,

Delhi-Mathura Road, Dist. Palwal, Haryana-121105

+91–1275–398400, 302222www.advance.edu.in