SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Cache Mapping
COMP375 1
Cache MappingCache Mapping
COMP375 Computer Architecture
d O i tiand Organization
Goals
• Understand how the cache system finds a
d t it i th hdata item in the cache.
• Be able to break an address into the fields
used by the different cache mapping
schemes.
Cache Challenges
• The challenge in cache design is to ensure
th t th d i d d t d i t tithat the desired data and instructions are
in the cache. The cache should achieve a
high hit ratio.
• The cache system must be quickly
searchable as it is checked every memorysearchable as it is checked every memory
reference.
Cache to Ram Ratio
• A processor might have 512 KB of cache
d 512 MB f RAMand 512 MB of RAM.
• There may be 1000 times more RAM than
cache.
• The cache algorithms have to carefully
select the 0 1% of the memory that is likelyselect the 0.1% of the memory that is likely
to be most accessed.
Cache Mapping
COMP375 2
Tag Fields
• A cache line contains two fields
– Data from RAM
– The address of the block currently in the
cache.
• The part of the cache line that stores the
address of the block is called the tag field.
• Many different addresses can be in any• Many different addresses can be in any
given cache line. The tag field specifies
the address currently in the cache line.
• Only the upper address bits are needed.
Cache Lines
• The cache memory is divided into blocks
or lines. Currently lines can range from 16y g
to 64 bytes.
• Data is copied to and from the cache one
line at a time.
• The lower log2(line size) bits of an address
if i l b i lispecify a particular byte in a line.
Line address Offset
Line Example
0110010100
0110010101
0110010110
With a line size of 4,
0110010110
0110010111
0110011000
0110011001
0110011010
0110011011
These boxes
represent RAM
addresses
the offset is the
log2(4) = 2 bits.
The lower 2 bits
0110011011
0110011100
0110011101
0110011110
0110011111
specify which byte
in the line
Computer Science Search
• If you ask COMP285 students how to
h f d t it th h ld b blsearch for a data item, they should be able
to tell you
• Linear Search – O(n)
Binary Search O(log n)• Binary Search – O(log2n)
• Hashing – O(1)
• Parallel Search – O(n/p)
Cache Mapping
COMP375 3
Mapping
• The memory system has to quickly
determine if a given address is in the cache.
• There are three popular methods of
mapping addresses to cache locations.
–Fully Associative – Search the entire
cache for an address.
Direct Each address has a specific–Direct – Each address has a specific
place in the cache.
–Set Associative – Each address can be
in any of a small set of cache locations.
Direct Mapping
• Each location in RAM has one specific
place in cache where the data will be held.
C id th h t b lik• Consider the cache to be like an array.
Part of the address is used as index into
the cache to identify where the data will be
held.
• Since a data block from RAM can only bey
in one specific line in the cache, it must
always replace the one block that was
already there. There is no need for a
replacement algorithm.
Direct Cache Addressing
• The lower log2(line size) bits define which
b t i th bl kbyte in the block
• The next log2(number of lines) bits defines
which line of the cache
• The remaining upper bits are the tag field.
Tag Line Offset
Cache Constants
• cache size / line size = number of lines
• log2(line size) = bits for offset
• log2(number of lines) = bits for cache index
• remaining upper bits = tag address bits
Cache Mapping
COMP375 4
Example direct address
Assume you have
• 32 bit addresses (can address 4 GB)
• 64 byte lines (offset is 6 bits)
• 32 KB of cache
• Number of lines = 32 KB / 64 = 512
• Bits to specify which line = log2(512) = 9
Tag Line Offset
6 bits9 bits17 bits
Example Address
• Using the previous direct mapping scheme
ith 17 bit t 9 bit i d d 6 bit ff twith 17 bit tag, 9 bit index and 6 bit offset
01111101011101110001101100111000
01111101011101110 001101100 111000
Tag Index offset
• Compare the tag field of line 001101100
(10810) for the value 01111101011101110. If it
matches, return byte 111000 (5610) of the line
How many bits are in the tag, line
and offset fields?
25% 25%25%25%Direct Mapping
24 bit addresses
64K bytes of cache
16 byte cache lines
1. tag=4, line=16, offset=4
tag=4,line=16,offset=4
tag=4,line=14,offset=6
tag=8,line=12,offset=4
tag=6,line=12,offset=6
2. tag=4, line=14, offset=6
3. tag=8, line=12, offset=4
4. tag=6, line=12, offset=6
Associative Mapping
• In associative cache mapping, the data
from any location in RAM can be stored in
any location in cacheany location in cache.
• When the processor wants an address, all
tag fields in the cache as checked to
determine if the data is already in the
cache.
• Each tag line requires circuitry to compare
the desired address with the tag field.
• All tag fields are checked in parallel.
Cache Mapping
COMP375 5
Associative Cache Mapping
• The lower log2(line size) bits define which
b t i th bl kbyte in the block
• The remaining upper bits are the tag field.
• For a 4 GB address space with 128 KB
cache and 32 byte blocks:
Tag Offset
5 bits27 bits
Example Address
• Using the previous associate mapping
h ith 27 bit t d 5 bit ff tscheme with 27 bit tag and 5 bit offset
01111101011101110001101100111000
011111010111011100011011001 11000
Tag offset
• Compare all tag fields for the value
011111010111011100011011001. If a match
is found, return byte 11000 (2410
) of the line
How many bits are in the tag and
offset fields?
25% 25%25%25%Associative Mapping
24 bit addresses
128K bytes of cache
64 byte cache lines
1. tag= 20, offset=4
tag=
20,offset=4tag=19,offset=5tag=18,offset=6tag=16,offset=8
2. tag=19, offset=5
3. tag=18, offset=6
4. tag=16, offset=8
Set Associative Mapping
• Set associative mapping is a mixture of
direct and associative mapping.pp g
• The cache lines are grouped into sets.
• The number of lines in a set can vary from
2 to 16.
• A portion of the address is used to specify
which set will hold an address.
• The data can be stored in any of the lines
in the set.
Cache Mapping
COMP375 6
Set Associative Mapping
• When the processor wants an address, it
indexes to the set and then searches theindexes to the set and then searches the
tag fields of all lines in the set for the
desired address.
• n = cache size / line size = number of lines
• b = log2(line size) = bit for offset
• w = number of lines / set
• s = n / w = number of sets
Example Set Associative
Assume you have
• 32 bit addresses
• 32 KB of cache 64 byte lines
• Number of lines = 32 KB / 64 = 512
• 4 way set associative
• Number of sets = 512 / 4 = 128
• Set bits = log2(128) = 7
Tag Set Offset
6 bits7 bits19 bits
Example Address
• Using the previous set-associate mapping
ith 19 bit t 7 bit i d d 6 bit ff twith 19 bit tag, 7 bit index and 6 bit offset
01111101011101110001101100111000
0111110101110111000 1101100 111000
Tag Index offset
• Compare the tag fields of lines 110110000 to
110110011 for the value
0111110101110111000. If a match is found,
return byte 111000 (56) of that line
How many bits are in the tag, set
and offset fields?
25% 25%25%25%2-way Set Associative
24 bit addresses
128K bytes of cache
16 byte cache lines
1. tag=8, set = 12, offset=4
tag=8,set=
12,offset=4
tag=16,set=
4,offset=4
tag=12,set=
8,offset=4
tag=10,set=
10,offset=4
g
2. tag=16, set = 4, offset=4
3. tag=12, set = 8, offset=4
4. tag=10, set = 10, offset=4
Cache Mapping
COMP375 7
Replacement policy
• When a cache miss occurs, data is copied
into some location in cache.into some location in cache.
• With Set Associative or Fully Associative
mapping, the system must decide where
to put the data and what values will be
replaced.
• Cache performance is greatly affected by
properly choosing data that is unlikely to
be referenced again.
Replacement Options
• First In First Out (FIFO)
• Least Recently Used (LRU)
• Pseudo LRU
• Random
LRU replacement
• LRU is easy to implement for 2 way set
i tiassociative.
• You only need one bit per set to indicate
which line in the set was most recently used
• LRU is difficult to implement for larger ways.
For an N way mapping there are N!• For an N way mapping, there are N!
different permutations of use orders.
• It would require log2(N!) bits to keep track.
Pseudo LRU
• Pseudo LRU is frequently used in set
associative mapping.pp g
• In pseudo LRU there is a bit for each half
of a group indicating which have was most
recently used.
• For 4 way set associative, one bit
i di h h lindicates that the upper two or lower two
was most recently used. For each half
another bit specifies which of the two lines
was most recently used. 3 bits total.
Cache Mapping
COMP375 8
Comparison of Mapping
Fully Associative
A i i i k h b b i• Associative mapping works the best, but is
complex to implement. Each tag line
requires circuitry to compare the desired
address with the tag field.
• Some special purpose cache such as theSome special purpose cache, such as the
virtual memory Translation Lookaside
Buffer (TLB) is an associative cache.
Comparison of Mapping
Direct
• Direct has the lowest performance, but is
easiest to implement.
• Direct is often used for instruction cache.
• Sequential addresses fill a cache line and
then go to the next cache line.
• Intel Pentium level 1 instruction cache
uses direct mapping.
Comparison of Mapping
Set Associative
• Set associative is a compromise between
the other two. The bigger the “way” the
better the performance, but the more
complex and expensive.
• Intel Pentium uses 4 way set associative
caching for level 1 data and 8 way set
associative for level 2.

