SlideShare a Scribd company logo
1 of 16
Download to read offline
Cache Replacement Policies,
Types of Cache Miss,
Writing Policies
Ms. Snehalata Agasti
CSE department
Cache replacement policies
 Cache memory size is very less comparative to main memory size.
 Processor fetches data from cache memory to perform execution operation.
 So when required block is not found within cache, then main memory block is transferred to cache and
previously present block is replaced.
 For that reason cache replacement algorithm is used.
 Page replacement policies are normally used in Set-associative and Fully-associative mapping.
 Different cache replacement policies are used.
➢ FIFO
➢ Optimal algorithm
➢ LRU
➢ MRU
➢ Pseudo LRU
FIFO(First In First Out)
 Memory block which referenced first , that block is replaced first.
 Let main memory references are given:- 1, 2, 3, 4, 1, 2, 3, 5, 6,7
 Number of blocks in cache memory=4
1
2
1
3
2
1
4
3
2
1
4
3
2
1
4
3
2
1
4
3
2
1
4
3
2
5
4
7
6
5
4
3
6
5
1 miss 2 miss 3 miss 2 hit
1 hit
4 miss 5 miss
3 hit 6 miss 7 miss
0
1
2
3
Hit ratio and Miss ratio using FIFO
 Total reference = 10
 Total number of hit = 3
 Total number of miss = 7
 Hit ratio = number of hit / total reference
=3/10=0.3
 %of hit ratio = 0.3 x100 = 30%
 Miss ratio = number of miss / total reference
=7/10=0.7
 %of miss ratio = 0.7 x100 = 70%
 Total probability=1. If hit ratio=0.3 then miss ratio= 1-0.3=0.7
Optimal page replacement algorithm
 The page which is not referenced in near future, that page is replaced.
 It has no practical implementation.
 But gives more efficiency.
 Used as reference model.
 Let memory reference is given :- 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 2
 Number of Cache block=4
7
0
7
1
0
7
2
1
0
7
2
1
0
7
2
1
0
3
2
1
0
3
2
4
0
3
2
4
0
3
2
4
0
3
0
1
2
3
7 miss 0 miss 1 miss 3 miss
0 hit
2 miss 4 miss
0 hit 2 hit
2
4
0
3
2
4
0
3
3 hit 0 hit 2hit
Hit ratio and miss ratio using optimal
replacement algorithm
 Total reference = 12
 Total number of hit = 6
 Total number of miss = 6
 Hit ratio = number of hit / total reference
=6/12=0.5
 %of hit ratio = 0.5 x100 = 50%
 Miss ratio = number of miss / total reference
=6/12=0.5
 %of miss ratio = 0.5 x100 = 50%
LRU(Least Recently Used)
 This algorithm replaces the cache memory block by main memory block, the block which
is least recently used.
 Let memory reference is given :- 7, 0, 1, 2, 0, 3, 5, 4, 2, 3, 0
 Number of Cache block=4
0
1
2
3
7
0
7
1
0
7
2
1
0
7
2
1
0
7
2
1
0
3
2
5
0
3
4
5
0
3
4
5
2
3
4
5
2
3
7 miss 0 miss 1 miss 3 miss
0 hit
2 miss 4 miss
5 miss 2 miss
4
0
2
3
3 hit 0 miss
Hit ratio and miss Ratio in LRU
 Total reference = 11
 Total number of hit = 2
 Total number of miss = 9
 Hit ratio = number of hit / total reference
=2/11= .18
 %of hit ratio = 0.,18 x100 = 18%
 Miss ratio = number of miss / total reference
=9/11=0.82
 %of miss ratio = 0.82 x100 = 82%
MRU(Most Recently Used)
 This algorithm replaces the cache memory block by main memory block, the block which
is least recently used.
 Let memory reference is given :- 7, 0, 1, 2, 0, 3 ,0, 5, 4, 3, 0
 Number of Cache block=4
7
0
7
1
0
7
2
1
0
7
2
1
0
7
2
1
3
7
2
1
0
7
2
1
5
7
2
1
3
7
2
1
4
7
7 miss 0 miss 1 miss 3 miss
0 hit
2miss 5 miss
0 miss 4 miss
2
1
0
7
3 miss 0 miss
Hit ratio and miss ratio using MRU
 Total reference = 11
 Total number of hit = 1
 Total number of miss = 10
 Hit ratio = number of hit / total reference
=1/11= o.09
 %of hit ratio = 0.09 x100 = 9%
 Miss ratio = number of miss / total reference
=10/11=0.9099=0.91
 %of miss ratio = 0.91 x100 = 91%
Types of Miss
 When some required block is searched inside cache memory and not found then that is
