Storage Management

• Page replacement- FIFO




                           1
Recap


In the last class, you have learnt

    Demand Paging
    Steps to handle page faults




                                     2
HOME     PREVIOUS TOPIC NEXT
PREVIOUS QUESTION PAPERS FOR OS
CPP TUTORIALS




                                  3
Objective


  On completion of this class, you will be able to

  know
• Concepts of Page Replacement

• FIFO page replacement algorithm




                                                     4
Page Replacement

• When a user process is executing, a page fault
  occurs
• The OS determines where the desired page is
  residing on the disk
• Finds that there are no free frames on the free-
  frame list
• All memory is in use Figure:1

                                                     5
Need For Page Replacement




         Figure: 1
                            6
Procedure to find free Frame:

• Page replacement – find some page in memory,
 which is not really in use & swap it out
  – In order to swap use one of the Page replacement
    algorithm
  – Select an algorithm which will result in minimum number
    of page faults & improves the performance

• Same page may be brought into memory several
 times
                                                          7
Basic Page Replacement

•       Find the location of the desired page on disk
•       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
•       Read the desired page into the (newly) free
        frame as shown in Fig: 2
•       Update the page and frame tables
•       Restart the process
                                                             8
Page Replacement




      Fig: 2
                   9
Page Replacement
• Prevent over-allocation of memory
• Include page replacement
• Use modify (dirty) bit to reduce overhead of
  page transfers
• Each page or a frame may have a modify bit
  associated with it in the hardware



                                                 10
Page Replacement
• Modify bit for a page is set by the hardware when a
  word or byte is written to page
• Only modified pages are written to disk
• Page replacement completes separation between
  logical memory and physical memory
• Large virtual memory can be provided on a smaller
  physical memory


                                                 11
Page Replacement Algorithm

 How to select the page replacement
  algorithm?
• The string of memory references is called
  reference string
• Evaluate the algorithm by running on a
  reference string and compute the number of
  page faults
• Select the one with lowest page-fault rate
                                               12
Page Replacement Algorithm

How to determine the no. of page faults?

• Need to have the knowledge of number of

  page frames available for a reference string

• As number of page frames increases the

  page faults will decrease


                                                 13
FIFO Replacement Algorithms

FIFO - First In First Out
• Simplest page replacement algorithm
• Replace the page that has been in primary
  memory the longest
• FIFO queue holds the pages in memory
• Replace the page at the head of the queue
• The new page is inserted at the tail of the queue
                                                  14
FIFO Page Replacement
• Page fault’s at 7,0,1,2,3,0,4,2,3,0,1,2,7,0,1 of
  reference string




                          Fig 3
                                                     15
FIFO

Example : 12
references, 9
faults




                       Fig 4   16
FIFO

 Disadvantages of FIFO algorithm
 Performance is not always good
 The page in active use is replaced for the new one
 This bad replacement choice increases the page
  faults
 To illustrate the problem consider the
 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

                                                         18
FIFO
   3 frames (3 pages can be in memory at
    a time per process)
                1   1    4 55
                         4
                2   2    1 33
                         1        9 page faults
                3   3    2 44
                         2

                        Fig 5
       4 frames

        1   1   5 44
                5
        2   2   1 55
                1        10 page faults
        3   3   2
                2

        4   4   3
                3

            Fig 6                                 19
Belady's Anomaly
• FIFO with 3 page frames Fig : 7 (a)
• FIFO with 4 page frames Fig : 7 (b)
• P's show which page references show page
  faults



                 Fig 7




                 Fig 7
                                             20
FIFO

 The result is unexpected and is known as

  Belady’s Anomaly

 For some page replacement algorithm

  Page-fault rate may increase as the no. of

  allocated frames increase


                                               21
Paging Behavior with Increasing
   Number of Page Frames




               Fig 8

                                  22
FIFO Illustrating Belady’s Anomaly




                 Fig 9
                                     23
Summary

 In this class, you have learnt
       Concepts of Page replacement
       FIFO algorithm




                                       24
Frequently Asked Questions

What is the need for page replacement?

How do you find a free frame?

What is dirty bit?

What is meant by page replacement?

Explain FIFO page replacement algorithm

                                          25
Quiz
1. Use _____________to reduce overhead of page
  transfers
 a) Segmentation
 b) Modify (dirty) bit
 c) None

2. Modify bit for a page is _____by the hardware when a
  word or byte is written to page
   a) Reset
   b) Hole
   c) set
   d) None
                                                          26
Quiz
3. ___________completes separation between logical
   memory and physical memory
a) Page number
b) MULTICS
c) Page replacement
d) None
4. Each page or a frame may have a
   ___________associated with it in the hardware
a) External fragmentation
b) modify bit
c) Compaction
d) None
                                                     27
Quiz

5. What is a Page?
a) Blocks of logical memory
b) Blocks of physical memory
c) Blocks of virtual memory
d) None

6. FIFO queue replaces the pages at
a) Head of queue
b) Tail of queue
c) Both
d) None
                                      28
Quiz
7. ___________completes separation between logical
   memory and physical memory