Weitere ähnliche Inhalte

Was ist angesagt?

Computer architecture cache memory
Computer architecture cache memoryComputer architecture cache memory
Computer architecture cache memoryMazin Alwaaly
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kVijay Kumar
 
INTERNAL STRUCTURE OF 8086 MICROPROCESSOR
INTERNAL STRUCTURE OF  8086 MICROPROCESSORINTERNAL STRUCTURE OF  8086 MICROPROCESSOR
INTERNAL STRUCTURE OF 8086 MICROPROCESSORMd. Hasnat Shoheb
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchyAJAL A J
 
High Bandwidth Memory(HBM)
High Bandwidth Memory(HBM)High Bandwidth Memory(HBM)
High Bandwidth Memory(HBM)HARINATH REDDY
 
Address mapping
Address mappingAddress mapping
Address mappingrockymani
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORSagar Kuntumal
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and ArchitectureDhaval Bagal
 
Cache memory
Cache memoryCache memory
Cache memoryAnuj Modi
 

Was ist angesagt? (20)

Cache memory
Cache memoryCache memory
Cache memory
 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
 
Computer architecture cache memory
Computer architecture cache memoryComputer architecture cache memory
Computer architecture cache memory
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
Cache
CacheCache
Cache
 
Interrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.kInterrupts on 8086 microprocessor by vijay kumar.k
Interrupts on 8086 microprocessor by vijay kumar.k
 