called miss in cache.
 There are 3-different types of miss occurs in cache memory.
➢ Compulsory miss
➢ Capacity miss
➢ Conflict miss
 Compulsory miss: Any main memory block is missed for very first time is called Compulsory
miss. It can be reduced by increasing the capacity of cache memory size.
Cont…
 Capacity miss: if cache block is full then capacity miss occurs. It can be reduced by
increasing the cache memory size.
 Conflict miss: if cache set is full and number of main memory block is mapped to same
tag, then conflict miss occurs. It can be reduced by increasing the associativity. Conflict
miss never occurs in fully-associative memory.
 Note: -
If number of set = 1, it is same as direct mapping.
Number of set =k implies only tag bits are present and same as fully-associative memory.
Writing policy
 If cache lines are not modified ,it needs updating using different writing policies.
 Two different writing policy is used. Write through Write back.
 Write Through: Data is updated simultaneously in cache memory as well as in main
memory.
 Consistent data is present.
 But consumes more time.
 Write back: data in cache is updated first and final value is updated in main memory.
 Less time consumes.
 But inconsistent data is present.
Examples of write through and write-back
policies
 Ex : for( i=0 ; i<10 ; i++)
Printf( i )
 Using write through technique ‘i’ value is updated in cache memory and in main memory,
but using write back policy cache memory is updated first then final value of ‘i’ is updated
in main memory.
i=01 2
3 4 5 6
7 8 9
10
i=0 1 2 3 4 5
6 7 8 9 10
i=01 2
3 4 5 6
7 8 9
10
i = 10
Write Through policy Write Back policy
Main memory
Main memory
Cache memory Cache memory
Cache coherence
 In multi processor system data is present in main memory along with local cache memory
of computer. It is required to update the data in all cache memory and in main memory.
This is called cache coherence.
 If data is not updated in some of the local cache that leads to inconsistency. This is called
cache coherence problem means synchronisation between local cache and shared
memory is lost.
Local
memory
CPU-1 CPU-2 CPU-3
Shared
Memory
Local
memory
Local
memory
Int x=5
Int x=5
Int x=5
Int x=5
Cache Replacement Algorithms and Policies Explained

More Related Content

What's hot

Types of instructions
Types of instructionsTypes of instructions
Types of instructionsihsanjamil
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Gaditek
 
Cache memoy designed by Mohd Tariq
Cache memoy designed by Mohd TariqCache memoy designed by Mohd Tariq
Cache memoy designed by Mohd TariqMohd Tariq
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memoryMazin Alwaaly
 
Computer registers
Computer registersComputer registers
Computer registersJatin Grover
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Cache memory
Cache memoryCache memory
Cache memoryAnuj Modi
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stackAsif Iqbal
 
INTEL 80386 MICROPROCESSOR
INTEL  80386  MICROPROCESSORINTEL  80386  MICROPROCESSOR
INTEL 80386 MICROPROCESSORAnnies Minu
 
Memory organization in computer architecture
Memory organization in computer architectureMemory organization in computer architecture
Memory organization in computer architectureFaisal Hussain
 
Memory organization
Memory organizationMemory organization
Memory organizationDhaval Bagal
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 

What's hot (20)

Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Registers
RegistersRegisters
Registers
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Cache memoy designed by Mohd Tariq
Cache memoy designed by Mohd TariqCache memoy designed by Mohd Tariq
Cache memoy designed by Mohd Tariq
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Computer registers
Computer registersComputer registers
Computer registers
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
Register organization, stack
Register organization, stackRegister organization, stack
Register organization, stack
 
INTEL 80386 MICROPROCESSOR
INTEL  80386  MICROPROCESSORINTEL  80386  MICROPROCESSOR
INTEL 80386 MICROPROCESSOR
 
Memory organization in computer architecture
Memory organization in computer architectureMemory organization in computer architecture
Memory organization in computer architecture
 
Memory mapping
Memory mappingMemory mapping
Memory mapping
 
Direct access memory
Direct access memoryDirect access memory
Direct access memory
 
Memory organization
Memory organizationMemory organization
Memory organization
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Cache memory
Cache memoryCache memory
Cache memory
 
memory hierarchy
memory hierarchymemory hierarchy
memory hierarchy
 
Associative memory
Associative memoryAssociative memory
Associative memory
 

Similar to Cache Replacement Algorithms and Policies Explained

High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer ArchitectureSubhasis Dash
 
Cache.pptx
Cache.pptxCache.pptx
Cache.pptxVCETCSE
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7wajanga
 
hierarchical memory technology.pptx
hierarchical memory technology.pptxhierarchical memory technology.pptx
hierarchical memory technology.pptx2105986
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptxRajapriya82
 
