SlideShare a Scribd company logo
1 of 30
P R E S E N T E D B Y
A H S A N A S H F A Q
B C S ( H O N S ) F R O M U O P ( G O L D M E D A L I S T )
( 2 0 0 8 - 2 0 1 1 )
M S S C H O L A R I N I M | S C I E N C E S P E S H A W A R
( 2 0 1 3 - 2 0 1 5 )
CACHE MEMORY
STRUCTURE, ORGANIZATION AND MAPPING
MAJOR ACHIEVEMENTS
• Gold Medalist from University Of Peshawar.
• Course : BCS (Hons)
• Session : 2008 to 2011
• CGPA : 3.9/4.0
• 3rd Position in Computer Science Group in Board of
Intermediate and Secondary Education Peshawar.
• Course : FSc Computer Science
• Session : 2006-2007
• Marks : 901/1100
2
CONTENTS
• Memory Hierarchy
• Background
• Working of Cache Memory
• Structure and Organization
• Reference of Locality
• Mapping Techniques
• Direct
• Associative
• Set Associative
• Write Policies
• Cache Misses and its types
• Solution for Cache Misses
3Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
MEMORY HIERARCHY
4Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
BACKGROUND
• Main Memory provides data to Processor for
Processing.
• Difference between the speed of Processor and Main
Memory.
• Processor being the Main Resource can not be utilized fully.
5Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
CACHE MEMORY
• Cache Memory is used in order to achieve higher
performance of CPU by allowing the CPU to access
data at faster speed.
6Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
HOW CACHE WORKS ?
7Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
CACHE OPERATION
• CPU requests contents of memory location
• Check cache for this data
• If present, get from cache (fast)
• If not present, read required block from main
memory to cache
• Question : Why a Block is transferred ?
8Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
REFERENCE OF LOCALITY
• Spatial vs. Temporal
Temporal : Recently referenced items are likely to be
references in near future.
Spatial : Items with near by addresses tend to be referenced
close together in time.
9Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
CACHE/MAIN MEMORY STRUCTURE
10Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
TYPICAL CACHE ORGANIZATION
11Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
CACHE ADDRESSING
• Where does cache sit?
• Between processor and virtual memory management unit
• Between MMU and main memory
• Logical cache (virtual cache) stores data using virtual
addresses
• Processor accesses cache directly, not thorough physical
cache
• Cache access faster, before MMU address translation
• Virtual addresses use same address space for different
applications
• Must flush cache on each context switch
• Physical cache stores data using main memory physical
addresses
12Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
MAPPING FUNCTION
• Number of Blocks (M) in the main Memory is quite
large then the Number of Lines (m) in the cache
Memory i.e. m<M.
• So we need a Mapping Function.
• Direct Mapping
• Associative Mapping
• Set Associative Mapping
13Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
DIRECT MAPPING
• Each block of Main Memory can be mapped to a
specific line of Cache.
• If we want a block we will check its present in a
specific line.
• Mapping Function is
• i=j module m
• i=Cache Line number
• J=Main memory Block
• m=Total lines in Cache
14Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
DIRECT MAPPING CACHE
ORGANIZATION
15Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
DIRECT MAPPING ADDRESS FORMAT
2w = Words in a Block
2S = Total blocks in MM
2r = Total lines in Cache
16Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
DIRECT MAPPING PROS & CONS
• Simple
• Inexpensive
• Fixed location for given block
• If a program accesses 2 blocks that map to the same line
repeatedly, cache misses are very high
17Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
ASSOCIATIVE MAPPING
• A main memory block can load into any line of
cache
• Memory address is interpreted as tag and word
• Tag uniquely identifies block of memory
• Every line’s tag is examined for a match
• Cache searching gets expensive
18Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
FULLY ASSOCIATIVE CACHE
ORGANIZATION
19Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
ASSOCIATIVE MAPPING ADDRESS
FORMAT
Tag 22 bit
Word
2 bit
s w
Address Length=(s+w) bits
2w = Words in a Block/Line
2S = Total blocks in MM
Number of Lines in Cache=Undefined
20Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
ASSOCIATIVE MAPPING PROS & CONS
• Associative mapping result in high memory
utilization.
• Less Efficient search criteria
• Search is expensive in terms of price and performance.
21Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
SET ASSOCIATIVE MAPPING
• Cache is divided into a number of sets
• Each set contains a number of lines
• Between MM Block and Cache Set Mapping is
direct and inside Set its Associative.
• Mapping Function
• Set # = Block # module Total Sets
• e.g. 2 lines per set
• 2 way associative mapping
• A given block can be in one of 2 lines in only one set
22Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
SET-ASSOCIATIVE MAPPING
ADDRESS FORMAT
Address Length=(s+w) bits
2w = Words in a Block/Line
2r = Total sets in cache
wrs-r
23Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
K-WAY SET ASSOCIATIVE CACHE
ORGANIZATION
24
REPLACEMENT ALGORITHMS
ASSOCIATIVE & SET ASSOCIATIVE
• Least Recently used (LRU)
• e.g. in 2 way set associative
• Which of the 2 block is lru?
• First in first out (FIFO)
• replace block that has been in cache longest
• Least frequently used
• replace block which has had fewest hits
• Random
25Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
WRITE POLICY
• Must not overwrite a cache block unless main
memory is up to date
• Multiple CPUs may have individual caches
• I/O may address main memory directly
26Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
WRITE THROUGH
• All writes go to main memory as well as cache
• Multiple CPUs can monitor main memory traffic to
keep local (to CPU) cache up to date
• Lots of traffic
• Slows down writes
27Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
WRITE BACK
• Updates initially made in cache only
• Update bit for cache slot is set when update occurs
• If block is to be replaced, write to main memory
only if update bit is set
• I/O must access main memory through cache
28Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
CACHE MISSES
• Compulsory Misses
• Capacity Misses
• Conflict Misses
Solution
Miss Cache
Victim Cache
Prefetching
29Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
Discussions ??
30Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar

