Page allocation

Download Report

Transcript Page allocation

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
si  size of process pi
m  64
si  10
S   si
s2  127
m  total number of frames
s
ai  allocation for pi  i  m
S
a1 
10
 64  5
137
127
a2 
 64  59
137
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
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
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
Thrashing
Thrashing
• Why does paging work?
– Locality model
• Process migrates from one locality to another
• Why does thrashing occur?
–  size of locality > total memory size
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
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
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
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
Example
Given the following reference string:
0
1
2
3
0
1
2
(a) Determine WS(ti) with  = 3
(b) Determine WS(ti) with  = 4
(c) Determine WS(ti) with  = 9
3
0
1
2
3
4
5
6
7