INTERNAL STRUCTURE OF 8086 MICROPROCESSOR
INTERNAL STRUCTURE OF  8086 MICROPROCESSORINTERNAL STRUCTURE OF  8086 MICROPROCESSOR
INTERNAL STRUCTURE OF 8086 MICROPROCESSOR
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Cache memory
Cache memoryCache memory
Cache memory
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
Cache memory
Cache memoryCache memory
Cache memory
 
High Bandwidth Memory(HBM)
High Bandwidth Memory(HBM)High Bandwidth Memory(HBM)
High Bandwidth Memory(HBM)
 
80486
8048680486
80486
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
Mapping
MappingMapping
Mapping
 
Address mapping
Address mappingAddress mapping
Address mapping
 
INTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSORINTEL 8086 MICROPROCESSOR
INTEL 8086 MICROPROCESSOR
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
 
Cache memory
Cache memoryCache memory
Cache memory
 

Andere mochten auch

Cache presentation on Mapping and its types
Cache presentation on Mapping and its typesCache presentation on Mapping and its types
Cache presentation on Mapping and its typesEngr Kumar
 
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 designUET Taxila
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryWayne Jones Jnr
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating SystemRaj Mohan
 

Andere mochten auch (14)

Memory Mapping Cache
Memory Mapping CacheMemory Mapping Cache
Memory Mapping Cache
 
Cache memory presentation
Cache memory presentationCache memory presentation
Cache memory presentation
 
Cache presentation on Mapping and its types
Cache presentation on Mapping and its typesCache presentation on Mapping and its types
Cache presentation on Mapping and its types
 
Memory mapping
Memory mappingMemory mapping
Memory mapping
 
Cache memory
Cache memoryCache memory
Cache memory
 
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
 
Paging
PagingPaging
Paging
 
04 Cache Memory
04  Cache  Memory04  Cache  Memory
04 Cache Memory
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 

Ähnlich wie Cache mapping

Ähnlich wie Cache mapping (20)

Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Cache recap
Cache recapCache recap
Cache recap
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Memory caching
Memory cachingMemory caching
Memory caching
 
Advance computer architecture
Advance computer architectureAdvance computer architecture
Advance computer architecture
 
Cmp.pptx
Cmp.pptxCmp.pptx
Cmp.pptx
 
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 introduction, level, function
cache memory introduction, level, functioncache memory introduction, level, function
cache memory introduction, level, function
 
cache memory
cache memorycache memory
cache memory
 
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
 

