SlideShare una empresa de Scribd logo
1 de 21
By
SATHISHKUMAR G
(sathishsak111@gmail.com)
 Processes tend to reference pages in localized
patterns
 Temporal locality
 locations referenced recently likely to be referenced
again
 Spatial locality
 locations near recently referenced locations are likely to
be referenced soon.
 Goal of a paging system is
 stay out of the way when there is plenty of available
memory
 don’t bring the system to its knees when there is not.
 Demand Paging refers to a technique where
program pages are loaded from disk into memory
as they are referenced.
 Each reference to a page not previously touched
causes a page fault.
 The fault occurs because the reference found a
page table entry with its valid bit off.
 As a result of the page fault, the OS allocates a
new page frame and reads the faulted page from
the disk.
 When the I/O completes, the OS fills in the PTE,
sets its valid bit, and restarts the faulting process.
 Demand paging
 don’t load page until absolutely necessary
 commonly used in most systems
 doing things one at a time can be slower than batching
them.
 Prepaging
 anticipate fault before it happens
 overlap fetch with computation
 hard to predict the future
 some simple schemes (hints from programmer or program
behavior) can work.
 vm_advise
 larger “virtual” page size
 sequential pre-paging from mapped files
 Imagine that when a program starts, it has:
 no pages in memory
 a page table with all valid bits off
 The first instruction to be executed faults,
loading the first page.
 Instructions fault until the program has enough
pages to execute for a while.
 It continues until the next page fault.
 Faults are expensive, so once the program is
running they should not occur frequently,
assuming the program is “well behaved” (has
good locality).
 When a fault occurs, the OS loads the faulted
page from disk into a page of memory.
 At some point, the process has used all of the
page frames it is allowed to use.
 When this happens, the OS must replace a page
for each page faulted in. That is, it must select a
page to throw out of primary memory to make
room.
 How it does this is determined by the page
replacement algorithm.
 The goal of the replacement algorithm is to
reduce the fault rate by selecting the best victim
page to remove.
 A good property
 if you put more memory on the machine, then your page
fault rate will go down.
 Increasing the size of the resource pool helps everyone.
 The best page to toss out is the one you’ll never
need again
 that way, no faults.
 Never is a long time, so picking the one closest to
“never” is the next best thing.
 Replacing the page that won’t be used for the longest
period of time absolutely minimizes the number of page
faults.
 Example:
 The optimal algorithm, called Belady’s algorithm, has the
lowest fault rate for any reference string.
 Basic idea: replace the page that will not be used for the
longest time in the future.
 Basic problem: phone calls to psychics are expensive.
 Basic use: gives us an idea of how well any
implementable algorithm is doing relative to the best
possible algorithm.
 compare the fault rate of any proposed algorithm to
Optimal
 if Optimal does not do much better, then your proposed
algorithm is pretty good.
 If your proposed algorithm doesn’t do much better than
Random, go home.
Effective Access.Time = (1-p)*Tm + p*Td
Tm = time to access main memory
Td = time to fault
Execution time = (roughly) #memory refs * E.A.T.
# of physical page frames
execution
time
Random
LRU
Opt
Down in
this
range,
it doesn’t
matter so
much what
you do.
In here,
you can
expect to
have some
effect.
Up here,
forget it.
Few frames Lots of frames
 FIFO is an obvious algorithm and simple to implement.
 Basic idea, maintain a list or queue of pages in the order
in which they were paged into memory.
 On replacement, remove the one brought in the longest
time ago.
 Why might it work?
 Maybe the one brought in the
longest ago is one we’re not using now.
 Why it might not work?
 Maybe it’s not.
 We have no real information to tell us if it’s being used or
not.
 FIFO suffers from “Belady’s anomaly”
 the fault rate might actually increase when the algorithm is
given more memory -- a bad property.
This page
was faulted
recently
This page
was faulted
a long time ago.
Reference stream is A B C A B D A D B C
OPTIMAL
A B C A B D A D B C B
toss A or Dtoss C5 Faults
FIFO
A B C A B D A D B C B
toss A
A
B
C
D
A
B
C
toss ?7 Faults
 Basic idea: we can’t look into the
