SlideShare a Scribd company logo
Computer Organization
and Architecture
Cache Memory
Location
• CPU
• Internal
• External
Memory Hierarchy
• Registers
—In CPU
• Internal or Main memory
—May include one or more levels of cache
—“RAM”
• External memory
—Backing store
Memory Hierarchy - Diagram
Performance
• Access time
—Time between presenting the address and
getting the valid data
• Memory Cycle time
—Time may be required for the memory to
“recover” before next access
—Cycle time is access + recovery
• Transfer Rate
—Rate at which data can be moved
Hierarchy List
• Registers
• L1 Cache
• L2 Cache
• Main memory
• Disk cache
• Disk
• Optical
• Tape
Cache
• Small amount of fast memory
• Sits between normal main memory and
CPU
• May be located on CPU chip or module
Cache and Main Memory
Cache/Main Memory Structure
Cache operation – overview
• 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
• Then deliver from cache to CPU
• Cache includes tags to identify which
block of main memory is in each cache
slot
Cache Read Operation - Flowchart
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
Mapping Function
• Cache of 64kByte
• Cache block of 4 bytes
—i.e. cache is 16k (214
) lines of 4 bytes
• 16MBytes main memory
• 24 bit address
—(224
=16M)
Direct Mapping
• Each block of main memory maps to only
one cache line
—i.e. if a block is in cache, it must be in one
specific place
• Address is in two parts
• Least Significant w bits identify unique
word
• Most Significant s bits specify one memory
block
• The MSBs are split into a cache line field r
and a tag of s-r (most significant)
Direct Mapping
Address Structure
Tag s-r Line or Slot r Word w
8 14 2
• 24 bit address
• 2 bit word identifier (4 byte block)
• 22 bit block identifier
— 8 bit tag (=22-14)
— 14 bit slot or line
• No two blocks in the same line have the same Tag field
• Check contents of cache by finding line and checking Tag
Direct Mapping from Cache to Main Memory
Direct Mapping
Cache Line Table
Cache line Main Memory blocks held
0 0, m, 2m, 3m…2s-m
1 1,m+1, 2m+1…2s-m+1
…
m-1 m-1, 2m-1,3m-1…2s-1
Direct Mapping Cache Organization
Direct Mapping Summary
• Address length = (s + w) bits
• Number of addressable units = 2s+w
words
or bytes
• Block size = line size = 2w
words or bytes
• Number of blocks in main memory
= 2s+ w
/2w
= 2s
• Number of lines in cache = m = 2r
• Size of tag = (s – r) bits
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
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
Associative Mapping from
Cache to Main Memory
Fully Associative Cache Organization
Tag 22 bit
Word
2 bit
Associative Mapping
Address Structure
• 22 bit tag stored with each 32 bit block of data
• Compare tag field with tag entry in cache to
check for hit
• Least significant 2 bits of address identify which
16 bit word is required from 32 bit data block
• e.g.
—Address Tag Data Cache
line
—FFFFFC FFFFFC24682468 3FFF
Associative Mapping Summary
• Address length = (s + w) bits
• Number of addressable units = 2s+w
words
or bytes
• Block size = line size = 2w
words or bytes
• Number of blocks in main memory
= 2s+ w
/2w
= 2s
• Number of lines in cache = undetermined
• Size of tag = s bits
Set Associative Mapping
• Cache is divided into a number of sets
• Each set contains a number of lines
• A given block maps to any line in a given
set
—e.g. Block B can be in any line of set i
• e.g. 2 lines per set
—2 way associative mapping
—A given block can be in one of 2 lines in only
one set
Set Associative Mapping
Example
• 13 bit set number
• Block number in main memory is modulo
213
• 000000, 00A000, 00B000, 00C000 … map
to same set
Mapping From Main Memory to Cache:
v Associative
Mapping From Main Memory to Cache:
k-way Associative
K-Way Set Associative Cache
Organization
Set Associative Mapping
Address Structure
• Use set field to determine cache set to
look in
• Compare tag field to see if we have a hit
• e.g
—Address Tag Data Set
number
—1FF 7FFC 1FF 12345678 1FFF
—001 7FFC 001 11223344 1FFF
Tag 9 bit Set 13 bit
Word
2 bit
Set Associative Mapping Summary
• Address length = (s + w) bits
• Number of addressable units = 2s+w
words
or bytes
• Block size = line size = 2w
words or bytes
• Number of blocks in main memory = 2d
• Number of lines in set = k
• Number of sets = v = 2d
• Number of lines in cache = kv = k * 2d
• Size of tag = (s – d) bits
Replacement Algorithms (1)
Direct mapping
• No choice
• Each block only maps to one line
• Replace that line
Replacement Algorithms (2)
Associative & Set Associative
• Hardware implemented algorithm (speed)
• 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
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
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
• Remember bogus write through caches!
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
• Other caches get out of sync
• I/O must access main memory through
cache
• N.B. 15% of memory references are
writes
Multilevel Caches
• High logic density enables caches on chip
—Faster than bus access
—Frees bus for other transfers
• Common to use both on and off chip
cache
—L1 on chip, L2 off chip in static RAM
—L2 access much faster than DRAM or ROM
—L2 often uses separate data path
—L2 may now be on chip
—Resulting in L3 cache
– Bus access or now on chip…
Unified v Split Caches
• One cache for data and instructions or
two, one for data and one for instructions
• Advantages of unified cache
—Higher hit rate
– Balances load of instruction and data fetch
– Only one cache to design & implement
• Advantages of split cache
—Eliminates cache contention between
instruction fetch/decode unit and execution
unit
– Important in pipelining
Ad

