SlideShare a Scribd company logo
1 of 34
Operating Systems


         Page Replacement
            Algorithms



               A. Frank - P. Weisberg
Virtual Memory Management
    •   Background
    •   Demand Paging
    •   Demand Segmentation
    •   Paging Considerations
    •   Page Replacement Algorithms
    •   Virtual Memory Policies

2                   A. Frank - P. Weisberg
Page Replacement Algorithms
    • Want lowest page-fault rate.
    • Evaluate algorithm by running it on a
      particular string of memory references
      (reference string) and computing the
      number of page faults and page
      replacements on that string.
    • In all our examples, we use a few
      recurring reference strings.
3                  A. Frank - P. Weisberg
Graph of Page Faults vs. the Number of Frames




4                  A. Frank - P. Weisberg
The FIFO Policy

    • Treats page frames allocated to a process
      as a circular buffer:
      – When the buffer is full, the oldest page is
        replaced. Hence first-in, first-out:
         • A frequently used page is often the oldest, so it
           will be repeatedly paged out by FIFO.
      – Simple to implement:
         • requires only a pointer that circles through the
           page frames of the process.
5                      A. Frank - P. Weisberg
FIFO Page Replacement




6       A. Frank - P. Weisberg
First-In-First-Out (FIFO) Algorithm
    • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
    • 3 frames (3 pages can be in memory 1 1 4                    5
                    at a time per process): 2 2 1                 3   9 page faults
                                                      3   3   2   4


    • 4 frames:                                       1   1   5   4
                                                      2   2   1   5   10 page faults
                                                      3   3   2

                                                      4   4   3

    • FIFO Replacement manifests Belady’s Anomaly:
       – more frames ⇒ more page faults
7                            A. Frank - P. Weisberg
FIFO Illustrating Belady’s Anomaly




8             A. Frank - P. Weisberg
Optimal Page Replacement

    • The Optimal policy selects for
      replacement the page that will not be used
      for longest period of time.
    • Impossible to implement (need to know
      the future) but serves as a standard to
      compare with the other algorithms we
      shall study.

9                   A. Frank - P. Weisberg
Optimal Page Replacement




10         A. Frank - P. Weisberg
Optimal Algorithm
     • Reference string : 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
     • 4 frames example
                                           1      4
                                           2          6 page faults
                                           3

                                           4      5



     • How do you know future use? You don’t!
     • Used for measuring how well your algorithm
       performs.
11                       A. Frank - P. Weisberg
The LRU Policy

     • Replaces the page that has not been
       referenced for the longest time:
       – By the principle of locality, this should be the
         page least likely to be referenced in the near
         future.
       – performs nearly as well as the optimal policy.



12
LRU Page Replacement




13       A. Frank - P. Weisberg
Least Recently Used (LRU) Algorithm
     • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

                  1   1   1     1     5
                  2   2   2     2     2
                                               8 page faults
                  3   5   5     4     4
                  4   4   3     3     3




14                         A. Frank - P. Weisberg
Comparison of OPT with LRU
     • Example: A process of 5 pages with an OS that
       fixes the resident set size to 3.




15
Comparison of FIFO with LRU




     • LRU recognizes that pages 2 and 5 are referenced
       more frequently than others but FIFO does not.
16                      A. Frank - P. Weisberg
Implementation of the LRU Policy
     • Each page could be tagged (in the page table entry)
       with the time at each memory reference.
     • The LRU 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 LRU
       replacement policy.
     • Other algorithms are used instead.
17                     A. Frank - P. Weisberg
LRU Implementations
     • Counter implementation:
        – Every page entry has a counter; every time a page is
          referenced through this entry, copy the clock into the
          counter.
        – When a page needs to be changed, look at the counters to
          determine which are to change.
     • Stack implementation – keep a stack of page numbers
       in a double link form:
        – Page referenced:
           • move it to the top
           • requires 6 pointers to be changed
        – No search for replacement.
18                         A. Frank - P. Weisberg
Use of a stack to implement LRU
     • Stack implementation – keep a stack of page numbers in a
       double link form:
        – Page referenced:
            • move it to the top
            • requires 6 pointers to be changed
        – No search for replacement – always take the bottom one.




