allocation of frames each process needs minimum number of pages two major allocation schemes...

12
Allocation of Frames Each process needs minimum number of pages Two major allocation schemes fixed allocation priority allocation

Upload: wendy-quinn

Post on 16-Dec-2015

247 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Allocation of Frames• Each process needs minimum number of pages

• Two major allocation schemes

– fixed allocation

– priority allocation

Page 2: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Fixed Allocation

• Equal allocation – For example, if there are 100 frames and 5 processes, give each process 20 frames.

• Proportional allocation – Allocate according to the size of process

mSs

pa

m

sS

ps

iii

i

ii

for allocation

frames of number total

process of size

5964137127

56413710

127

10

64

2

1

2

a

a

s

s

m

i

Page 3: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Priority Allocation

• Use a proportional allocation scheme using

priorities rather than size

• If process Pi generates a page fault,

– select for replacement one of its frames

– select for replacement a frame from a process with lower

priority number

Page 4: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

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

Page 5: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Thrashing•If a process does not have “enough” pages, the page-fault rate is very high. This leads to low CPU utilization

•Thrashing a process is busy swapping pages in and out

It may happen–operating system thinks that it needs to increase the degree of multiprogramming–another process added to the system

Page 6: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Thrashing

Page 7: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Thrashing• Why does paging work?

– Locality model

• Process migrates from one locality to another

• Why does thrashing occur?– size of locality > total memory size

Page 8: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Dynamic Paging Algorithms• Paging algorithms considered so far all assume that a process is

allocated a fixed amount of memory when it is started and the amount does not change during the computation

• Static algorithms do not adjust the allocation of frames, even if the process passes through phases in which it requires a large physical address space or its memory requirements are modest

• A process changes locality as it executes. When the locality changes, not only do the identities of the pages change but also the number of pages in the locality is likely to change

• Sometimes the process needs only a few frames to hold the pages it is using, while at other times it needs many frames

• Dynamic paging algorithms adjust the memory allocation to match the process’s needs as they change

Page 9: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Working Set Model• working set window a fixed number of

page references (e.g., 10,000 instructions)• WS(ti) working set at time ti pages

referenced in the most recent (up to ti)– if too small will not encompass entire locality– if too large will encompass several localities– if = will encompass entire program

Page 10: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Working Set Model• For any fixed value of , the working set size can

vary over time– For many programs, periods of relatively stable working

set sizes alternate with periods of rapid change

– When a process first begins executing, it gradually builds up to a working set as it references new pages

– Eventually, by the principle of locality, the process should stabilize on a certain set of pages

– Subsequent transient periods reflect a shift of the program to a new locality

Page 11: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

Working Set Model• The OS monitors the working set of each

process and allocates enough frames to provide it with its working set size– If there are enough extra frames, another process can

be initiated– D = |WS(ti)| sum of working set sizes of all

processes at ti total demand frames

– if D > m Thrashing

– Policy: if D > m, then suspend one of the processes

• This strategy prevents thrashing while keeping the degree of multiprogramming as high as possible. Thus, it optimizes CPU utilization

Page 12: Allocation of Frames Each process needs minimum number of pages Two major allocation schemes –fixed allocation –priority allocation

ExampleExample

Given the following reference string:

0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7

(a) Determine WS(ti) with = 3

(b) Determine WS(ti) with = 4

(c) Determine WS(ti) with = 9