Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 57

p 

Ú 

|
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 


î Mrinciple of locality of references: memory


references within a process tend to cluster
î Hence: only a few pieces of a process will
be needed over a short period of time
î Mossible to make intelligent guesses about
which pieces will be needed in the future
î This suggests that virtual memory may
work efficiently (ie: trashing should not
occur too often)

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

î We will first discuss the hardware aspects;


then the algorithms used by the OS

º
M 
î Typically, each process has its own page table

î Each page table entry contains a present bit to indicate


whether the page is in main memory or not.
[ 
 
  


  

 

[  
 
   

   
 
 
   
   
 
   

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 

î Mage tables are variable in length (depends


on process size)
 
 



î A single register holds the starting
physical address of the page table of the
currently running process

Î
  
 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

î Similarly to paging, each segment table entry


contains a present bit and a modified bit
î [f the segment is in main memory, the entry contains
the starting address and the length of that segment
î Other control bits may be present if protection and
sharing is managed at the segment level
î Logical to physical address translation is similar to
paging except that the offset is added to the starting
|6 address (instead of being appended)
  
 J 

J 

|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 

î Segments are shared when entries in the


segment tables of 2 different processes
point to the same physical locations
î Ex: the same code of a text editor can be
shared by many users
3    

î but each user would still need to have its
own private data segment

|
Ú
 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 

î The Segment Base is the physical address of the page


table of that segment
î Mresent and modified bits are present only in page
table entry
î Mrotection and sharing info most naturally resides in
segment table entry
’!
 

 
 
(((
|
3 J  J

î aemory management software depends
on whether the hardware supports paging
or segmentation or both
î Mure segmentation systems are rare.
Segments are usually paged -- memory
management issues are then those of
paging
î We shall thus concentrate on issues
associated with paging
î To achieve good performance we need a
low page fault rate

m M

î etermines when a page should be brought into
main memory. Two common policies:
  
 

 
 
    
 !   
6    
 


 



 



 
6    
 
 

  
 

     
6       ! 


 
+ , 
 

6"
M  

î etermines where in real memory a
process piece resides
î For pure segmentation systems:

   (((
  


î For paging (and paged segmentation):
  

 
  !
  
  





- 

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


î The decision for the set of pages to be


considered for replacement is related to
the resident set management strategy:
 

   
 
.è 

î Ño matter what is the set of pages


considered for replacement, the
replacement policy deals with algorithms
that will choose the page within that set


‰ 
  
   

î 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





 

î When the main memory is empty, each new


page we bring in is a result of a page fault
î For the purpose of comparing the different
algorithms, we are not counting these
initial page faults
 
   


 
î But, in contrast to what is shown in the
figures, these initial references are really
producing page faults

[  

 Gw M

î Each page could be tagged (in the page table
entry) with the time at each memory reference.
î The LwU page is the one with the smallest
time value (needs to be searched at each page
fault)
î This would require expensive hardware and a
great deal of overhead.
î Consequently very few computer systems
provide sufficient hardware support for true
LwU replacement policy
î Other algorithms are used instead

6
 m[m3M

î Treats page frames allocated to a process
as a circular buffer
è   
    

(3! 
  
 
6 4  
   /1*

6 5
-      

   2[23
) 
6
-
   
 

  

  



Ú


m[m3  Gw

î LwU recognizes that pages 2 and 5 are referenced


more frequently than others but F[FO does not
î F[FO performs relatively poorly
0"
w 
w   
î *11 
7   
î 1
   


î è   
 3)   


î Ú 



 

î Ú 



 

î Ú 



 

î Ú 



 

î Ñ1*
 
 
 

  (
î Ñ1*  
  
   
 -


0|
J
Ú  

 

î 7    2[232[23 


   

î )  5  1   
î [ 18"  

î [ 18| 1
       
      9




  (
î 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
  


Ú


Ú
  m[m3Gw

î Asterisk indicates that the corresponding use


bit is set to 1
î Clock protects frequently referenced pages by
setting the use bit to 1 at each reference
0
Ú


Ú
  m[m3Gw
î Ñumerical experiments tend to show that
performance of Clock is close to that of LwU
î Experiments have been performed when the
number of frames allocated to each process is
fixed and when pages local to the page-fault
process are considered for replacement
è    

 

 
 
  
 6  
/1*2[23
4  

  | 


 |6

 ( 


 
  




M‰ 
î Mages to be replaced are kept in main memory for a
while to guard against poorly performing
replacement algorithms such as F[FO
î Two lists of pointers are maintained: each entry
points to a frame selected for replacement



   
  
    
  

  
   
  
î A frame to be replace has a pointer added to the tail
of one of the lists and the present bit is cleared in
corresponding page table entry
 
 



M‰ 
î At each page fault the two lists are first examined
to see if the needed page is still in main memory
[  9  
 


 

  
 
 

[     
  
 
      


 

   

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
     

  



Ú 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

î The working set of a process first grows


when it starts executing
î then stabilizes by the principle of locality
î it grows again when the process enters a
new locality (transition period)
   
 
 

  
î then decreases after a sufficient long time
spent in the new locality

|
 #
 JJ
î the working set concept suggest the following
strategy to determine the resident set size
7 
 

 


  
 
 
 

  
  

è  
 

 

  

 
6 [    


 
 




< !
    



6
 #
 JJ

î Mractical problems with this working set strategy



  

 



6 
  
 




 

6 
 

- 

 

 

  
; 


î Solution: rather than monitor the working set,
monitor the page fault rate!

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    



You might also like