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

More Related Content

PPT
cache memory
PPT
04 cache memory
PPT
Ch_4.pptInnovation technology pptInnovation technology ppt
PDF
unit 4.faosdfjasl;dfkjas lskadfj asdlfk jasdf;laksjdf ;laskdjf a;slkdjf
PPT
Cache Memory for Computer Architecture.ppt
PPT
Cache Memory.ppt
PPT
04_Cache Memory.ppt
PPT
04_Cache Memory.ppt
cache memory
04 cache memory
Ch_4.pptInnovation technology pptInnovation technology ppt
unit 4.faosdfjasl;dfkjas lskadfj asdlfk jasdf;laksjdf ;laskdjf a;slkdjf
Cache Memory for Computer Architecture.ppt
Cache Memory.ppt
04_Cache Memory.ppt
04_Cache Memory.ppt

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

PPT
04_Cache Memory-computer-architecture.ppt
PPT
04 cache memory.ppt 1
PPT
Detailed representation of Cache Memory.
PPT
04_Cache_Memory_William _Stallings_COA.ppt
PPT
04 cache memory
PPT
04 cache memory
PPT
cache memory introduction, level, function
PDF
Chache memory ( chapter number 4 ) by William stalling
PPT
total cache memory is here.please read this for better knowledge
PPT
04_Cache_Memory-cust memori memori memori.ppt
PPTX
CAO-Unit-III.pptx
PPT
Akanskaha_ganesh_kullarni_memory_computer.ppt
PPT
04_Cache Memory.ppt
PPT
cache memory
PPT
Memory Organization and Cache mapping.ppt
PPTX
BCSE205L_Module 4 Computer Architecture Org.pptx
PPT
cache memory.ppt
PPT
cache memory.ppt
PPT
Cache memory
PPT
Cache memory
04_Cache Memory-computer-architecture.ppt
04 cache memory.ppt 1
Detailed representation of Cache Memory.
04_Cache_Memory_William _Stallings_COA.ppt
04 cache memory
04 cache memory
cache memory introduction, level, function
Chache memory ( chapter number 4 ) by William stalling
total cache memory is here.please read this for better knowledge
04_Cache_Memory-cust memori memori memori.ppt
CAO-Unit-III.pptx
Akanskaha_ganesh_kullarni_memory_computer.ppt
04_Cache Memory.ppt
cache memory
Memory Organization and Cache mapping.ppt
BCSE205L_Module 4 Computer Architecture Org.pptx
cache memory.ppt
cache memory.ppt
Cache memory
Cache memory
Ad

More from ArifatunNesa (8)

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

Recently uploaded (20)

PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
web development for engineering and engineering
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPT
Drone Technology Electronics components_1
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PPT
Project quality management in manufacturing
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
436813905-LNG-Process-Overview-Short.pptx
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPT
Chapter 6 Design in software Engineeing.ppt
PDF
composite construction of structures.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
Practice Questions on recent development part 1.pptx
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
AgentX UiPath Community Webinar series - Delhi
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Geodesy 1.pptx...............................................
web development for engineering and engineering
Strings in CPP - Strings in C++ are sequences of characters used to store and...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Simulation of electric circuit laws using tinkercad.pptx
Drone Technology Electronics components_1
“Next-Gen AI: Trends Reshaping Our World”
Project quality management in manufacturing
Lesson 3_Tessellation.pptx finite Mathematics
436813905-LNG-Process-Overview-Short.pptx
ETO & MEO Certificate of Competency Questions and Answers
Chapter 6 Design in software Engineeing.ppt
composite construction of structures.pdf
573137875-Attendance-Management-System-original
Practice Questions on recent development part 1.pptx
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
AgentX UiPath Community Webinar series - Delhi

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