SlideShare uma empresa Scribd logo
1 de 14
Understand CPU Caching Concepts Abhijit K Rao IIIT - Bangalore
Concept of Caching Need for Cache has come about due to reasons :  The concept of Locality of reference.       -> 5 percent of the data is accessed 95 percent of the times, so           makes sense to cache the 5 percent of the data. The gap between CPU and main memory speeds.      ->  In analogy to producer consumer problem, the CPU is the           consumer and RAM, hard disks act as producers. Slow           producers limit  the performance of the consumer.
Locality of Reference Spatial locality : If a particular memory location say nth location is referenced at a particular time, then it is likely that (n+1) th memory location will be referenced in the near future The actual piece of data that was requested is called the critical word, and the surrounding group of bytes that gets fetched along with it is called a cache line or cache block. Temporal Locality: If at one point in time say T a particular memory location is referenced, then it is likely that the same location will be referenced again at time T+delta.      This is very similar to the concept of working set, i.e., set of pages which the CPU frequently accesses.
CPU Cache and its operation A CPU cache is a smaller, faster memory which stores copies  of the data from  the most frequently used main memory locations.  The concept of locality of reference drives caching concept, we cache the most frequently used, data, instruction for faster data access.    CPU cache could be data cache, instruction cache. Unlike RAM, cache is not expandable. The CPU first checks in the L1 cache for data, if it does not find it at L1, it moves over to L2 and finally L3.  If not found at L3, it’s a cache miss and RAM is searched next, followed by the hard drive. If the CPU finds the requested data in cache, it’s a cache hit, and if not, it’s a cache miss.
Levels of caching and speed, size comparisons
Cache organization When the processor needs to read or write a location in main       memory, it first checks whether that memory location is in the cache.      This is accomplished by comparing the address of the memory location      to all tags in the cache that might contain that address. If the processor finds that the memory location is in the cache, we say      that a cache hit has occurred; otherwise, we speak of a cache miss.
Cache Entry structure Cache row entries usually have the following structure: The data blocks (cache line) contain the actual data fetched from the main memory. The memory address is split into the tag, the index and the displacement (offset), while the valid bit denotes that this particular entry has valid data. ,[object Object]
The displacement length is and specifies which block of the ones we have stored we need.
The tag length is address − index − displacement ,[object Object]
Mapping RAM blocks to cache block Fully associative : Any RAM block can be stored in any available block frame. The problem with this scheme is that if you want to retrieve a specific block from the cache, you have to check the tag of every single block frame in the entire cache because the desired block could be in any of the frames Direct mapping : In a direct-mapped cache, each block frame can cache only a certain subset of the blocks in main memory.  ForEg. Ram block X whose modulo results in 1 are always stored in Cache block 1.     The problem with this approach is certain cache blocks could remain unused and there could be frequent eviction of cache entries for certain cache blocks. N way associative : Ram block X, could be either mapped to Cache Block X or Y.
Handling Cache Miss In order to make room for the new entry on a cache miss, the cache has to evict one of the existing entries.  The heuristic that it uses to choose the entry to evict is called the replacement policy. The fundamental problem with any replacement policy is that it must predict which existing cache entry is least likely to be used in the future. Some of the replacement policies are : Random Eviction: Removal of any cache entry by random choice. LIFO: Evicting the latest cache entry. FIFO: Evicting the oldest cache entry. LRU: Evicting the Least recently used cache entry.
Mirroring Cache to Main memory If data are written to the cache, they must at some point be written to main memory and other higher order cache as well. The timing of this write is controlled by what is known as the write policy. A Write-through cache, every write to the cache causes a write to main memory and higher order cache like L2, L3. Write-back or copy-back cache, writes are not immediately mirrored to the main memory.  Instead, the cache tracks which locations will be evicted. Such entries are written to main memory, higher order cache just before eviction of the cache entry
Stale data in cache The data in main memory being cached may be changed by other entities (e.g. peripherals using direct memory access or multi-core processor), in which case the copy in the cache may become out-of-date or stale.  Alternatively, when the CPU in a multi-core processor updates the data in the cache, copies of data in caches associated with other cores will become stale.  Communication protocols between the cache managers. Which keep the data consistent are known as cache coherence protocols.  Eg. Snoopy based, directory based, token based.
State of the Art today Current day research on cache design, handling cache coherence, is more biased to multicore architectures. References Wikipedia : http://en.wikipedia.org/wiki/CPU_cache ArsTechnica : http://arstechnica.com/ http://software.intel.com What Every Programmer Should Know About Memory -     - Ulrich Drepper, Red Hat, Inc.