More Related Content

Similar to Cache Memory from Computer Architecture.ppt (20)

04_Cache Memory-computer-architecture.ppt
04_Cache Memory-computer-architecture.ppt04_Cache Memory-computer-architecture.ppt
04_Cache Memory-computer-architecture.ppt
ssuser39f59e
 
04 cache memory.ppt 1
04 cache memory.ppt 104 cache memory.ppt 1
04 cache memory.ppt 1
Anwal Mirza
 
Detailed representation of Cache Memory.
Detailed representation of Cache Memory.Detailed representation of Cache Memory.
Detailed representation of Cache Memory.
ananya195642
 
04_Cache_Memory_William _Stallings_COA.ppt
04_Cache_Memory_William _Stallings_COA.ppt04_Cache_Memory_William _Stallings_COA.ppt
04_Cache_Memory_William _Stallings_COA.ppt
maheeeesharma
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
Inshad Arshad
 
04 cache memory
04 cache memory04 cache memory
04 cache memory
Faisal Hayat
 
cache memory introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, function
TeddyIswahyudi1
 
Chache memory ( chapter number 4 ) by William stalling
Chache memory ( chapter number 4 ) by William stallingChache memory ( chapter number 4 ) by William stalling
Chache memory ( chapter number 4 ) by William stalling
ZainabShahzad9
 
total cache memory is here.please read this for better knowledge
total cache memory is here.please read this for better knowledgetotal cache memory is here.please read this for better knowledge
total cache memory is here.please read this for better knowledge
JoysreeNandy
 
04_Cache_Memory-cust memori memori memori.ppt
04_Cache_Memory-cust memori memori memori.ppt04_Cache_Memory-cust memori memori memori.ppt
04_Cache_Memory-cust memori memori memori.ppt
TeddyIswahyudi1
 
CAO-Unit-III.pptx
CAO-Unit-III.pptxCAO-Unit-III.pptx
CAO-Unit-III.pptx
ClassicFUKRA
 
Akanskaha_ganesh_kullarni_memory_computer.ppt
Akanskaha_ganesh_kullarni_memory_computer.pptAkanskaha_ganesh_kullarni_memory_computer.ppt
Akanskaha_ganesh_kullarni_memory_computer.ppt
akankshakulkarni141
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.ppt
Shiva340703
 