19                            A. Frank - P. Weisberg
Hardware Matrix LRU Implementation
     Pages are referenced in the order 0, 1, 2, 3, 2, 1, 0, 3, 2, 3




20                            A. Frank - P. Weisberg
(LRU Approximation Algorithms (1
     • Reference Bit:
       – With each page associate a bit, initially = 0
       – When page is referenced, bit is set to 1.
       – Replace the one which is 0 (if one exists) –
         we do not know the real order of use, however.




21                      A. Frank - P. Weisberg
(LRU Approximation Algorithms (2
     • Reference Byte:
       – Idea is to record reference bits at regular intervals;
         Keep a byte of reference bits for each page.
       – At regular intervals (say, every 20 ms), left shift
         the reference bit of each page into the high-order
         bit of the byte.
       – Each reference byte keeps the history of the page
         use (aging) for the last eight time intervals.
       – If we interpret the reference byte as an unsigned
         integer, the page with the lowest number is the
         LRU page.
22                       A. Frank - P. Weisberg
Reference Byte Example




23        A. Frank - P. Weisberg
The Clock (Second Chance) Policy
     • 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 reference bit for each frame is set to 1 whenever:
        – a page is first loaded into the frame.
        – the corresponding page is referenced.
     • When it is time to replace a page, the first frame
       encountered with the reference bit set to 0 is replaced:
        – During the search for replacement, each reference bit
          set to 1 is changed to 0.

24                          A. Frank - P. Weisberg
Clock Page-Replacement Algorithm




25             A. Frank - P. Weisberg
The Clock Policy: Another Example




26             A. Frank - P. Weisberg
(Comparison of Clock with FIFO and LRU (1




     • Asterisk indicates that the corresponding use bit is set to 1.
     • The arrow indicates the current position of the pointer.
     • Note that the clock policy is adept at protecting frames 2 and 5
       from replacement.
27                          A. Frank - P. Weisberg
(Comparison of Clock with FIFO and LRU (2
     • Numerical experiments tend to show that performance
       of Clock is close to that of LRU.
     • 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:
        – When few (6 to 8) frames are allocated per process, there
          is almost a factor of 2 of page faults between LRU and
          FIFO.
        – This factor reduces close to 1 when several (more than
          12) frames are allocated. (But then more main memory is
          needed to support the same level of multiprogramming).
28                        A. Frank - P. Weisberg
Fixed-Allocation, Local Page Replacement




29                A. Frank - P. Weisberg
Counting-based Algorithms
     • Keep a counter of the number of references that
       have been made to each page.
     • Two possibilities: Least/Most Frequently Used
       (LFU/MFU).
     • LFU Algorithm: replaces page with smallest
       count; others were and will be used more.
     • MFU Algorithm: based on the argument that
       the page with the smallest count was probably
       just brought in and has yet to be used.
30                    A. Frank - P. Weisberg
(Page Buffering (1
     • Pages to be replaced are kept in main memory for a while to
       guard against poorly performing replacement algorithms such
       as FIFO.
     • Two lists of pointers are maintained: each entry points to a
       frame selected for replacement:
        – a free page list for frames that have not been modified since
          brought in (no need to swap out).
        – a modified page list for frames that have been modified (need to
          write them out).
     • A frame to be replaced has a pointer added to the tail of one of
       the lists and the present bit is cleared in corresponding page
       table entry; but the page remains in the same memory frame.
31                           A. Frank - P. Weisberg
(Page Buffering (2
     • At each page fault the two lists are first examined to see
       if the needed page is still in main memory:
        – If it is, we just need to set the present bit in the corresponding
          page table entry (and remove the matching entry in the
          relevant page list).
        – If it is not, then the needed page is brought in, it is placed in
          the frame pointed by the head of the free frame list
          (overwriting the page that was there); the head of the free
          frame list is moved to the next entry.
        – (the frame number in the page table entry could be used to
          scan the two lists, or each list entry could contain the process
          id and page number of the occupied frame).
     • The modified list also serves to write out modified
       pages in cluster (rather than individually).
32                           A. Frank - P. Weisberg
(Cleaning Policy (1
     • When should a modified page be written out to disk?
     • Demand cleaning:
        – a page is written out only when it’s frame has been
          selected for replacement
           • but a process that suffers a page fault may have to wait
             for 2 page transfers.
     • Pre-cleaning:
        – modified pages are written before their frames are
          needed so that they can be written out in batches:
           • but makes little sense to write out so many pages if the
             majority of them will be modified again before they are
             replaced.
33                         A. Frank - P. Weisberg
(Cleaning Policy (2
     • A good compromise can be achieved with page
       buffering:
       – recall that pages chosen for replacement are
         maintained either on a free (unmodified) list or on
         a modified list.
       – pages on the modified list can be periodically
         written out in batches and moved to the free list.
       – a good compromise since:
          • not all dirty pages are written out but only those chosen
            for replacement.
          • writing is done in batch.
34                        A. Frank - P. Weisberg

More Related Content

What's hot

Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmsPiyush Rochwani
 
Computer memory management
Computer memory managementComputer memory management
Computer memory managementKumar
 
Gestion de archivos
Gestion de archivosGestion de archivos
Gestion de archivosJulian Parra
 
Page Replacement Algorithms
Page Replacement AlgorithmsPage Replacement Algorithms
Page Replacement AlgorithmsKashif Dayo
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page tableduvvuru madhuri
 
Modelacion de algoritmo de paginacion
Modelacion de algoritmo de paginacionModelacion de algoritmo de paginacion
Modelacion de algoritmo de paginacionLuisFernandoCarranza
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basicSanoj Kumar
 
Operating system 37 demand paging
Operating system 37 demand pagingOperating system 37 demand paging
Operating system 37 demand pagingVaibhav Khanna
 
Distributed operating system amoeba case study
Distributed operating system  amoeba case studyDistributed operating system  amoeba case study
Distributed operating system amoeba case studyRamuAryan
 
Mca ii os u-1 introduction to os
Mca  ii  os u-1 introduction to osMca  ii  os u-1 introduction to os
Mca ii os u-1 introduction to osRai University
 
Máy tiện Mazak Mazatrol T2-T3
Máy tiện Mazak Mazatrol T2-T3Máy tiện Mazak Mazatrol T2-T3
Máy tiện Mazak Mazatrol T2-T3Technical VN
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43myrajendra
 
5.2.2. Memory Consistency Models.pptx
5.2.2. Memory Consistency Models.pptx5.2.2. Memory Consistency Models.pptx
5.2.2. Memory Consistency Models.pptxAnusuya123
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithmsMazin Alwaaly
 

What's hot (19)

Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Computer memory management
Computer memory managementComputer memory management
Computer memory management
 
Gestion de archivos
Gestion de archivosGestion de archivos
Gestion de archivos
 
Page Replacement Algorithms
Page Replacement AlgorithmsPage Replacement Algorithms
Page Replacement Algorithms
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
 
Modelacion de algoritmo de paginacion
Modelacion de algoritmo de paginacionModelacion de algoritmo de paginacion
Modelacion de algoritmo de paginacion
 
Memory management
Memory managementMemory management
Memory management
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basic
 
Operating system 37 demand paging
Operating system 37 demand pagingOperating system 37 demand paging
Operating system 37 demand paging
 
Cache memory
Cache memoryCache memory
Cache memory
 
Distributed operating system amoeba case study
Distributed operating system  amoeba case studyDistributed operating system  amoeba case study
Distributed operating system amoeba case study
 
Mca ii os u-1 introduction to os
Mca  ii  os u-1 introduction to osMca  ii  os u-1 introduction to os
Mca ii os u-1 introduction to os
 
Máy tiện Mazak Mazatrol T2-T3
Máy tiện Mazak Mazatrol T2-T3Máy tiện Mazak Mazatrol T2-T3
Máy tiện Mazak Mazatrol T2-T3
 
Memory management
Memory managementMemory management
Memory management
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Memory management
Memory managementMemory management
Memory management
 
5.2.2. Memory Consistency Models.pptx
5.2.2. Memory Consistency Models.pptx5.2.2. Memory Consistency Models.pptx
5.2.2. Memory Consistency Models.pptx
 
Computer architecture page replacement algorithms
Computer architecture page replacement algorithmsComputer architecture page replacement algorithms
Computer architecture page replacement algorithms
 

Viewers also liked

Viewers also liked (6)

Evaluation
EvaluationEvaluation
Evaluation
 
Excel Final Saved In A Power Point Presentation
Excel Final Saved In A Power Point PresentationExcel Final Saved In A Power Point Presentation
Excel Final Saved In A Power Point Presentation
 
Media evaluation
Media evaluationMedia evaluation
Media evaluation
 
Relationship-Based Top-K Concept Retrieval for Ontology Search
Relationship-Based Top-K Concept Retrieval for Ontology SearchRelationship-Based Top-K Concept Retrieval for Ontology Search
Relationship-Based Top-K Concept Retrieval for Ontology Search
 
Media evaluation
Media evaluationMedia evaluation
Media evaluation
 
Chemistry Matters Dioxin2016 Analytical Summary
Chemistry Matters Dioxin2016 Analytical SummaryChemistry Matters Dioxin2016 Analytical Summary
Chemistry Matters Dioxin2016 Analytical Summary
 

Similar to Bijendra

Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfHarika Pudugosula
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxSureshD94
 
Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Siddhi Viradiya
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithmMuhammad Mansoor Ul Haq
 
9 virtual memory management
9 virtual memory management9 virtual memory management
9 virtual memory managementDr. Loganathan R
 
Replacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cuReplacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cuPankajKumar790026
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifomyrajendra
 
Operating system 40 lru algorithm
Operating system 40 lru algorithmOperating system 40 lru algorithm
Operating system 40 lru algorithmVaibhav Khanna
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryrapunzel08
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkHKShab
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryWayne Jones Jnr
 

Similar to Bijendra (20)

Page replacement alg
Page replacement algPage replacement alg
Page replacement alg
 
Virtual memory
Virtual memory Virtual memory
Virtual memory
 
Segmentation and paging
Segmentation and paging Segmentation and paging
Segmentation and paging
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Comparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptxComparision of page replacement algorithms.pptx
Comparision of page replacement algorithms.pptx
 
O ssvv82014
O ssvv82014O ssvv82014
O ssvv82014
 
Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)Pagereplacement algorithm(computional concept)
Pagereplacement algorithm(computional concept)
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
 
9 virtual memory management
9 virtual memory management9 virtual memory management
9 virtual memory management
 
운영체제론 Ch10
운영체제론 Ch10운영체제론 Ch10
운영체제론 Ch10
 
Replacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cuReplacement.ppt operating system in BCA cu
Replacement.ppt operating system in BCA cu
 
Virtual Memory.pdf
Virtual Memory.pdfVirtual Memory.pdf
Virtual Memory.pdf
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
 
Ch09
Ch09Ch09
Ch09
 
page_fault pbm.ppt
page_fault pbm.pptpage_fault pbm.ppt
page_fault pbm.ppt
 
Operating system 40 lru algorithm
Operating system 40 lru algorithmOperating system 40 lru algorithm
Operating system 40 lru algorithm
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvkVirtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
Virtual Memory sjkdhikejv vsdkjnksnv vkjhfvk
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 

More from bijendra

More from bijendra (7)

resume formate
resume formateresume formate
resume formate
 
2pages 10
2pages 102pages 10
2pages 10
 
2pages 7
2pages 72pages 7
2pages 7
 
2pages 6
2pages 62pages 6
2pages 6
 
2pages 5
2pages 52pages 5
2pages 5
 
2pages 11
2pages 112pages 11
2pages 11
 
Job Portal
Job PortalJob Portal
Job Portal
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Bijendra

  • 1. Operating Systems Page Replacement Algorithms A. Frank - P. Weisberg
  • 2. Virtual Memory Management • Background • Demand Paging • Demand Segmentation • Paging Considerations • Page Replacement Algorithms • Virtual Memory Policies 2 A. Frank - P. Weisberg
  • 3. Page Replacement Algorithms • Want lowest page-fault rate. • Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults and page replacements on that string. • In all our examples, we use a few recurring reference strings. 3 A. Frank - P. Weisberg
  • 4. Graph of Page Faults vs. the Number of Frames 4 A. Frank - P. Weisberg
  • 5. The FIFO Policy • Treats page frames allocated to a process as a circular buffer: – When the buffer is full, the oldest page is replaced. Hence first-in, first-out: • A frequently used page is often the oldest, so it will be repeatedly paged out by FIFO. – Simple to implement: • requires only a pointer that circles through the page frames of the process. 5 A. Frank - P. Weisberg
  • 6. FIFO Page Replacement 6 A. Frank - P. Weisberg
  • 7. First-In-First-Out (FIFO) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • 3 frames (3 pages can be in memory 1 1 4 5 at a time per process): 2 2 1 3 9 page faults 3 3 2 4 • 4 frames: 1 1 5 4 2 2 1 5 10 page faults 3 3 2 4 4 3 • FIFO Replacement manifests Belady’s Anomaly: – more frames ⇒ more page faults 7 A. Frank - P. Weisberg
  • 8. FIFO Illustrating Belady’s Anomaly 8 A. Frank - P. Weisberg
  • 9. Optimal Page Replacement • The Optimal policy selects for replacement the page that will not be used for longest period of time. • Impossible to implement (need to know the future) but serves as a standard to compare with the other algorithms we shall study. 9 A. Frank - P. Weisberg
  • 10. Optimal Page Replacement 10 A. Frank - P. Weisberg
  • 11. Optimal Algorithm • Reference string : 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 • 4 frames example 1 4 2 6 page faults 3 4 5 • How do you know future use? You don’t! • Used for measuring how well your algorithm performs. 11 A. Frank - P. Weisberg
  • 12. The LRU Policy • Replaces the page that has not been referenced for the longest time: – By the principle of locality, this should be the page least likely to be referenced in the near future. – performs nearly as well as the optimal policy. 12
  • 13. LRU Page Replacement 13 A. Frank - P. Weisberg
  • 14. Least Recently Used (LRU) Algorithm • Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 1 1 1 5 2 2 2 2 2 8 page faults 3 5 5 4 4 4 4 3 3 3 14 A. Frank - P. Weisberg
  • 15. Comparison of OPT with LRU • Example: A process of 5 pages with an OS that fixes the resident set size to 3. 15
  • 16. Comparison of FIFO with LRU • LRU recognizes that pages 2 and 5 are referenced more frequently than others but FIFO does not. 16 A. Frank - P. Weisberg
  • 17. Implementation of the LRU Policy • Each page could be tagged (in the page table entry) with the time at each memory reference. • The LRU 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 LRU replacement policy. • Other algorithms are used instead. 17 A. Frank - P. Weisberg
  • 18. LRU Implementations • Counter implementation: – Every page entry has a counter; every time a page is referenced through this entry, copy the clock into the counter. – When a page needs to be changed, look at the counters to determine which are to change. • Stack implementation – keep a stack of page numbers in a double link form: – Page referenced: • move it to the top • requires 6 pointers to be changed – No search for replacement. 18 A. Frank - P. Weisberg
  • 19. Use of a stack to implement LRU • Stack implementation – keep a stack of page numbers in a double link form: – Page referenced: • move it to the top • requires 6 pointers to be changed – No search for replacement – always take the bottom one. 19 A. Frank - P. Weisberg
  • 20. Hardware Matrix LRU Implementation Pages are referenced in the order 0, 1, 2, 3, 2, 1, 0, 3, 2, 3 20 A. Frank - P. Weisberg
  • 21. (LRU Approximation Algorithms (1 • Reference Bit: – With each page associate a bit, initially = 0 – When page is referenced, bit is set to 1. – Replace the one which is 0 (if one exists) – we do not know the real order of use, however. 21 A. Frank - P. Weisberg
  • 22. (LRU Approximation Algorithms (2 • Reference Byte: – Idea is to record reference bits at regular intervals; Keep a byte of reference bits for each page. – At regular intervals (say, every 20 ms), left shift the reference bit of each page into the high-order bit of the byte. – Each reference byte keeps the history of the page use (aging) for the last eight time intervals. – If we interpret the reference byte as an unsigned integer, the page with the lowest number is the LRU page. 22 A. Frank - P. Weisberg
  • 23. Reference Byte Example 23 A. Frank - P. Weisberg
  • 24. The Clock (Second Chance) Policy • 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 reference bit for each frame is set to 1 whenever: – a page is first loaded into the frame. – the corresponding page is referenced. • When it is time to replace a page, the first frame encountered with the reference bit set to 0 is replaced: – During the search for replacement, each reference bit set to 1 is changed to 0. 24 A. Frank - P. Weisberg
  • 25. Clock Page-Replacement Algorithm 25 A. Frank - P. Weisberg
  • 26. The Clock Policy: Another Example 26 A. Frank - P. Weisberg
  • 27. (Comparison of Clock with FIFO and LRU (1 • Asterisk indicates that the corresponding use bit is set to 1. • The arrow indicates the current position of the pointer. • Note that the clock policy is adept at protecting frames 2 and 5 from replacement. 27 A. Frank - P. Weisberg
  • 28. (Comparison of Clock with FIFO and LRU (2 • Numerical experiments tend to show that performance of Clock is close to that of LRU. • 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: – When few (6 to 8) frames are allocated per process, there is almost a factor of 2 of page faults between LRU and FIFO. – This factor reduces close to 1 when several (more than 12) frames are allocated. (But then more main memory is needed to support the same level of multiprogramming). 28 A. Frank - P. Weisberg
  • 29. Fixed-Allocation, Local Page Replacement 29 A. Frank - P. Weisberg
  • 30. Counting-based Algorithms • Keep a counter of the number of references that have been made to each page. • Two possibilities: Least/Most Frequently Used (LFU/MFU). • LFU Algorithm: replaces page with smallest count; others were and will be used more. • MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used. 30 A. Frank - P. Weisberg
  • 31. (Page Buffering (1 • Pages to be replaced are kept in main memory for a while to guard against poorly performing replacement algorithms such as FIFO. • Two lists of pointers are maintained: each entry points to a frame selected for replacement: – a free page list for frames that have not been modified since brought in (no need to swap out). – a modified page list for frames that have been modified (need to write them out). • A frame to be replaced has a pointer added to the tail of one of the lists and the present bit is cleared in corresponding page table entry; but the page remains in the same memory frame. 31 A. Frank - P. Weisberg
  • 32. (Page Buffering (2 • At each page fault the two lists are first examined to see if the needed page is still in main memory: – If it is, we just need to set the present bit in the corresponding page table entry (and remove the matching entry in the relevant page list). – If it is not, then the needed page is brought in, it is placed in the frame pointed by the head of the free frame list (overwriting the page that was there); the head of the free frame list is moved to the next entry. – (the frame number in the page table entry could be used to scan the two lists, or each list entry could contain the process id and page number of the occupied frame). • The modified list also serves to write out modified pages in cluster (rather than individually). 32 A. Frank - P. Weisberg
  • 33. (Cleaning Policy (1 • When should a modified page be written out to disk? • Demand cleaning: – a page is written out only when it’s frame has been selected for replacement • but a process that suffers a page fault may have to wait for 2 page transfers. • Pre-cleaning: – modified pages are written before their frames are needed so that they can be written out in batches: • but makes little sense to write out so many pages if the majority of them will be modified again before they are replaced. 33 A. Frank - P. Weisberg
  • 34. (Cleaning Policy (2 • A good compromise can be achieved with page buffering: – recall that pages chosen for replacement are maintained either on a free (unmodified) list or on a modified list. – pages on the modified list can be periodically written out in batches and moved to the free list. – a good compromise since: • not all dirty pages are written out but only those chosen for replacement. • writing is done in batch. 34 A. Frank - P. Weisberg