Mais conteúdo relacionado

Semelhante a CPU Caching Concepts

Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt Arpita Naik
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7wajanga
 
lecture-5.pptx
lecture-5.pptxlecture-5.pptx
lecture-5.pptxsarasaad69
 
lecture-2-3_Memory.pdf,describing memory
lecture-2-3_Memory.pdf,describing memorylecture-2-3_Memory.pdf,describing memory
lecture-2-3_Memory.pdf,describing memoryfloraaluoch3
 
Cache memory
Cache memoryCache memory
Cache memoryAnuj Modi
 
cachememory-210517060741 (1).pdf
cachememory-210517060741 (1).pdfcachememory-210517060741 (1).pdf
cachememory-210517060741 (1).pdfOmGadekar2
 
MODULE-4 - Memory-System used in Computer organization
MODULE-4 - Memory-System used in Computer organizationMODULE-4 - Memory-System used in Computer organization
MODULE-4 - Memory-System used in Computer organizationMadhuraNK
 
Elements of cache design
Elements of cache designElements of cache design
Elements of cache designRohail Butt
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchyAJAL A J
 
computerarchitecturecachememory-170927134432.pdf
computerarchitecturecachememory-170927134432.pdfcomputerarchitecturecachememory-170927134432.pdf
computerarchitecturecachememory-170927134432.pdfssuserf86fba
 
coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxRuhul Amin
 

Semelhante a CPU Caching Concepts (20)

Cache memory ppt
Cache memory ppt  Cache memory ppt
Cache memory ppt
 
Cache memory
Cache memoryCache memory
Cache memory
 
IS 139 Lecture 7
IS 139 Lecture 7IS 139 Lecture 7
IS 139 Lecture 7
 
lecture-5.pptx
lecture-5.pptxlecture-5.pptx
lecture-5.pptx
 
Cache memory
Cache memoryCache memory
Cache memory
 
lecture-2-3_Memory.pdf,describing memory
lecture-2-3_Memory.pdf,describing memorylecture-2-3_Memory.pdf,describing memory
lecture-2-3_Memory.pdf,describing memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache memory
Cache memoryCache memory
Cache memory
 
Cache Memory
Cache MemoryCache Memory
Cache Memory
 
cachememory-210517060741 (1).pdf
cachememory-210517060741 (1).pdfcachememory-210517060741 (1).pdf
cachememory-210517060741 (1).pdf
 
computer-memory
computer-memorycomputer-memory
computer-memory
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
MODULE-4 - Memory-System used in Computer organization
MODULE-4 - Memory-System used in Computer organizationMODULE-4 - Memory-System used in Computer organization
MODULE-4 - Memory-System used in Computer organization
 
Elements of cache design
Elements of cache designElements of cache design
Elements of cache design
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
computerarchitecturecachememory-170927134432.pdf
computerarchitecturecachememory-170927134432.pdfcomputerarchitecturecachememory-170927134432.pdf
computerarchitecturecachememory-170927134432.pdf
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
 
CA UNIT V..pptx
CA UNIT V..pptxCA UNIT V..pptx
CA UNIT V..pptx
 
COA notes
COA notesCOA notes
COA notes
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