cache memory
 cache memory cache memory
cache memory
NAHID HASAN
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
MUNAZARAZZAQELEA
 
cache memory.ppt
cache memory.pptcache memory.ppt
cache memory.ppt
MUNAZARAZZAQELEA
 
Cache memory
Cache memoryCache memory
Cache memory
Muhammad Ishaq
 
Cache memory
Cache memoryCache memory
Cache memory
Muhammad Ishaq
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
Budditha Hettige
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
sathish sak
 
04_Cache Memory-computer-architecture.ppt
04_Cache Memory-computer-architecture.ppt04_Cache Memory-computer-architecture.ppt
04_Cache Memory-computer-architecture.ppt
ssuser39f59e
 
04 cache memory.ppt 1
04 cache memory.ppt 104 cache memory.ppt 1
04 cache memory.ppt 1
Anwal Mirza
 
Detailed representation of Cache Memory.
Detailed representation of Cache Memory.Detailed representation of Cache Memory.
Detailed representation of Cache Memory.
ananya195642
 
04_Cache_Memory_William _Stallings_COA.ppt
04_Cache_Memory_William _Stallings_COA.ppt04_Cache_Memory_William _Stallings_COA.ppt
04_Cache_Memory_William _Stallings_COA.ppt
maheeeesharma
 
cache memory introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, function
TeddyIswahyudi1
 
Chache memory ( chapter number 4 ) by William stalling
Chache memory ( chapter number 4 ) by William stallingChache memory ( chapter number 4 ) by William stalling
Chache memory ( chapter number 4 ) by William stalling
ZainabShahzad9
 
total cache memory is here.please read this for better knowledge
total cache memory is here.please read this for better knowledgetotal cache memory is here.please read this for better knowledge
total cache memory is here.please read this for better knowledge
JoysreeNandy
 
04_Cache_Memory-cust memori memori memori.ppt
04_Cache_Memory-cust memori memori memori.ppt04_Cache_Memory-cust memori memori memori.ppt
04_Cache_Memory-cust memori memori memori.ppt
TeddyIswahyudi1
 
Akanskaha_ganesh_kullarni_memory_computer.ppt
Akanskaha_ganesh_kullarni_memory_computer.pptAkanskaha_ganesh_kullarni_memory_computer.ppt
Akanskaha_ganesh_kullarni_memory_computer.ppt
akankshakulkarni141
 
04_Cache Memory.ppt
04_Cache Memory.ppt04_Cache Memory.ppt
04_Cache Memory.ppt
Shiva340703
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
Budditha Hettige
 

More from ArifatunNesa (8)

CH13-COA10e update Addressing mode of instruction.pptx
CH13-COA10e update Addressing mode of instruction.pptxCH13-COA10e update Addressing mode of instruction.pptx
CH13-COA10e update Addressing mode of instruction.pptx
ArifatunNesa
 
Computer Security- Lecture-11 Security Attacks.pptx
Computer Security- Lecture-11 Security Attacks.pptxComputer Security- Lecture-11 Security Attacks.pptx
Computer Security- Lecture-11 Security Attacks.pptx
ArifatunNesa
 
cryptography-and-network-security-behrouz-ch01-slides.pptx
cryptography-and-network-security-behrouz-ch01-slides.pptxcryptography-and-network-security-behrouz-ch01-slides.pptx
cryptography-and-network-security-behrouz-ch01-slides.pptx
ArifatunNesa
 
Computer Security- Lecture-03 Overview of Cryptography.pptx
Computer Security- Lecture-03 Overview of Cryptography.pptxComputer Security- Lecture-03 Overview of Cryptography.pptx
Computer Security- Lecture-03 Overview of Cryptography.pptx
ArifatunNesa
 
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
ArifatunNesa
 