CPU Caching Concepts
CPU Caching ConceptsCPU Caching Concepts
CPU Caching ConceptsAbhijit K Rao
 
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013Neo4j
 
9.1-CSE3421-multicolumn-cache.pdf
9.1-CSE3421-multicolumn-cache.pdf9.1-CSE3421-multicolumn-cache.pdf
9.1-CSE3421-multicolumn-cache.pdfrishav957243
 
Memory allocation for real time operating system
Memory allocation for real time operating systemMemory allocation for real time operating system
Memory allocation for real time operating systemAsma'a Lafi
 
Cache memory and cache
Cache memory and cacheCache memory and cache
Cache memory and cacheVISHAL DONGA
 
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...Ilango Jeyasubramanian
 
Ways to reduce misses
Ways to reduce missesWays to reduce misses
Ways to reduce missesnellins
 

Similar to Cache Replacement Algorithms and Policies Explained (20)

High Performance Computer Architecture
High Performance Computer ArchitectureHigh Performance Computer Architecture
High Performance Computer Architecture
 
module3.ppt
module3.pptmodule3.ppt
module3.ppt
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
computer-memory
computer-memorycomputer-memory
computer-memory
 
Cache.pptx
Cache.pptxCache.pptx
Cache.pptx
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
 
hierarchical memory technology.pptx
hierarchical memory technology.pptxhierarchical memory technology.pptx
hierarchical memory technology.pptx
 
Unit 5-lecture-1
Unit 5-lecture-1Unit 5-lecture-1
Unit 5-lecture-1
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
CPU Caching Concepts
CPU Caching ConceptsCPU Caching Concepts
CPU Caching Concepts
 
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013
MySQL to Neo4j: A DBA Perspective - David Stern @ GraphConnect NY 2013
 
Cache memory
Cache  memoryCache  memory
Cache memory
 
Memory organisation
Memory organisationMemory organisation
Memory organisation
 
9.1-CSE3421-multicolumn-cache.pdf
9.1-CSE3421-multicolumn-cache.pdf9.1-CSE3421-multicolumn-cache.pdf
9.1-CSE3421-multicolumn-cache.pdf
 
cache memory
 cache memory cache memory
cache memory
 
Memory allocation for real time operating system
Memory allocation for real time operating systemMemory allocation for real time operating system
Memory allocation for real time operating system
 
Cache memory and cache
Cache memory and cacheCache memory and cache
Cache memory and cache
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...
DESIGNED DYNAMIC SEGMENTED LRU AND MODIFIED MOESI PROTOCOL FOR RING CONNECTED...
 
Ways to reduce misses
Ways to reduce missesWays to reduce misses
Ways to reduce misses
 

Recently uploaded

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 

Recently uploaded (20)

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 