More Related Content

What's hot

Memory management ppt
Memory management pptMemory management ppt
Memory management pptManishaJha43
 
Storage management in operating system
Storage management in operating systemStorage management in operating system
Storage management in operating systemDeepikaT13
 
Multiprocessor
MultiprocessorMultiprocessor
MultiprocessorNeel Patel
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)Sandesh Jonchhe
 
External memory - Computer Architecture
External memory - Computer ArchitectureExternal memory - Computer Architecture
External memory - Computer ArchitectureBretz Harllynne Moltio
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memoryMazin Alwaaly
 
Multiprocessor Architecture (Advanced computer architecture)
Multiprocessor Architecture  (Advanced computer architecture)Multiprocessor Architecture  (Advanced computer architecture)
Multiprocessor Architecture (Advanced computer architecture)vani261
 
Memory technology and optimization in Advance Computer Architechture
Memory technology and optimization in Advance Computer ArchitechtureMemory technology and optimization in Advance Computer Architechture
Memory technology and optimization in Advance Computer ArchitechtureShweta Ghate
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memoryDeepak John
 
Elements of cache design
Elements of cache designElements of cache design
Elements of cache designRohail Butt
 
Computer System Basics
Computer System BasicsComputer System Basics
Computer System Basicspathumbee
 

What's hot (20)

Memory management ppt
Memory management pptMemory management ppt
Memory management ppt
 
Storage management in operating system
Storage management in operating systemStorage management in operating system
Storage management in operating system
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
Memory management
Memory managementMemory management
Memory management
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)
 
Bus aribration
Bus aribrationBus aribration
Bus aribration
 
External memory - Computer Architecture
External memory - Computer ArchitectureExternal memory - Computer Architecture
External memory - Computer Architecture
 
Memory types
Memory typesMemory types
Memory types
 
Computer architecture virtual memory
Computer architecture virtual memoryComputer architecture virtual memory
Computer architecture virtual memory
 
Multiprocessor Architecture (Advanced computer architecture)
Multiprocessor Architecture  (Advanced computer architecture)Multiprocessor Architecture  (Advanced computer architecture)
Multiprocessor Architecture (Advanced computer architecture)
 
Memory technology and optimization in Advance Computer Architechture
Memory technology and optimization in Advance Computer ArchitechtureMemory technology and optimization in Advance Computer Architechture
Memory technology and optimization in Advance Computer Architechture
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
 
Elements of cache design
Elements of cache designElements of cache design
Elements of cache design
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Cache memory
Cache memoryCache memory
Cache memory
 
File organisation
File organisationFile organisation
File organisation
 
File system
File systemFile system
File system
 
Computer System Basics
Computer System BasicsComputer System Basics
Computer System Basics
 
Buses in a computer
Buses in a computerBuses in a computer
Buses in a computer
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 

Viewers also liked

Viewers also liked (17)

cache memory
cache memorycache memory
cache memory
 