future, but let’s look at past experience
to make a good guess.
 LRU: on replacement, remove the
page that has not been used for the
longest time in the past.
 Implementation: to really implement
this, we would need to time stamp
every reference, or maintain a stack
that’s updated on every reference.
This would be too costly.
 So, we can’t implement this exactly,
but we can try to approximate it.
 why is an approximate solution totally
acceptable?
This page was
most recently used.
This page
was least
recently
used.
Our “bet” is that pages
which you used recently
are ones which you will
use again (principle of
locality) and, by
implication, those that
you didn’t, you won’t.
 Various LRU approximations use the PTE reference bit.
 keep a counter for each page
 at regular intervals, do:
 for every page:
 if ref bit = 0, increment its counter
 if ref bit = 1, zero its counter
 zero the reference bit
 the counter will thus contain the number of intervals since the
last reference to the page.
 the page with the largest counter will be least recently used
one.
 If we don’t have a reference bit, we can simulate it
using the VALID bit and taking a few extra faults.
 therefore want impact when there is plenty of memory to
be low.
 Basic idea is to reflect the passage of time in
the actual data structures and sweeping
method.
 Arrange all of physical pages in a big circle (a
clock).
 A clock hand is used to select a good LRU
candidate:
 sweep through the pages in circular order like a
clock.
 if the ref bit is off, it’s a good page.
 else, turn the ref bit off and try next page.
 Arm moves quickly when pages are needed.
 Low overhead when plenty of memory
 If memory is big, “accuracy” of information
degrades.
 add in additional hands
P0
P1
P2
 In a multiprogramming system, we need a way to
allocate memory to the competing processes.
 Question is: how to determine how much memory to
give to each process?
 In a fixed-space algorithm each process is given a limit of
pages it can use; when it reaches its limit, it starts
replacing new faults with its own pages. This is called
local replacement.
 some processes may do well while others suffer.
 In variable-spaced algorithms, each process can grow or
shrink dynamically, displacing other process’ pages.
This is global replacement.
 one process can ruin it for the rest.
 Peter Denning defined the working set of a program as
a way to model the dynamic locality of a program in
execution.
 Definition:
WS(t,w) = {pages i s.t. i was referenced in the interval
(t,t-w)}
t is a time, w is the working set window, a backward
looking interval,measured in references.
 So, a page is in the WS only if it was referenced in the
last w references.
 The working set size is the number of pages in the
working set; i.e., the number of pages touched in the interval
(t, t-w).
 The working set size changes with program locality.
 during periods of poor locality, you reference more pages.
 so, within that period of time, you will have a larger working set size.
 For some parameter w, we could keep the working sets of each process in
memory.
 Don’t run process unless working set is in memory.
t
w
time
references
 But, we have two problems:
 how do we select w?
 how do we know when the working set changes?
 So, working set is not used in practice.
 PFF is a variable space
algorithm that uses a more
ad hoc approach.
 Basic idea:
 monitor the fault rate for each
process
 if the fault rate is above a high
threshold, give it more memory
 should fault less
 but it doesn’t always
 if the rate is below a low
threshold, take away memory
 should fault more
 but it doesn’t always
 Hard to tell between
changes in locality and
changes in size of working
set. TIME
Fault
Rate
 If the page is dirty, you have to write it out to disk.
 record the disk block number for the page in the PTE.
 If the page is clean, you don’t have to do anything.
 just overwrite the page with new data
 make sure you know where the old copy of the page came from
 Want to avoid THRASHING
 When a paging algorithm breaks down
 Most of the OS time spent in ferrying pages to and from disk
 no time spent doing useful work.
 the system is OVERCOMMITTED
 no idea what pages should be resident in order to run effectively
 Solutions include:
 SWAP
 Buy more memory
VM Page Replacement

Más contenido relacionado

Similar a VM Page Replacement

