page replacement

13
Page Replacement

Upload: floyd

Post on 22-Feb-2016

49 views

Category:

Documents


0 download

DESCRIPTION

Page Replacement. Overview. Why we need page replacement? Basic page replacement technique. Different type of page replacement algorithm and their examples. Why????. Limited physical memory --> limited number of frame --> limited number of frame allocated to a process. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Page Replacement

Page Replacement

Page 2: Page Replacement

Overview

1. Why we need page replacement?

2. Basic page replacement technique.

3. Different type of page replacement algorithm and their examples.

Page 3: Page Replacement

Why????

• Limited physical memory --> limited number of frame --> limited number of frame allocated to a process.

Page 4: Page Replacement

Basic Page Replacement

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

2. Find a free frame• If there is a free frame use it.• No free frame – use page replacement

algorithm to select a victim frame.• Write the victim frame to disk, change the

frame and page tables accordingly.

Page 5: Page Replacement

Replacement Policy

• Which page to be replaced?

• Page removed should be the page least likely to be referenced in the near future.

• Most policies predict the future behavior on the basis of past behavior.

Page 6: Page Replacement

Replacement Algorithm

1. FIFO page replacement

2. Optimal page replacement

3. LRU page replacement

4. LRU-Approximation page replacement

5. Counting-Based page replacement

Page 7: Page Replacement

example

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

String Reference

7 7

0

7

1

0

0

1

2

0

1

2

1

2

3

2

3

0

3

0

4

4

3

2

2

3

0

2

3

0

2

3

0

0

1

2

0

1

2

0

1

2

7

7

7

7

7

7

0

4

2

3

0

1

7

7

7

* * * * * * * * * * **

Young page

Old Page

Frames initially empty

Page faults

Page 8: Page Replacement

• FIFO is similar to First In First Out CPU scheduling algorithm wherein the requested page is loaded first and subsequent fetches are also serviced in order of request arrival.

• A page which is being accessed quite often may also get replaced because it arrived earlier than those present

• Ignores locality of reference. A page which was referenced last may also get replaced, although there is high probability that the same page may be needed again.

FIFO Page Replacement

Page 9: Page Replacement

7 7

0

7

1

0

0

1

2

0

1

2

1

2

3

2

3

0

3

0

4

4

3

2

2

3

0

2

3

0

2

3

0

0

1

2

0

1

2

0

1

2

7

7

7

7

7

7

0

4

2

3

0

1

7

7

7

* * * * * * * * * * **

pf/n

pf = page faults N = number of reference made

12/20 = 60%

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

FIFO

Page 10: Page Replacement

• The main idea of OPT is to replace the pages found n the frames that re not going to be used/ referenced soon.

• An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms (called OPT or MIN). It is simply this: Replace the page that will not be used for the longest period of time.

- At the moment of page fault:• Label each page in memory is labeled with the number of

instructions that will be executed before that page is first referenced

• Replace the page with the highest number: i.e. postpone as much as possible the next page fault

Optimal Page Replacement (OPT)

Page 11: Page Replacement

OPT

7 7

0

7

1

0

0

1

2

0

1

2

0

2

3

0

3

0

4

2

3

4

2

3

0

2

3

0

2

3

0

2

3

2

0

1

0

1

2

0

1

2

0

1

7

0

1

7

4

2

3

2

0

1

0

1

7

* * * * *

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

*pf/n

pf = page faults N = number of reference made

6/20 = 30%

Page 12: Page Replacement

Least Recently Used Page Replacement Algorithm

• This algorithm reposes on the opposite of the concept of temporal locality, wherein if a page has not been referenced for quite some time then it is not going to be referenced in the future.

Page 13: Page Replacement

7 7

0

7

0

1

0

1

2

1

2

0

2

0

3

2

3

0

3

0

4

4

2

3

2

3

0

2

3

0

0

3

2

3

1

2

1

2

0

2

0

1

0

7

1

1

7

0

2

4

2

3

2

1

7

0

1

* * * * ** ** *

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

• Pf/N 9 / 20 = 45%

Least Recently Used Page Replacement Algorithm