Docsity

Virtual Memory Three - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Virtual Memory Three - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Operating Systems

Lecture 24:

Virtual Memory (cont)

1

Ryan?

2

Clock Policy

• Uses and additional bit called a “use bit”

• When a page is first loaded in memory or

referenced, the use bit is set to 1

• When it is time to replace a page, the OS

scans the set flipping all 1’s to 0

• The first frame encountered with the use bit

already set to 0 is replaced.

5

Clock Policy

Algorithmically identical with another algorithm called “2nd^ chance”.

Only the implementation is different.

7

The 2

nd

Chance Algorithm

  • Holds a FIFO list of pages, each page has a bit R=1 if referenced.
  • Evict the oldest page not referenced in last tick.
  • Repeat while oldest has R=1:
    • Move to end of list (as if just paged in)
    • Set R=
  • At worst, all pages have R=1, so degenerates to regular FIFO.
  • Page list if fault occurs at time 20, A has R bit set (numbers above pages are loading times)

8

The Clock Page Replacement Alg

  • The clock algorithm on 2 bits: referenced R and modified M
  • Hardware sets corresponding R on every memory reference
  • At process start, M and R set to 0
  • Each circular pass, R bits set to 0.
  • Pages are classified
    1. not referenced, not modified
    2. not referenced, modified
    3. referenced, not modified
    4. referenced, modified
  • NRU removes page from lowest- numbered non-empty class

Combined Examples

Comparison

Results based on the execution of 0.25 x 10^6 references in a FORTRAN program, using

a page size of 256 words. It is assumed that the number of page frames assigned to a

process is fixed.

13

Thrashing

• If a process does not have “enough” pages, the page-

fault rate is very high. This leads to:

  • low CPU utilization
  • operating system thinks that it needs to increase the

degree of multiprogramming

  • another process added to the system

• Thrashing ≡ a process is busy swapping pages in and

out

14

Thrashing (Cont.)

16

Allocation of Frames

• Each process needs minimum number of pages

• Example: 6 pages needed by one instruction

  • instruction might span 2 pages
  • 1 st^ argument spans 2 pages
  • 2 nd^ argument spans 2 pages

• Major allocation schemes

  • Fixed vs. Priority allocation
  • Global vs. Local allocation

17

Fixed Allocation

• Equal allocation: e.g, 100 frames and 5

processes, give each process 20 frames.

• Proportional allocation – Allocate according to

the size of process

m S

s a p

m

S s

s p

i i i

i

i i

= = ×

allocation for

totalnumber of frames

sizeofprocess

2

1

2

= × ≈

= × ≈

a

a

s

s

m

i

19

Global vs. Local Allocation

• Global replacement – process selects a

replacement frame from the set of all

frames; one process can take a frame from

another

• Local replacement – each process selects

from only its own set of allocated frames

20

  • A, B, C processes in memory
  • Process A page faults requesting A6.
  • LRU used

Global vs. Local Allocation

(cont)

Time last reference