Memory management
Memory managementMemory management
Memory management
Rasi123
 
Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904
marangburu42
 

Similar a VM Page Replacement (20)

virtual memory Operating system
virtual memory Operating system virtual memory Operating system
virtual memory Operating system
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Ch09
Ch09Ch09
Ch09
 
Operating System
Operating SystemOperating System
Operating System
 
Os unit 2
Os unit 2Os unit 2
Os unit 2
 
Pge Replacement Algorithm.pdf
Pge Replacement Algorithm.pdfPge Replacement Algorithm.pdf
Pge Replacement Algorithm.pdf
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
Virtual Memory in Operating System
Virtual Memory in Operating SystemVirtual Memory in Operating System
Virtual Memory in Operating System
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
Memory management
Memory managementMemory management
Memory management
 
page replacement.pptx
page replacement.pptxpage replacement.pptx
page replacement.pptx
 
Virtual memory pre-final-formatting
Virtual memory pre-final-formattingVirtual memory pre-final-formatting
Virtual memory pre-final-formatting
 
STORAGE MANAGEMENT AND PAGING ALGORITHMS.pptx
STORAGE MANAGEMENT AND PAGING ALGORITHMS.pptxSTORAGE MANAGEMENT AND PAGING ALGORITHMS.pptx
STORAGE MANAGEMENT AND PAGING ALGORITHMS.pptx
 
Distributed Operating System_3
Distributed Operating System_3Distributed Operating System_3
Distributed Operating System_3
 
Virtual memory - Demand Paging
Virtual memory - Demand PagingVirtual memory - Demand Paging
Virtual memory - Demand Paging
 
LRU_Replacement-Policy.pdf
LRU_Replacement-Policy.pdfLRU_Replacement-Policy.pdf
LRU_Replacement-Policy.pdf
 
CSI-503 - 9. Virtual Memory
CSI-503 - 9. Virtual MemoryCSI-503 - 9. Virtual Memory
CSI-503 - 9. Virtual Memory
 
Page replacement
Page replacementPage replacement
Page replacement
 
Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904Virtualmemorypre final-formatting-161019022904
Virtualmemorypre final-formatting-161019022904
 

Más de sathish sak

Más de sathish sak (20)

TRANSPARENT CONCRE
TRANSPARENT CONCRETRANSPARENT CONCRE
TRANSPARENT CONCRE
 
Stationary Waves
Stationary WavesStationary Waves
Stationary Waves
 
Electrical Activity of the Heart
Electrical Activity of the HeartElectrical Activity of the Heart
Electrical Activity of the Heart
 
Electrical Activity of the Heart
Electrical Activity of the HeartElectrical Activity of the Heart
Electrical Activity of the Heart
 
Software process life cycles
Software process life cyclesSoftware process life cycles
Software process life cycles
 
Digital Logic Circuits
Digital Logic CircuitsDigital Logic Circuits
Digital Logic Circuits
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Scheduling
 
Real-Time Signal Processing: Implementation and Application
Real-Time Signal Processing:  Implementation and ApplicationReal-Time Signal Processing:  Implementation and Application
Real-Time Signal Processing: Implementation and Application
 
DIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEWDIGITAL SIGNAL PROCESSOR OVERVIEW
DIGITAL SIGNAL PROCESSOR OVERVIEW
 
FRACTAL ROBOTICS
FRACTAL  ROBOTICSFRACTAL  ROBOTICS
FRACTAL ROBOTICS
 
Electro bike
Electro bikeElectro bike
Electro bike
 
ROBOTIC SURGERY
ROBOTIC SURGERYROBOTIC SURGERY
ROBOTIC SURGERY
 
POWER GENERATION OF THERMAL POWER PLANT
POWER GENERATION OF THERMAL POWER PLANTPOWER GENERATION OF THERMAL POWER PLANT
POWER GENERATION OF THERMAL POWER PLANT
 
mathematics application fiels of engineering
mathematics application fiels of engineeringmathematics application fiels of engineering
mathematics application fiels of engineering
 