a) Page number
b) MULTICS
c) Page replacement
d) None
8. Each page or a frame may have a ___________associated
    with it in the hardware
a) External fragmentation
b) modify bit
c) Compaction
d) None
                                                     29
Other subject materials

•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home

41 page replacement fifo

  • 1.
    Storage Management • Pagereplacement- FIFO 1
  • 2.
    Recap In the lastclass, you have learnt Demand Paging Steps to handle page faults 2
  • 3.
    HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS 3
  • 4.
    Objective Oncompletion of this class, you will be able to know • Concepts of Page Replacement • FIFO page replacement algorithm 4
  • 5.
    Page Replacement • Whena user process is executing, a page fault occurs • The OS determines where the desired page is residing on the disk • Finds that there are no free frames on the free- frame list • All memory is in use Figure:1 5
  • 6.
    Need For PageReplacement Figure: 1 6
  • 7.
    Procedure to findfree Frame: • Page replacement – find some page in memory, which is not really in use & swap it out – In order to swap use one of the Page replacement algorithm – Select an algorithm which will result in minimum number of page faults & improves the performance • Same page may be brought into memory several times 7
  • 8.
    Basic Page Replacement • Find the location of the desired page on disk • 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 • Read the desired page into the (newly) free frame as shown in Fig: 2 • Update the page and frame tables • Restart the process 8
  • 9.
  • 10.
    Page Replacement • Preventover-allocation of memory • Include page replacement • Use modify (dirty) bit to reduce overhead of page transfers • Each page or a frame may have a modify bit associated with it in the hardware 10
  • 11.
    Page Replacement • Modifybit for a page is set by the hardware when a word or byte is written to page • Only modified pages are written to disk • Page replacement completes separation between logical memory and physical memory • Large virtual memory can be provided on a smaller physical memory 11
  • 12.
    Page Replacement Algorithm How to select the page replacement algorithm? • The string of memory references is called reference string • Evaluate the algorithm by running on a reference string and compute the number of page faults • Select the one with lowest page-fault rate 12
  • 13.
    Page Replacement Algorithm Howto determine the no. of page faults? • Need to have the knowledge of number of page frames available for a reference string • As number of page frames increases the page faults will decrease 13
  • 14.
    FIFO Replacement Algorithms FIFO- First In First Out • Simplest page replacement algorithm • Replace the page that has been in primary memory the longest • FIFO queue holds the pages in memory • Replace the page at the head of the queue • The new page is inserted at the tail of the queue 14
  • 15.
    FIFO Page Replacement •Page fault’s at 7,0,1,2,3,0,4,2,3,0,1,2,7,0,1 of reference string Fig 3 15
  • 16.
  • 18.
    FIFO Disadvantages ofFIFO algorithm  Performance is not always good  The page in active use is replaced for the new one  This bad replacement choice increases the page faults  To illustrate the problem consider the  Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 18
  • 19.
    FIFO  3 frames (3 pages can be in memory at a time per process) 1 1 4 55 4 2 2 1 33 1 9 page faults 3 3 2 44 2 Fig 5  4 frames 1 1 5 44 5 2 2 1 55 1 10 page faults 3 3 2 2 4 4 3 3 Fig 6 19
  • 20.
    Belady's Anomaly • FIFOwith 3 page frames Fig : 7 (a) • FIFO with 4 page frames Fig : 7 (b) • P's show which page references show page faults Fig 7 Fig 7 20
  • 21.
    FIFO  The resultis unexpected and is known as Belady’s Anomaly  For some page replacement algorithm Page-fault rate may increase as the no. of allocated frames increase 21
  • 22.
    Paging Behavior withIncreasing Number of Page Frames Fig 8 22
  • 23.
  • 24.
    Summary  In thisclass, you have learnt  Concepts of Page replacement  FIFO algorithm 24
  • 25.
    Frequently Asked Questions Whatis the need for page replacement? How do you find a free frame? What is dirty bit? What is meant by page replacement? Explain FIFO page replacement algorithm 25
  • 26.
    Quiz 1. Use _____________toreduce overhead of page transfers a) Segmentation b) Modify (dirty) bit c) None 2. Modify bit for a page is _____by the hardware when a word or byte is written to page a) Reset b) Hole c) set d) None 26
  • 27.
    Quiz 3. ___________completes separationbetween logical memory and physical memory a) Page number b) MULTICS c) Page replacement d) None 4. Each page or a frame may have a ___________associated with it in the hardware a) External fragmentation b) modify bit c) Compaction d) None 27
  • 28.
    Quiz 5. What isa Page? a) Blocks of logical memory b) Blocks of physical memory c) Blocks of virtual memory d) None 6. FIFO queue replaces the pages at a) Head of queue b) Tail of queue c) Both d) None 28
  • 29.
    Quiz 7. ___________completes separationbetween logical memory and physical memory a) Page number b) MULTICS c) Page replacement d) None 8. Each page or a frame may have a ___________associated with it in the hardware a) External fragmentation b) modify bit c) Compaction d) None 29
  • 30.
    Other subject materials • Web designing • Micro processors • C++ tutorials • java home