Coa swetappt copy
Coa swetappt   copyCoa swetappt   copy
Coa swetappt copy
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
Memory mapping techniques and low power memory design
Memory mapping techniques and low power memory designMemory mapping techniques and low power memory design
Memory mapping techniques and low power memory design
 
How Motherboards Work
How Motherboards WorkHow Motherboards Work
How Motherboards Work
 
Windows Utilities
Windows UtilitiesWindows Utilities
Windows Utilities
 
Memory organisation ppt final presentation
Memory organisation ppt final presentationMemory organisation ppt final presentation
Memory organisation ppt final presentation
 
Computer architecture
Computer architecture Computer architecture
Computer architecture
 
Computer organization
Computer organizationComputer organization
Computer organization
 
Cache memory
Cache memoryCache memory
Cache memory
 
Central Processing Unit
Central Processing UnitCentral Processing Unit
Central Processing Unit
 
Cpu and its functions
Cpu and its functionsCpu and its functions
Cpu and its functions
 
08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)08. Central Processing Unit (CPU)
08. Central Processing Unit (CPU)
 
Cpu presentation
Cpu presentationCpu presentation
Cpu presentation
 
History of CPU Architecture
History of CPU ArchitectureHistory of CPU Architecture
History of CPU Architecture
 
Cache memory presentation
Cache memory presentationCache memory presentation
Cache memory presentation
 
Address mapping
Address mappingAddress mapping
Address mapping
 

Similar to Cache memory

Cache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.pptCache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.pptrularofclash69
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchyAJAL A J
 
cache memory introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, functionTeddyIswahyudi1
 
Computer architecture for HNDIT
Computer architecture for HNDITComputer architecture for HNDIT
Computer architecture for HNDITtjunicornfx
 
coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxRuhul Amin
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.pptShiva340703
 
Cache Memory.ppt
Cache Memory.pptCache Memory.ppt
Cache Memory.pptAmarDura2
 
04 cache memory.ppt 1
04 cache memory.ppt 104 cache memory.ppt 1
04 cache memory.ppt 1Anwal Mirza
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystemSandeep Kamath
 

Similar to Cache memory (20)

04 cache memory
04 cache memory04 cache memory
04 cache memory
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 
cache memory
cache memorycache memory
cache memory
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
Cache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.pptCache Memory for Computer Architecture.ppt
Cache Memory for Computer Architecture.ppt
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
cache memory introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, function
 
Computer architecture for HNDIT
Computer architecture for HNDITComputer architecture for HNDIT
Computer architecture for HNDIT
 
CAO-Unit-III.pptx
CAO-Unit-III.pptxCAO-Unit-III.pptx
CAO-Unit-III.pptx
 
coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.ppt
 
Cache Memory.ppt
Cache Memory.pptCache Memory.ppt
Cache Memory.ppt
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.ppt
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.ppt
 
04 cache memory.ppt 1
04 cache memory.ppt 104 cache memory.ppt 1
04 cache memory.ppt 1
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
 
Ct213 memory subsystem
Ct213 memory subsystemCt213 memory subsystem
Ct213 memory subsystem
 

Recently uploaded

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
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
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 

Recently uploaded (20)

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
★ 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
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
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 )
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 

