Virtual memory is a technique that is used to execute
processes that are not in main memory completely. The
remaining part are placed on the backing storage.
Demand paging
It is a technique that is used to bring a page into memory only
when it is needed.
 Page is needed  reference to it
 Referenced page not in real memory  Page Fault
 Just not in memory  Demand paging
 Find free frame
 Swap page into frame
 Reset tables to indicate page now in memory
 Restart the instruction that caused the page fault
“Page replacement completes separation between logical
memory and physical memory large virtual memory can be
provided on a smaller physical memory”
 It terminates the program immediately
Or
 Swaps out program & frees all of its frames
 It reduces the degree of multiprogramming
Steps performed by OS while replacing a page upon a page
fault:
1. Find the location of the desired page on disk
2. Find a free frame:
If there is a free frame, use it
If there is no free frame, use a page replacement algorithm
to select a victim frame; if the victim page is modified, write it
back to disk.
3. Bring the desired page into the (new) free frame; update the
page and frame tables
4. Restart the process
 Want lowest page-fault rate on both first access and re-
access
 There is particular string of memory references.
 String is just page numbers, not full addresses
 Repeated access to the same page does not cause a
page fault
 Results depend on number of frames available
 In all our examples, the reference string of referenced
page numbers is
7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
 Oldest page in main memory is the one which will be
selected for replacement
 Easy to implement, keep a list, replace pages from the tail
and add new pages at the head.
 Adding more frames can cause more page
faults!
 Belady’s Anomaly
15 page faults
 Replace page that will not be used for longest period of time
 How do you know this?
 Used for measuring how well your algorithm performs
 Use past knowledge rather than future
 Replace page that has not been used in the most amount of time
 12 faults – better than FIFO but worse than OPT
 Generally good algorithm and frequently used
With each page associate a bit, initially= 0
When page is referenced bit set to 1
 This Algorithm is a FIFO replacement algorithm wit
consideration given to the reference bit .when a page
has been selected for replacement , its reference bit is
inspected .
 When a page is given a second chance its reference bit
is cleared and its arrival time reset to the current time
 Improve algorithm by using reference bit and modify bit (if
available) in concert
1. (0, 0) neither recently used not modified – best page to
replace
2. (0, 1) not recently used but modified – not quite as good,
must write out before replacement
3. (1, 0) recently used but clean – probably will be used
again soon
4. (1, 1) recently used and modified – probably will be used
again soon and need to write out before replacement
 Each process needs minimum number of pages
 Various allocation approaches
› fixed allocation
› global allocation
› local 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
m
S
s
pa
m
sS
ps
i
ii
i
ii





forallocation
framesofnumbertotal
processofsize
Example:
5964
137
127
564
137
10
127
10
64
2
1
2





a
a
s
s
m
i
 When a page fault occurs for a process and we need page
replacement, there are two general approaches:
› Global replacement – select a victim frame from the
set of all frames;
 one process can take a frame from another
› Local replacement – select a victim frame only from
the frames allocated to the process.
 A process uses always its allocated frames
 At some time , the processor may be spend most of its
time swapping pages and doing little productive work, this
is known as Thrashing.
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system
virtual memory Operating system

virtual memory Operating system

  • 2.
    Virtual memory isa technique that is used to execute processes that are not in main memory completely. The remaining part are placed on the backing storage. Demand paging It is a technique that is used to bring a page into memory only when it is needed.
  • 3.
     Page isneeded  reference to it  Referenced page not in real memory  Page Fault  Just not in memory  Demand paging  Find free frame  Swap page into frame  Reset tables to indicate page now in memory  Restart the instruction that caused the page fault
  • 4.
    “Page replacement completesseparation between logical memory and physical memory large virtual memory can be provided on a smaller physical memory”
  • 5.
     It terminatesthe program immediately Or  Swaps out program & frees all of its frames  It reduces the degree of multiprogramming
  • 6.
    Steps performed byOS while replacing a page upon a page fault: 1. Find the location of the desired page on disk 2. Find a free frame: If there is a free frame, use it If there is no free frame, use a page replacement algorithm to select a victim frame; if the victim page is modified, write it back to disk. 3. Bring the desired page into the (new) free frame; update the page and frame tables 4. Restart the process
  • 7.
     Want lowestpage-fault rate on both first access and re- access  There is particular string of memory references.  String is just page numbers, not full addresses  Repeated access to the same page does not cause a page fault  Results depend on number of frames available  In all our examples, the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
  • 8.
     Oldest pagein main memory is the one which will be selected for replacement  Easy to implement, keep a list, replace pages from the tail and add new pages at the head.
  • 9.
     Adding moreframes can cause more page faults!  Belady’s Anomaly 15 page faults
  • 11.
     Replace pagethat will not be used for longest period of time  How do you know this?  Used for measuring how well your algorithm performs
  • 12.
     Use pastknowledge rather than future  Replace page that has not been used in the most amount of time
  • 13.
     12 faults– better than FIFO but worse than OPT  Generally good algorithm and frequently used
  • 14.
    With each pageassociate a bit, initially= 0 When page is referenced bit set to 1
  • 16.
     This Algorithmis a FIFO replacement algorithm wit consideration given to the reference bit .when a page has been selected for replacement , its reference bit is inspected .  When a page is given a second chance its reference bit is cleared and its arrival time reset to the current time
  • 17.
     Improve algorithmby using reference bit and modify bit (if available) in concert 1. (0, 0) neither recently used not modified – best page to replace 2. (0, 1) not recently used but modified – not quite as good, must write out before replacement 3. (1, 0) recently used but clean – probably will be used again soon 4. (1, 1) recently used and modified – probably will be used again soon and need to write out before replacement
  • 18.
     Each processneeds minimum number of pages  Various allocation approaches › fixed allocation › global allocation › local allocation
  • 19.
     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 m S s pa m sS ps i ii i ii      forallocation framesofnumbertotal processofsize Example: 5964 137 127 564 137 10 127 10 64 2 1 2      a a s s m i
  • 20.
     When apage fault occurs for a process and we need page replacement, there are two general approaches: › Global replacement – select a victim frame from the set of all frames;  one process can take a frame from another › Local replacement – select a victim frame only from the frames allocated to the process.  A process uses always its allocated frames
  • 21.
     At sometime , the processor may be spend most of its time swapping pages and doing little productive work, this is known as Thrashing.