Transcript Lecture 21
Lecture 21
Virtual Memory
Allocation of Frames
Working-Set Model
Fall 2000
M.B. Ibáñez
Allocation of Frames
• How much main memory to allocate for a
particular process?
• Allocation policies
– Fixed
– Variable
• Replacement scope
– Local
– global
Fall 2000
M.B. Ibáñez
Fixed-allocation
• Gives a process a fixed number of pages
within which to execute
• When a page fault occurs, one of the pages
of that process must be replaced
From Operating Systems.
Internals and Design Principles
W. Stalling. Prentice Hall.
Fall 2000
M.B. Ibáñez
Fixed Allocation
• Equal allocation – e.g., if 100 frames and 5 processes, give
each 20 pages.
• Proportional allocation – Allocate according to the size of
process.
m 64
si 10
si size of process pi
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
From Operating System Concepts. Silberschatz & Galvin
Fall 2000
M.B. Ibáñez
Variable Allocation
• This policy allows the number of page frames
allocated to a process to be varied over the lifetime
of the process.
• A process that is suffering persistently high levels of page
faults, will be given additional page frames to reduce the
fault rate.
• A process with an exceptionally low page fault rate,
indicating that the process is quite well-behaved from a
locality point of view, will be given a reduced allocation.
Fall 2000
M.B. Ibáñez
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.
From Operating System Concepts. Silberschatz & Galvin
Fall 2000
M.B. Ibáñez
Variable Allocation,
Local Scope
• When a new process is loaded into main memory,
allocate to it a certain number of page frames. Use
either prepaging or demand paging
• When a page fault occurs, select the page to
replace from the resident page set of that process
• From time to time, reevaluate the allocation
provided to the process, and increase or decrease it
to improve overall performance
Fall 2000
M.B. Ibáñez
Variable Allocation,
Local Scope
• Key elements, criterion used to determine
– Resident set size
• Based on an assessment of the likely future demands
of active processes
– Timing of changes
Fall 2000
M.B. Ibáñez
Working Set Strategy
• The Working Set with parameter D for a
process at virtual time t, W(t, D), is the set
of pages of that process that have been
referenced in the last D virtual times units.
Fall 2000
M.B. Ibáñez
Fall 2000
M.B. Ibáñez
From Operating Systems. Internals and Design Principles
W. Stalling. Prentice Hall.
Working Set
Fall 2000
M.B. Ibáñez
From Operating Systems. Internals and Design Principles
W. Stalling. Prentice Hall.
Variations of the Working Set
• When a process first begin 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
Fall 2000
M.B. Ibáñez
Using the Working Set
to guide a strategy
for Resident Set Size
• Monitor the working set of each process
• Periodically remove from the resident set a
process those pages that are not in its
working set
• A process may execute only if its working
set is in main memory
Fall 2000
M.B. Ibáñez
Problems with the
Working Set Strategy
• The past not always predict the future.
– Both the size and the membership of the working set will change
over time
• A true measurement of working set for each
process is impractical
– It will be necessary to time stamp every page reference for every
process using the virtual time of that process and then maintain a
time-ordered queue of pages for each process
• The optimal value of D is unknown and in
any case would vary
Fall 2000
M.B. Ibáñez
Attempt to approximate a
Working Set strategy
• Focus on the page fault rate of a process
• Why?
– If the page fault rate for a process is below some
minimum threshold , the system as a hold can benefit
by assigning a smaller resident set size to this process
– If the page fault rate for a process is above some
maximum threshold , the process can benefit from an
increased resident set size without degrading the system
Fall 2000
M.B. Ibáñez
Page-fault frequency (PFF)
algorithm
• Requires a bit to be associated with each page in memory
• This bit is set to 1 when that page is accessed
• When a page fault occurs, the operating system notes the
virtual time since the last page fault for that process
• A threshold F is defined
• If the amount of time since the last page fault is less than F,
then a page is added to the resident size
• Otherwise, discard all pages with a use bit of zero, and
shrink the resident set accordingly
• At the same page, reset the use bit on the remaining pages
of the process to zero
Fall 2000
M.B. Ibáñez
Page Size
• Smaller page size, less amount of internal
fragmentation
• Smaller page size, more pages required per
process
• More pages per process means larger page tables
• Larger page tables means large portion of page
tables in virtual memory
• Secondary memory is designed to efficiently
transfer large blocks of data so a large page size is
better
Fall 2000
M.B. Ibáñez
From Operating Systems.
Internals and Design Principles
W. Stalling. Prentice Hall.
Page Size
• Small page size, large number of pages will be
found in main memory
• As time goes on during execution, the pages in
memory will all contain portions of the process
near recent references. Page faults low.
• Increased page size causes pages to contain
locations further from any recent reference. Page
faults rise.
From Operating Systems.
Internals and Design Principles
W. Stalling. Prentice Hall.
Fall 2000
M.B. Ibáñez