CPU Caching Concepts

  • 1. Understand CPU Caching Concepts Abhijit K Rao IIIT - Bangalore
  • 2. Concept of Caching Need for Cache has come about due to reasons : The concept of Locality of reference. -> 5 percent of the data is accessed 95 percent of the times, so makes sense to cache the 5 percent of the data. The gap between CPU and main memory speeds. -> In analogy to producer consumer problem, the CPU is the consumer and RAM, hard disks act as producers. Slow producers limit the performance of the consumer.
  • 3. Locality of Reference Spatial locality : If a particular memory location say nth location is referenced at a particular time, then it is likely that (n+1) th memory location will be referenced in the near future The actual piece of data that was requested is called the critical word, and the surrounding group of bytes that gets fetched along with it is called a cache line or cache block. Temporal Locality: If at one point in time say T a particular memory location is referenced, then it is likely that the same location will be referenced again at time T+delta. This is very similar to the concept of working set, i.e., set of pages which the CPU frequently accesses.
  • 4. CPU Cache and its operation A CPU cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. The concept of locality of reference drives caching concept, we cache the most frequently used, data, instruction for faster data access. CPU cache could be data cache, instruction cache. Unlike RAM, cache is not expandable. The CPU first checks in the L1 cache for data, if it does not find it at L1, it moves over to L2 and finally L3. If not found at L3, it’s a cache miss and RAM is searched next, followed by the hard drive. If the CPU finds the requested data in cache, it’s a cache hit, and if not, it’s a cache miss.
  • 5. Levels of caching and speed, size comparisons
  • 6. Cache organization When the processor needs to read or write a location in main memory, it first checks whether that memory location is in the cache. This is accomplished by comparing the address of the memory location to all tags in the cache that might contain that address. If the processor finds that the memory location is in the cache, we say that a cache hit has occurred; otherwise, we speak of a cache miss.
  • 7.
  • 8. The displacement length is and specifies which block of the ones we have stored we need.
  • 9.
  • 10. Mapping RAM blocks to cache block Fully associative : Any RAM block can be stored in any available block frame. The problem with this scheme is that if you want to retrieve a specific block from the cache, you have to check the tag of every single block frame in the entire cache because the desired block could be in any of the frames Direct mapping : In a direct-mapped cache, each block frame can cache only a certain subset of the blocks in main memory. ForEg. Ram block X whose modulo results in 1 are always stored in Cache block 1. The problem with this approach is certain cache blocks could remain unused and there could be frequent eviction of cache entries for certain cache blocks. N way associative : Ram block X, could be either mapped to Cache Block X or Y.
  • 11. Handling Cache Miss In order to make room for the new entry on a cache miss, the cache has to evict one of the existing entries. The heuristic that it uses to choose the entry to evict is called the replacement policy. The fundamental problem with any replacement policy is that it must predict which existing cache entry is least likely to be used in the future. Some of the replacement policies are : Random Eviction: Removal of any cache entry by random choice. LIFO: Evicting the latest cache entry. FIFO: Evicting the oldest cache entry. LRU: Evicting the Least recently used cache entry.
  • 12. Mirroring Cache to Main memory If data are written to the cache, they must at some point be written to main memory and other higher order cache as well. The timing of this write is controlled by what is known as the write policy. A Write-through cache, every write to the cache causes a write to main memory and higher order cache like L2, L3. Write-back or copy-back cache, writes are not immediately mirrored to the main memory. Instead, the cache tracks which locations will be evicted. Such entries are written to main memory, higher order cache just before eviction of the cache entry
  • 13. Stale data in cache The data in main memory being cached may be changed by other entities (e.g. peripherals using direct memory access or multi-core processor), in which case the copy in the cache may become out-of-date or stale. Alternatively, when the CPU in a multi-core processor updates the data in the cache, copies of data in caches associated with other cores will become stale. Communication protocols between the cache managers. Which keep the data consistent are known as cache coherence protocols. Eg. Snoopy based, directory based, token based.
  • 14. State of the Art today Current day research on cache design, handling cache coherence, is more biased to multicore architectures. References Wikipedia : http://en.wikipedia.org/wiki/CPU_cache ArsTechnica : http://arstechnica.com/ http://software.intel.com What Every Programmer Should Know About Memory - - Ulrich Drepper, Red Hat, Inc.
  • 15. Q/A