Professional Documents
Culture Documents
Virtual Memory
Virtual Memory
Ú
|
M
î The OS brings into main memory only a
few pieces of the program (including its
starting point)
î Each page/segment table entry has a
present bit that is set only if the
corresponding piece is in main memory
î The resident set is the portion of the
process that is in main memory
î An interrupt (memory fault) is generated
when the memory reference is on a piece
not present in main memory
6
G
p
0
J
p
î aemory management hardware must
support paging and/or segmentation
î OS must be able to manage the movement of
pages and/or segments between secondary
memory and main memory
º
M
î Typically, each process has its own page table
[
M
î A modified bit indicates if the page has been
altered since it was last loaded into main
memory
[
î Other control bits may be present if protection
is managed at the page level
!
6
MJ
Î
M J
J M
î [f we share the same code among different users,
it is sufficient to keep only one copy in main
memory
î Shared code must be reentrant (ie: non self-
modifying) so that 2 or more processes can
execute the same code
î [f we use paging, each sharing process will have a
page table who¶s entry points to the same frames:
only one copy is in main memory
î But each user needs to have its own private data
pages
ü
M
p
î aost computer systems support a very large
virtual address space
06 º
[ 06
º#
6$%6"&
î The entire page table may take up too much main
memory. Hence, page tables are often also stored
in virtual memory and subjected to paging
è
|"
M
î Since a page table will generally require several pages
to be stored. One solution is to organize page tables
into a multilevel hierarchy
è
6
!0
|6
|
'
6(
||
J
î Typically, each process has its own segment table
|0
J
î [n each segment table entry we have both the starting
address and length of the segment
î But variable length segments introduce external
fragmentation and are more difficult to swap in and
out...
î [t is natural to provide protection and sharing at the
segment level since segments are visible to the
programmer (pages are not)
î Useful protection bits in segment table entry:
)
*
|º
J J
J
|
Ú
J
M
î To combine their advantages some processors and
OS page the segments.
î Several combinations exists. Here is a simple one
î Each process has:
!
î The virtual address consist of:
!
'
!
|
J
M J
|Î
J Ú
J
M
-
6|
w M
î eals with the selection of a page in main
memory to be replaced when a new page is
brought in
î This occurs whenever main memory is full
(no free frame available)
î Occurs often since the OS tries to bring
into main memory as many processes as it
can to increase the multiprogramming level
66
w M
î Ñot all pages in main memory can be
selected for replacement
î Some frames are locked (cannot be paged
out):
[ 3
î The OS might decide that the set of pages
considered for replacement should be:
60
w M
6º
î The Optimal policy selects for replacement
the page for which the time to the next
reference is the longest
!
6 /
/1*
6 2
2[23
6
6
Gw M
î weplaces the page that has not been referenced for the
longest time
î Example: A process of 5 pages with an OS that fixes
the resident set size to 3
6
6
m[m3M
î Treats page frames allocated to a process
as a circular buffer
è
(3!
6 4
/1*
6 5
-
2[23
)
6
-
6ü
Ú
m[m3 Gw
î è
3)
î Ú
î Ú
î Ú
î Ú
î Ñ1*
(
î Ñ1*
-
0|
J
Ú
(
î isadvantage : it is inefficient because it is constantly
moving pages around on its list.
î Better approach :
06
Ú
M
î The set of frames candidate for replacement is
considered as a circular buffer
î When a page is replaced, a pointer is set to point to
the next frame in buffer
î A w bit for each frame is set to 1 whenever
î When it is time to replace a page, the first frame
encountered with the w bit set to 0 is replaced.
1 |
"
00
Ú
M
0º
Ú
Ú
m[m3Gw
[
6
î The modified list also serves to write out modified
pages in cluster (rather than individually)
0
Ú M
î When does a modified page should be written out
to disk?
î emand cleaning
'
6
6
î Mrecleaning
6
9
0ü
Ú M
î A good compromise can be achieved with
page buffering
!
6
6
º"
w
JJ
î The OS must decide how many page
frames to allocate to a process
º|
w
JJ
î Fixed-allocation policy
6
î pariable-allocation policy
6
6
-
3)
º6
w J
î [s the set of frames to be considered for
replacement when a page fault occurs
î Local replacement policy
î Olobal replacement policy
î Let us consider the possible combinations of
replacement scope and resident set size policy
º0
m
G
î Each process is allocated a fixed number of pages
î When a page fault occurs: page frames
considered for replacement are local to the page-
fault process
î Mroblem: difficult to determine ahead of time a
good number for the allocated frames
!
!
ºº
m
!
î [mpossible to achieve
º
"
î 2[23
(4
' (
º
p
!
î Simple to implement--adopted by many OS (like
Unix Spw )
î A list of free frames is maintained
3
4
!
î Mage buffering can alleviate this problem since
a page may be reclaimed if it is referenced again
soon
ºÎ
p
G
î aay be the best combination (used by Windows
ÑT)
î Allocate at load time a certain number of frames
to a new process based on application type
î When a page fault occurs, select the page to
replace from the resident set of the process that
suffers the fault
î weevaluate periodically the allocation provided
and increase or decrease it to improve overall
performance
º
G
w
î Locality of wef:
(
î 4
Working Set
î [
(
ºü
#
JJ
î [s a variable-allocation method with local scope
based on the assumption of locality of references
î The working set for a process at time t, W(k,t), is
the set of pages that have been referenced in the
last K most recent refrences.
:è#:
;
è#
'
"
#
JJ
|
#
JJ
î the working set concept suggest the following
strategy to determine the resident set size
7
è
6 [
< !
6
#
JJ
0
M$
M$mm%J
î efine an upper bound
U and lower bound L for
page fault rates
î Allocate more frames to
a process if fault rate is
higher than U
î Allocate less frames if
fault rate is < L
î The resident set size
should be close to the
working set size W
î We suspend the process
if the MFF > U and no
more free frames are
º
available
G
Ú
î etermines the number of
processes that will be
resident in main memory
(ie: the multiprogramming
level)
4
!
4
!
=
!
thrashing
G
Ú
î A working set or page fault frequency
algorithm takes care of load control
î Another approach is to adjust explicitly the
multiprogramming level so that the mean time
between page faults equals the time to
process a page fault
M
J
î Explicit load control requires that we sometimes
swap out (suspend) processes
î Mossible victim selection criteria:
2
6
/
6
6
-
/
6
Î