Cache Replacement Algorithms and Policies Explained

  • 1. Cache Replacement Policies, Types of Cache Miss, Writing Policies Ms. Snehalata Agasti CSE department
  • 2. Cache replacement policies  Cache memory size is very less comparative to main memory size.  Processor fetches data from cache memory to perform execution operation.  So when required block is not found within cache, then main memory block is transferred to cache and previously present block is replaced.  For that reason cache replacement algorithm is used.  Page replacement policies are normally used in Set-associative and Fully-associative mapping.  Different cache replacement policies are used. ➢ FIFO ➢ Optimal algorithm ➢ LRU ➢ MRU ➢ Pseudo LRU
  • 3. FIFO(First In First Out)  Memory block which referenced first , that block is replaced first.  Let main memory references are given:- 1, 2, 3, 4, 1, 2, 3, 5, 6,7  Number of blocks in cache memory=4 1 2 1 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 1 4 3 2 5 4 7 6 5 4 3 6 5 1 miss 2 miss 3 miss 2 hit 1 hit 4 miss 5 miss 3 hit 6 miss 7 miss 0 1 2 3
  • 4. Hit ratio and Miss ratio using FIFO  Total reference = 10  Total number of hit = 3  Total number of miss = 7  Hit ratio = number of hit / total reference =3/10=0.3  %of hit ratio = 0.3 x100 = 30%  Miss ratio = number of miss / total reference =7/10=0.7  %of miss ratio = 0.7 x100 = 70%  Total probability=1. If hit ratio=0.3 then miss ratio= 1-0.3=0.7
  • 5. Optimal page replacement algorithm  The page which is not referenced in near future, that page is replaced.  It has no practical implementation.  But gives more efficiency.  Used as reference model.  Let memory reference is given :- 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 2  Number of Cache block=4 7 0 7 1 0 7 2 1 0 7 2 1 0 7 2 1 0 3 2 1 0 3 2 4 0 3 2 4 0 3 2 4 0 3 0 1 2 3 7 miss 0 miss 1 miss 3 miss 0 hit 2 miss 4 miss 0 hit 2 hit 2 4 0 3 2 4 0 3 3 hit 0 hit 2hit
  • 6. Hit ratio and miss ratio using optimal replacement algorithm  Total reference = 12  Total number of hit = 6  Total number of miss = 6  Hit ratio = number of hit / total reference =6/12=0.5  %of hit ratio = 0.5 x100 = 50%  Miss ratio = number of miss / total reference =6/12=0.5  %of miss ratio = 0.5 x100 = 50%
  • 7. LRU(Least Recently Used)  This algorithm replaces the cache memory block by main memory block, the block which is least recently used.  Let memory reference is given :- 7, 0, 1, 2, 0, 3, 5, 4, 2, 3, 0  Number of Cache block=4 0 1 2 3 7 0 7 1 0 7 2 1 0 7 2 1 0 7 2 1 0 3 2 5 0 3 4 5 0 3 4 5 2 3 4 5 2 3 7 miss 0 miss 1 miss 3 miss 0 hit 2 miss 4 miss 5 miss 2 miss 4 0 2 3 3 hit 0 miss
  • 8. Hit ratio and miss Ratio in LRU  Total reference = 11  Total number of hit = 2  Total number of miss = 9  Hit ratio = number of hit / total reference =2/11= .18  %of hit ratio = 0.,18 x100 = 18%  Miss ratio = number of miss / total reference =9/11=0.82  %of miss ratio = 0.82 x100 = 82%
  • 9. MRU(Most Recently Used)  This algorithm replaces the cache memory block by main memory block, the block which is least recently used.  Let memory reference is given :- 7, 0, 1, 2, 0, 3 ,0, 5, 4, 3, 0  Number of Cache block=4 7 0 7 1 0 7 2 1 0 7 2 1 0 7 2 1 3 7 2 1 0 7 2 1 5 7 2 1 3 7 2 1 4 7 7 miss 0 miss 1 miss 3 miss 0 hit 2miss 5 miss 0 miss 4 miss 2 1 0 7 3 miss 0 miss
  • 10. Hit ratio and miss ratio using MRU  Total reference = 11  Total number of hit = 1  Total number of miss = 10  Hit ratio = number of hit / total reference =1/11= o.09  %of hit ratio = 0.09 x100 = 9%  Miss ratio = number of miss / total reference =10/11=0.9099=0.91  %of miss ratio = 0.91 x100 = 91%
  • 11. Types of Miss  When some required block is searched inside cache memory and not found then that is called miss in cache.  There are 3-different types of miss occurs in cache memory. ➢ Compulsory miss ➢ Capacity miss ➢ Conflict miss  Compulsory miss: Any main memory block is missed for very first time is called Compulsory miss. It can be reduced by increasing the capacity of cache memory size.
  • 12. Cont…  Capacity miss: if cache block is full then capacity miss occurs. It can be reduced by increasing the cache memory size.  Conflict miss: if cache set is full and number of main memory block is mapped to same tag, then conflict miss occurs. It can be reduced by increasing the associativity. Conflict miss never occurs in fully-associative memory.  Note: - If number of set = 1, it is same as direct mapping. Number of set =k implies only tag bits are present and same as fully-associative memory.
  • 13. Writing policy  If cache lines are not modified ,it needs updating using different writing policies.  Two different writing policy is used. Write through Write back.  Write Through: Data is updated simultaneously in cache memory as well as in main memory.  Consistent data is present.  But consumes more time.  Write back: data in cache is updated first and final value is updated in main memory.  Less time consumes.  But inconsistent data is present.
  • 14. Examples of write through and write-back policies  Ex : for( i=0 ; i<10 ; i++) Printf( i )  Using write through technique ‘i’ value is updated in cache memory and in main memory, but using write back policy cache memory is updated first then final value of ‘i’ is updated in main memory. i=01 2 3 4 5 6 7 8 9 10 i=0 1 2 3 4 5 6 7 8 9 10 i=01 2 3 4 5 6 7 8 9 10 i = 10 Write Through policy Write Back policy Main memory Main memory Cache memory Cache memory
  • 15. Cache coherence  In multi processor system data is present in main memory along with local cache memory of computer. It is required to update the data in all cache memory and in main memory. This is called cache coherence.  If data is not updated in some of the local cache that leads to inconsistency. This is called cache coherence problem means synchronisation between local cache and shared memory is lost. Local memory CPU-1 CPU-2 CPU-3 Shared Memory Local memory Local memory Int x=5 Int x=5 Int x=5 Int x=5