Kürzlich hochgeladen

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Cache mapping

  • 1. Cache Mapping COMP375 1 Cache MappingCache Mapping COMP375 Computer Architecture d O i tiand Organization Goals • Understand how the cache system finds a d t it i th hdata item in the cache. • Be able to break an address into the fields used by the different cache mapping schemes. Cache Challenges • The challenge in cache design is to ensure th t th d i d d t d i t tithat the desired data and instructions are in the cache. The cache should achieve a high hit ratio. • The cache system must be quickly searchable as it is checked every memorysearchable as it is checked every memory reference. Cache to Ram Ratio • A processor might have 512 KB of cache d 512 MB f RAMand 512 MB of RAM. • There may be 1000 times more RAM than cache. • The cache algorithms have to carefully select the 0 1% of the memory that is likelyselect the 0.1% of the memory that is likely to be most accessed.
  • 2. Cache Mapping COMP375 2 Tag Fields • A cache line contains two fields – Data from RAM – The address of the block currently in the cache. • The part of the cache line that stores the address of the block is called the tag field. • Many different addresses can be in any• Many different addresses can be in any given cache line. The tag field specifies the address currently in the cache line. • Only the upper address bits are needed. Cache Lines • The cache memory is divided into blocks or lines. Currently lines can range from 16y g to 64 bytes. • Data is copied to and from the cache one line at a time. • The lower log2(line size) bits of an address if i l b i lispecify a particular byte in a line. Line address Offset Line Example 0110010100 0110010101 0110010110 With a line size of 4, 0110010110 0110010111 0110011000 0110011001 0110011010 0110011011 These boxes represent RAM addresses the offset is the log2(4) = 2 bits. The lower 2 bits 0110011011 0110011100 0110011101 0110011110 0110011111 specify which byte in the line Computer Science Search • If you ask COMP285 students how to h f d t it th h ld b blsearch for a data item, they should be able to tell you • Linear Search – O(n) Binary Search O(log n)• Binary Search – O(log2n) • Hashing – O(1) • Parallel Search – O(n/p)
  • 3. Cache Mapping COMP375 3 Mapping • The memory system has to quickly determine if a given address is in the cache. • There are three popular methods of mapping addresses to cache locations. –Fully Associative – Search the entire cache for an address. Direct Each address has a specific–Direct – Each address has a specific place in the cache. –Set Associative – Each address can be in any of a small set of cache locations. Direct Mapping • Each location in RAM has one specific place in cache where the data will be held. C id th h t b lik• Consider the cache to be like an array. Part of the address is used as index into the cache to identify where the data will be held. • Since a data block from RAM can only bey in one specific line in the cache, it must always replace the one block that was already there. There is no need for a replacement algorithm. Direct Cache Addressing • The lower log2(line size) bits define which b t i th bl kbyte in the block • The next log2(number of lines) bits defines which line of the cache • The remaining upper bits are the tag field. Tag Line Offset Cache Constants • cache size / line size = number of lines • log2(line size) = bits for offset • log2(number of lines) = bits for cache index • remaining upper bits = tag address bits
  • 4. Cache Mapping COMP375 4 Example direct address Assume you have • 32 bit addresses (can address 4 GB) • 64 byte lines (offset is 6 bits) • 32 KB of cache • Number of lines = 32 KB / 64 = 512 • Bits to specify which line = log2(512) = 9 Tag Line Offset 6 bits9 bits17 bits Example Address • Using the previous direct mapping scheme ith 17 bit t 9 bit i d d 6 bit ff twith 17 bit tag, 9 bit index and 6 bit offset 01111101011101110001101100111000 01111101011101110 001101100 111000 Tag Index offset • Compare the tag field of line 001101100 (10810) for the value 01111101011101110. If it matches, return byte 111000 (5610) of the line How many bits are in the tag, line and offset fields? 25% 25%25%25%Direct Mapping 24 bit addresses 64K bytes of cache 16 byte cache lines 1. tag=4, line=16, offset=4 tag=4,line=16,offset=4 tag=4,line=14,offset=6 tag=8,line=12,offset=4 tag=6,line=12,offset=6 2. tag=4, line=14, offset=6 3. tag=8, line=12, offset=4 4. tag=6, line=12, offset=6 Associative Mapping • In associative cache mapping, the data from any location in RAM can be stored in any location in cacheany location in cache. • When the processor wants an address, all tag fields in the cache as checked to determine if the data is already in the cache. • Each tag line requires circuitry to compare the desired address with the tag field. • All tag fields are checked in parallel.
  • 5. Cache Mapping COMP375 5 Associative Cache Mapping • The lower log2(line size) bits define which b t i th bl kbyte in the block • The remaining upper bits are the tag field. • For a 4 GB address space with 128 KB cache and 32 byte blocks: Tag Offset 5 bits27 bits Example Address • Using the previous associate mapping h ith 27 bit t d 5 bit ff tscheme with 27 bit tag and 5 bit offset 01111101011101110001101100111000 011111010111011100011011001 11000 Tag offset • Compare all tag fields for the value 011111010111011100011011001. If a match is found, return byte 11000 (2410 ) of the line How many bits are in the tag and offset fields? 25% 25%25%25%Associative Mapping 24 bit addresses 128K bytes of cache 64 byte cache lines 1. tag= 20, offset=4 tag= 20,offset=4tag=19,offset=5tag=18,offset=6tag=16,offset=8 2. tag=19, offset=5 3. tag=18, offset=6 4. tag=16, offset=8 Set Associative Mapping • Set associative mapping is a mixture of direct and associative mapping.pp g • The cache lines are grouped into sets. • The number of lines in a set can vary from 2 to 16. • A portion of the address is used to specify which set will hold an address. • The data can be stored in any of the lines in the set.
  • 6. Cache Mapping COMP375 6 Set Associative Mapping • When the processor wants an address, it indexes to the set and then searches theindexes to the set and then searches the tag fields of all lines in the set for the desired address. • n = cache size / line size = number of lines • b = log2(line size) = bit for offset • w = number of lines / set • s = n / w = number of sets Example Set Associative Assume you have • 32 bit addresses • 32 KB of cache 64 byte lines • Number of lines = 32 KB / 64 = 512 • 4 way set associative • Number of sets = 512 / 4 = 128 • Set bits = log2(128) = 7 Tag Set Offset 6 bits7 bits19 bits Example Address • Using the previous set-associate mapping ith 19 bit t 7 bit i d d 6 bit ff twith 19 bit tag, 7 bit index and 6 bit offset 01111101011101110001101100111000 0111110101110111000 1101100 111000 Tag Index offset • Compare the tag fields of lines 110110000 to 110110011 for the value 0111110101110111000. If a match is found, return byte 111000 (56) of that line How many bits are in the tag, set and offset fields? 25% 25%25%25%2-way Set Associative 24 bit addresses 128K bytes of cache 16 byte cache lines 1. tag=8, set = 12, offset=4 tag=8,set= 12,offset=4 tag=16,set= 4,offset=4 tag=12,set= 8,offset=4 tag=10,set= 10,offset=4 g 2. tag=16, set = 4, offset=4 3. tag=12, set = 8, offset=4 4. tag=10, set = 10, offset=4
  • 7. Cache Mapping COMP375 7 Replacement policy • When a cache miss occurs, data is copied into some location in cache.into some location in cache. • With Set Associative or Fully Associative mapping, the system must decide where to put the data and what values will be replaced. • Cache performance is greatly affected by properly choosing data that is unlikely to be referenced again. Replacement Options • First In First Out (FIFO) • Least Recently Used (LRU) • Pseudo LRU • Random LRU replacement • LRU is easy to implement for 2 way set i tiassociative. • You only need one bit per set to indicate which line in the set was most recently used • LRU is difficult to implement for larger ways. For an N way mapping there are N!• For an N way mapping, there are N! different permutations of use orders. • It would require log2(N!) bits to keep track. Pseudo LRU • Pseudo LRU is frequently used in set associative mapping.pp g • In pseudo LRU there is a bit for each half of a group indicating which have was most recently used. • For 4 way set associative, one bit i di h h lindicates that the upper two or lower two was most recently used. For each half another bit specifies which of the two lines was most recently used. 3 bits total.
  • 8. Cache Mapping COMP375 8 Comparison of Mapping Fully Associative A i i i k h b b i• Associative mapping works the best, but is complex to implement. Each tag line requires circuitry to compare the desired address with the tag field. • Some special purpose cache such as theSome special purpose cache, such as the virtual memory Translation Lookaside Buffer (TLB) is an associative cache. Comparison of Mapping Direct • Direct has the lowest performance, but is easiest to implement. • Direct is often used for instruction cache. • Sequential addresses fill a cache line and then go to the next cache line. • Intel Pentium level 1 instruction cache uses direct mapping. Comparison of Mapping Set Associative • Set associative is a compromise between the other two. The bigger the “way” the better the performance, but the more complex and expensive. • Intel Pentium uses 4 way set associative caching for level 1 data and 8 way set associative for level 2.