Lecture 4_Linear & Binary search from data structure and algorithm
Lecture 4_Linear & Binary search from data structure and algorithmLecture 4_Linear & Binary search from data structure and algorithm
Lecture 4_Linear & Binary search from data structure and algorithm
ArifatunNesa
 
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheralLecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
ArifatunNesa
 
Arduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
ArifatunNesa
 
CH13-COA10e update Addressing mode of instruction.pptx
CH13-COA10e update Addressing mode of instruction.pptxCH13-COA10e update Addressing mode of instruction.pptx
CH13-COA10e update Addressing mode of instruction.pptx
ArifatunNesa
 
Computer Security- Lecture-11 Security Attacks.pptx
Computer Security- Lecture-11 Security Attacks.pptxComputer Security- Lecture-11 Security Attacks.pptx
Computer Security- Lecture-11 Security Attacks.pptx
ArifatunNesa
 
cryptography-and-network-security-behrouz-ch01-slides.pptx
cryptography-and-network-security-behrouz-ch01-slides.pptxcryptography-and-network-security-behrouz-ch01-slides.pptx
cryptography-and-network-security-behrouz-ch01-slides.pptx
ArifatunNesa
 
Computer Security- Lecture-03 Overview of Cryptography.pptx
Computer Security- Lecture-03 Overview of Cryptography.pptxComputer Security- Lecture-03 Overview of Cryptography.pptx
Computer Security- Lecture-03 Overview of Cryptography.pptx
ArifatunNesa
 
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
1618962066755_Lesson_02_Sura_Asor and objective pronouns_40 slides (1).pptx
ArifatunNesa
 
Lecture 4_Linear & Binary search from data structure and algorithm
Lecture 4_Linear & Binary search from data structure and algorithmLecture 4_Linear & Binary search from data structure and algorithm
Lecture 4_Linear & Binary search from data structure and algorithm
ArifatunNesa
 
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheralLecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
Lecture-05(Mouse Tecnology).pptx.pdf on Computer peripheral
ArifatunNesa
 
Arduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagramArduino microcontroller ins and outs with pin diagram
Arduino microcontroller ins and outs with pin diagram
ArifatunNesa
 
Ad

Recently uploaded (20)

Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Compiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptxCompiler Design_Syntax Directed Translation.pptx
Compiler Design_Syntax Directed Translation.pptx
RushaliDeshmukh2
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Ad

