1 / 19

Cache Memory

What is it and why do we need it?. Cache Memory. Chris Ward CS147 10/16/2008. Why do we need Cache?. What drives us to require cache? How and Why does it work? ???. Our Memory Needs. What we would prefer in our Computer Memory: Fast Large Cheap However,

gasha
Télécharger la présentation

Cache Memory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What is it and why do we need it? Cache Memory Chris Ward CS147 10/16/2008

  2. Why do we need Cache? What drives us to require cache? How and Why does it work? ???

  3. Our Memory Needs • What we would prefer in our Computer Memory: • Fast • Large • Cheap However, • Very Fast memory = Very expen$ive memory • Since we need large capacity ( today multi-gigabyte memories) we need to build a system that is the best compromise to keep the total $$ reasonable.

  4. Example of two Memory Types

  5. Performance Gap • In the early days of PC technology, memory access was only slightly slower than register access • Since the 1980s the performance gap between processor and memory has been growing. • CPU speed continues to double every few years, while the speed of disk and RAM cannot boast such a rapid rate of speed improvements. • For Main Memory RAM, the speed has increased from 50 nanoseconds (one billionth of a second) to <2 nanoseconds, a 25x improvement over a 30-year period

  6. Performance Gap

  7. A couple cool facts • It has been discovered that for about 90%of the time that our programs execute only 10% of our code is used! • This is known as the Locality Principle • Temporal Locality • When a program asks for a location in memory , it will likely ask for that samelocation again very soon thereafter • Spatial Locality • When a program asks for a memory location at a memory address (lets say 1000)… It will likely need a nearbylocation 1001,1002,1003,10004 … etc.

  8. The Solution Construct a Memory Hierarchy which tricks the CPU into thinking it has a very fast, large, cheap memory system.

  9. Memory Hierarchy For a 1 GHz CPU a 50 ns wait means 50 wasted clock cycles Main Memory and Disk estimates Fry’s Ad 10/16/2008

  10. Why does this solution work? • We established that the Locality principle states that only a small amount of Memory is needed for most of the program’s lifetime… • We now have a Memory Hierarchy that places very fast yet expensive RAM near the CPU and larger – slower – cheaper RAM further away… • The trick is to keep the data that the CPU wants in the small expensive fast memory close to the CPU … and how do we do that???

  11. … Memory Management • Hardware and the Operating System are responsible for moving data throughout the Memory Hierarchy when the CPU needs it. • Modern programming languages mainly assume two levels of memory, main memory and disk storage. • Programmers are responsible for moving data between disk and memory through file I/O. • Optimizing compilers are responsible for generating code that, when executed, will cause the hardware to use caches and registers efficiently.

  12. Cache algorithms • A computer program or a hardware-maintained structure that is designed to manage a cache of information • When the smaller cache is full, the algorithm must choose which items to discard to make room for the new data • The "hit rate" of a cache describes how often a searched-for item is actually found in the cache • The "latency" of a cache describes how long after requesting a desired item the cache can return that item

  13. Caching Techniques Each replacement strategy is a compromise between hit rate and latency. • Direct Mapped Cache • The direct mapped cache is the simplest form of cache and the easiest to check for a hit. • Unfortunately, the direct mapped cache also has the worst performance, because again there is only one place that any address can be stored. • Fully Associative Cache • The fully associative cache has the best hit ratio because any line in the cache can hold any address that needs to be cached. • However, this cache suffers from problems involving searching the cache • A replacement algorithm is used usually some form of a LRU "least recently used" algorithm • N-Way Set Associative Cache • The set associative cache is a good compromise between the direct mapped and set associative caches.

  14. And Finally What happens when we run out of main memory? Our programs need more and more RAM!

  15. Virtual Memory • Virtual Memory is basically the extension of physical main memory (RAM) into a lower cost portion of our Memory Hierarchy (lets say… Hard Disk) • A form of the Overlay approach, managed by the OS, called Paging is used to swap “pages” of memory back and forth between the Disk and Physical Ram. • Hard Disks are huge, but to you remember how slow they are??? Millions of times slower that the other memories in our pyramid.

  16. Increasing Speed and Memory

  17. Intel 'Nehalem' CPU

  18. References • http://en.wikipedia.org/wiki/CPU_cache • http://download.intel.com/pressroom/kits/IntelProcessorHistory.pdf • http://processorfinder.intel.com/details.aspx?sSpec=SLBBD • http://www.dba-oracle.com/t_history_ram.htm • http://www.superssd.com/products/ramsan-400/indexb.htm • http://www.pcguide.com/ref/ram/types_DRAM.htm • http://en.wikipedia.org/wiki/Memory_hierarchy • http://e-articles.info/e/a/title/Memory-Basics-~-ROM-DRAM-SRAM-Cache-Memory/ • http://en.wikipedia.org/wiki/Cache_algorithms • http://www.pcguide.com/ref/mbsys/cache/funcWhy-c.html

  19. Metric prefixes.

More Related