Cache memory

  • 1. P R E S E N T E D B Y A H S A N A S H F A Q B C S ( H O N S ) F R O M U O P ( G O L D M E D A L I S T ) ( 2 0 0 8 - 2 0 1 1 ) M S S C H O L A R I N I M | S C I E N C E S P E S H A W A R ( 2 0 1 3 - 2 0 1 5 ) CACHE MEMORY STRUCTURE, ORGANIZATION AND MAPPING
  • 2. MAJOR ACHIEVEMENTS • Gold Medalist from University Of Peshawar. • Course : BCS (Hons) • Session : 2008 to 2011 • CGPA : 3.9/4.0 • 3rd Position in Computer Science Group in Board of Intermediate and Secondary Education Peshawar. • Course : FSc Computer Science • Session : 2006-2007 • Marks : 901/1100 2
  • 3. CONTENTS • Memory Hierarchy • Background • Working of Cache Memory • Structure and Organization • Reference of Locality • Mapping Techniques • Direct • Associative • Set Associative • Write Policies • Cache Misses and its types • Solution for Cache Misses 3Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 4. MEMORY HIERARCHY 4Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 5. BACKGROUND • Main Memory provides data to Processor for Processing. • Difference between the speed of Processor and Main Memory. • Processor being the Main Resource can not be utilized fully. 5Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 6. CACHE MEMORY • Cache Memory is used in order to achieve higher performance of CPU by allowing the CPU to access data at faster speed. 6Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 7. HOW CACHE WORKS ? 7Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 8. CACHE OPERATION • CPU requests contents of memory location • Check cache for this data • If present, get from cache (fast) • If not present, read required block from main memory to cache • Question : Why a Block is transferred ? 8Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 9. REFERENCE OF LOCALITY • Spatial vs. Temporal Temporal : Recently referenced items are likely to be references in near future. Spatial : Items with near by addresses tend to be referenced close together in time. 9Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 10. CACHE/MAIN MEMORY STRUCTURE 10Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 11. TYPICAL CACHE ORGANIZATION 11Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 12. CACHE ADDRESSING • Where does cache sit? • Between processor and virtual memory management unit • Between MMU and main memory • Logical cache (virtual cache) stores data using virtual addresses • Processor accesses cache directly, not thorough physical cache • Cache access faster, before MMU address translation • Virtual addresses use same address space for different applications • Must flush cache on each context switch • Physical cache stores data using main memory physical addresses 12Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 13. MAPPING FUNCTION • Number of Blocks (M) in the main Memory is quite large then the Number of Lines (m) in the cache Memory i.e. m<M. • So we need a Mapping Function. • Direct Mapping • Associative Mapping • Set Associative Mapping 13Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 14. DIRECT MAPPING • Each block of Main Memory can be mapped to a specific line of Cache. • If we want a block we will check its present in a specific line. • Mapping Function is • i=j module m • i=Cache Line number • J=Main memory Block • m=Total lines in Cache 14Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 15. DIRECT MAPPING CACHE ORGANIZATION 15Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 16. DIRECT MAPPING ADDRESS FORMAT 2w = Words in a Block 2S = Total blocks in MM 2r = Total lines in Cache 16Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 17. DIRECT MAPPING PROS & CONS • Simple • Inexpensive • Fixed location for given block • If a program accesses 2 blocks that map to the same line repeatedly, cache misses are very high 17Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 18. ASSOCIATIVE MAPPING • A main memory block can load into any line of cache • Memory address is interpreted as tag and word • Tag uniquely identifies block of memory • Every line’s tag is examined for a match • Cache searching gets expensive 18Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 19. FULLY ASSOCIATIVE CACHE ORGANIZATION 19Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 20. ASSOCIATIVE MAPPING ADDRESS FORMAT Tag 22 bit Word 2 bit s w Address Length=(s+w) bits 2w = Words in a Block/Line 2S = Total blocks in MM Number of Lines in Cache=Undefined 20Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 21. ASSOCIATIVE MAPPING PROS & CONS • Associative mapping result in high memory utilization. • Less Efficient search criteria • Search is expensive in terms of price and performance. 21Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 22. SET ASSOCIATIVE MAPPING • Cache is divided into a number of sets • Each set contains a number of lines • Between MM Block and Cache Set Mapping is direct and inside Set its Associative. • Mapping Function • Set # = Block # module Total Sets • e.g. 2 lines per set • 2 way associative mapping • A given block can be in one of 2 lines in only one set 22Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 23. SET-ASSOCIATIVE MAPPING ADDRESS FORMAT Address Length=(s+w) bits 2w = Words in a Block/Line 2r = Total sets in cache wrs-r 23Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 24. K-WAY SET ASSOCIATIVE CACHE ORGANIZATION 24
  • 25. REPLACEMENT ALGORITHMS ASSOCIATIVE & SET ASSOCIATIVE • Least Recently used (LRU) • e.g. in 2 way set associative • Which of the 2 block is lru? • First in first out (FIFO) • replace block that has been in cache longest • Least frequently used • replace block which has had fewest hits • Random 25Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 26. WRITE POLICY • Must not overwrite a cache block unless main memory is up to date • Multiple CPUs may have individual caches • I/O may address main memory directly 26Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 27. WRITE THROUGH • All writes go to main memory as well as cache • Multiple CPUs can monitor main memory traffic to keep local (to CPU) cache up to date • Lots of traffic • Slows down writes 27Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 28. WRITE BACK • Updates initially made in cache only • Update bit for cache slot is set when update occurs • If block is to be replaced, write to main memory only if update bit is set • I/O must access main memory through cache 28Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 29. CACHE MISSES • Compulsory Misses • Capacity Misses • Conflict Misses Solution Miss Cache Victim Cache Prefetching 29Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar
  • 30. Discussions ?? 30Cache Memory By Ahsan Ashfaq MS Scholar, IM|Sciences Peshawar