Cache Memory from Computer Architecture.ppt

  • 3. Memory Hierarchy • Registers —In CPU • Internal or Main memory —May include one or more levels of cache —“RAM” • External memory —Backing store
  • 5. Performance • Access time —Time between presenting the address and getting the valid data • Memory Cycle time —Time may be required for the memory to “recover” before next access —Cycle time is access + recovery • Transfer Rate —Rate at which data can be moved
  • 6. Hierarchy List • Registers • L1 Cache • L2 Cache • Main memory • Disk cache • Disk • Optical • Tape
  • 7. Cache • Small amount of fast memory • Sits between normal main memory and CPU • May be located on CPU chip or module
  • 8. Cache and Main Memory
  • 10. Cache operation – overview • 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 • Then deliver from cache to CPU • Cache includes tags to identify which block of main memory is in each cache slot
  • 11. Cache Read Operation - Flowchart
  • 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
  • 13. Mapping Function • Cache of 64kByte • Cache block of 4 bytes —i.e. cache is 16k (214 ) lines of 4 bytes • 16MBytes main memory • 24 bit address —(224 =16M)
  • 14. Direct Mapping • Each block of main memory maps to only one cache line —i.e. if a block is in cache, it must be in one specific place • Address is in two parts • Least Significant w bits identify unique word • Most Significant s bits specify one memory block • The MSBs are split into a cache line field r and a tag of s-r (most significant)
  • 15. Direct Mapping Address Structure Tag s-r Line or Slot r Word w 8 14 2 • 24 bit address • 2 bit word identifier (4 byte block) • 22 bit block identifier — 8 bit tag (=22-14) — 14 bit slot or line • No two blocks in the same line have the same Tag field • Check contents of cache by finding line and checking Tag
  • 16. Direct Mapping from Cache to Main Memory
  • 17. Direct Mapping Cache Line Table Cache line Main Memory blocks held 0 0, m, 2m, 3m…2s-m 1 1,m+1, 2m+1…2s-m+1 … m-1 m-1, 2m-1,3m-1…2s-1
  • 18. Direct Mapping Cache Organization
  • 19. Direct Mapping Summary • Address length = (s + w) bits • Number of addressable units = 2s+w words or bytes • Block size = line size = 2w words or bytes • Number of blocks in main memory = 2s+ w /2w = 2s • Number of lines in cache = m = 2r • Size of tag = (s – r) bits
  • 20. 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
  • 21. 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
  • 23. Fully Associative Cache Organization
  • 24. Tag 22 bit Word 2 bit Associative Mapping Address Structure • 22 bit tag stored with each 32 bit block of data • Compare tag field with tag entry in cache to check for hit • Least significant 2 bits of address identify which 16 bit word is required from 32 bit data block • e.g. —Address Tag Data Cache line —FFFFFC FFFFFC24682468 3FFF
  • 25. Associative Mapping Summary • Address length = (s + w) bits • Number of addressable units = 2s+w words or bytes • Block size = line size = 2w words or bytes • Number of blocks in main memory = 2s+ w /2w = 2s • Number of lines in cache = undetermined • Size of tag = s bits
  • 26. Set Associative Mapping • Cache is divided into a number of sets • Each set contains a number of lines • A given block maps to any line in a given set —e.g. Block B can be in any line of set i • e.g. 2 lines per set —2 way associative mapping —A given block can be in one of 2 lines in only one set
  • 27. Set Associative Mapping Example • 13 bit set number • Block number in main memory is modulo 213 • 000000, 00A000, 00B000, 00C000 … map to same set
  • 28. Mapping From Main Memory to Cache: v Associative
  • 29. Mapping From Main Memory to Cache: k-way Associative
  • 30. K-Way Set Associative Cache Organization
  • 31. Set Associative Mapping Address Structure • Use set field to determine cache set to look in • Compare tag field to see if we have a hit • e.g —Address Tag Data Set number —1FF 7FFC 1FF 12345678 1FFF —001 7FFC 001 11223344 1FFF Tag 9 bit Set 13 bit Word 2 bit
  • 32. Set Associative Mapping Summary • Address length = (s + w) bits • Number of addressable units = 2s+w words or bytes • Block size = line size = 2w words or bytes • Number of blocks in main memory = 2d • Number of lines in set = k • Number of sets = v = 2d • Number of lines in cache = kv = k * 2d • Size of tag = (s – d) bits
  • 33. Replacement Algorithms (1) Direct mapping • No choice • Each block only maps to one line • Replace that line
  • 34. Replacement Algorithms (2) Associative & Set Associative • Hardware implemented algorithm (speed) • 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
  • 35. 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
  • 36. 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 • Remember bogus write through caches!
  • 37. 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 • Other caches get out of sync • I/O must access main memory through cache • N.B. 15% of memory references are writes
  • 38. Multilevel Caches • High logic density enables caches on chip —Faster than bus access —Frees bus for other transfers • Common to use both on and off chip cache —L1 on chip, L2 off chip in static RAM —L2 access much faster than DRAM or ROM —L2 often uses separate data path —L2 may now be on chip —Resulting in L3 cache – Bus access or now on chip…
  • 39. Unified v Split Caches • One cache for data and instructions or two, one for data and one for instructions • Advantages of unified cache —Higher hit rate – Balances load of instruction and data fetch – Only one cache to design & implement • Advantages of split cache —Eliminates cache contention between instruction fetch/decode unit and execution unit – Important in pipelining