Plastics…
Plastics…Plastics…
Plastics…
 
ENGINEERING
ENGINEERINGENGINEERING
ENGINEERING
 
ENVIRONMENTAL POLLUTION
ENVIRONMENTALPOLLUTIONENVIRONMENTALPOLLUTION
ENVIRONMENTAL POLLUTION
 
RFID TECHNOLOGY
RFID TECHNOLOGYRFID TECHNOLOGY
RFID TECHNOLOGY
 
green chemistry
green chemistrygreen chemistry
green chemistry
 
NANOTECHNOLOGY
  NANOTECHNOLOGY	  NANOTECHNOLOGY
NANOTECHNOLOGY
 

Último

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

VM Page Replacement

  • 2.  Processes tend to reference pages in localized patterns  Temporal locality  locations referenced recently likely to be referenced again  Spatial locality  locations near recently referenced locations are likely to be referenced soon.  Goal of a paging system is  stay out of the way when there is plenty of available memory  don’t bring the system to its knees when there is not.
  • 3.  Demand Paging refers to a technique where program pages are loaded from disk into memory as they are referenced.  Each reference to a page not previously touched causes a page fault.  The fault occurs because the reference found a page table entry with its valid bit off.  As a result of the page fault, the OS allocates a new page frame and reads the faulted page from the disk.  When the I/O completes, the OS fills in the PTE, sets its valid bit, and restarts the faulting process.
  • 4.  Demand paging  don’t load page until absolutely necessary  commonly used in most systems  doing things one at a time can be slower than batching them.  Prepaging  anticipate fault before it happens  overlap fetch with computation  hard to predict the future  some simple schemes (hints from programmer or program behavior) can work.  vm_advise  larger “virtual” page size  sequential pre-paging from mapped files
  • 5.  Imagine that when a program starts, it has:  no pages in memory  a page table with all valid bits off  The first instruction to be executed faults, loading the first page.  Instructions fault until the program has enough pages to execute for a while.  It continues until the next page fault.  Faults are expensive, so once the program is running they should not occur frequently, assuming the program is “well behaved” (has good locality).
  • 6.  When a fault occurs, the OS loads the faulted page from disk into a page of memory.  At some point, the process has used all of the page frames it is allowed to use.  When this happens, the OS must replace a page for each page faulted in. That is, it must select a page to throw out of primary memory to make room.  How it does this is determined by the page replacement algorithm.  The goal of the replacement algorithm is to reduce the fault rate by selecting the best victim page to remove.
  • 7.  A good property  if you put more memory on the machine, then your page fault rate will go down.  Increasing the size of the resource pool helps everyone.  The best page to toss out is the one you’ll never need again  that way, no faults.  Never is a long time, so picking the one closest to “never” is the next best thing.  Replacing the page that won’t be used for the longest period of time absolutely minimizes the number of page faults.  Example:
  • 8.  The optimal algorithm, called Belady’s algorithm, has the lowest fault rate for any reference string.  Basic idea: replace the page that will not be used for the longest time in the future.  Basic problem: phone calls to psychics are expensive.  Basic use: gives us an idea of how well any implementable algorithm is doing relative to the best possible algorithm.  compare the fault rate of any proposed algorithm to Optimal  if Optimal does not do much better, then your proposed algorithm is pretty good.  If your proposed algorithm doesn’t do much better than Random, go home.
  • 9. Effective Access.Time = (1-p)*Tm + p*Td Tm = time to access main memory Td = time to fault Execution time = (roughly) #memory refs * E.A.T. # of physical page frames execution time Random LRU Opt Down in this range, it doesn’t matter so much what you do. In here, you can expect to have some effect. Up here, forget it. Few frames Lots of frames
  • 10.  FIFO is an obvious algorithm and simple to implement.  Basic idea, maintain a list or queue of pages in the order in which they were paged into memory.  On replacement, remove the one brought in the longest time ago.  Why might it work?  Maybe the one brought in the longest ago is one we’re not using now.  Why it might not work?  Maybe it’s not.  We have no real information to tell us if it’s being used or not.  FIFO suffers from “Belady’s anomaly”  the fault rate might actually increase when the algorithm is given more memory -- a bad property. This page was faulted recently This page was faulted a long time ago.
  • 11. Reference stream is A B C A B D A D B C OPTIMAL A B C A B D A D B C B toss A or Dtoss C5 Faults FIFO A B C A B D A D B C B toss A A B C D A B C toss ?7 Faults
  • 12.  Basic idea: we can’t look into the future, but let’s look at past experience to make a good guess.  LRU: on replacement, remove the page that has not been used for the longest time in the past.  Implementation: to really implement this, we would need to time stamp every reference, or maintain a stack that’s updated on every reference. This would be too costly.  So, we can’t implement this exactly, but we can try to approximate it.  why is an approximate solution totally acceptable? This page was most recently used. This page was least recently used. Our “bet” is that pages which you used recently are ones which you will use again (principle of locality) and, by implication, those that you didn’t, you won’t.
  • 13.  Various LRU approximations use the PTE reference bit.  keep a counter for each page  at regular intervals, do:  for every page:  if ref bit = 0, increment its counter  if ref bit = 1, zero its counter  zero the reference bit  the counter will thus contain the number of intervals since the last reference to the page.  the page with the largest counter will be least recently used one.  If we don’t have a reference bit, we can simulate it using the VALID bit and taking a few extra faults.  therefore want impact when there is plenty of memory to be low.
  • 14.  Basic idea is to reflect the passage of time in the actual data structures and sweeping method.  Arrange all of physical pages in a big circle (a clock).  A clock hand is used to select a good LRU candidate:  sweep through the pages in circular order like a clock.  if the ref bit is off, it’s a good page.  else, turn the ref bit off and try next page.  Arm moves quickly when pages are needed.  Low overhead when plenty of memory  If memory is big, “accuracy” of information degrades.  add in additional hands P0 P1 P2
  • 15.  In a multiprogramming system, we need a way to allocate memory to the competing processes.  Question is: how to determine how much memory to give to each process?  In a fixed-space algorithm each process is given a limit of pages it can use; when it reaches its limit, it starts replacing new faults with its own pages. This is called local replacement.  some processes may do well while others suffer.  In variable-spaced algorithms, each process can grow or shrink dynamically, displacing other process’ pages. This is global replacement.  one process can ruin it for the rest.
  • 16.  Peter Denning defined the working set of a program as a way to model the dynamic locality of a program in execution.  Definition: WS(t,w) = {pages i s.t. i was referenced in the interval (t,t-w)} t is a time, w is the working set window, a backward looking interval,measured in references.  So, a page is in the WS only if it was referenced in the last w references.
  • 17.  The working set size is the number of pages in the working set; i.e., the number of pages touched in the interval (t, t-w).  The working set size changes with program locality.  during periods of poor locality, you reference more pages.  so, within that period of time, you will have a larger working set size.  For some parameter w, we could keep the working sets of each process in memory.  Don’t run process unless working set is in memory. t w time references
  • 18.  But, we have two problems:  how do we select w?  how do we know when the working set changes?  So, working set is not used in practice.
  • 19.  PFF is a variable space algorithm that uses a more ad hoc approach.  Basic idea:  monitor the fault rate for each process  if the fault rate is above a high threshold, give it more memory  should fault less  but it doesn’t always  if the rate is below a low threshold, take away memory  should fault more  but it doesn’t always  Hard to tell between changes in locality and changes in size of working set. TIME Fault Rate
  • 20.  If the page is dirty, you have to write it out to disk.  record the disk block number for the page in the PTE.  If the page is clean, you don’t have to do anything.  just overwrite the page with new data  make sure you know where the old copy of the page came from  Want to avoid THRASHING  When a paging algorithm breaks down  Most of the OS time spent in ferrying pages to and from disk  no time spent doing useful work.  the system is OVERCOMMITTED  no idea what pages should be resident in order to run effectively  Solutions include:  SWAP  Buy more memory