Understand CPU Caching Concepts
Understand CPU Caching Concepts
Concepts
Concept of Caching
Need for Cache has come about due to reasons :
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
Level Access Typical Technology Managed
Time Size By
Level 1 2-8 ns 8 KB-128 KB SRAM Hardware
Cache (on-
chip)
Level 2 5-12 ns 0.5 MB - 8 SRAM Hardware
Cache (off- MB
chip)
Main Memory 10-60 ns 64 MB - 2 DRAM Operating
GB System
Hard Disk 3,000,000 - 100 GB - 2 Magnetic Operating
10,000,000 ns TB System
Cache organization
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:
Data Displacem
Tag Index Valid bit
blocks ent
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.
•The index length is bits and describes which row the data has been put in.
•The displacement length is and specifies which block of the ones we have stored we
need.
When the CPU requests a byte from a particular RAM block, it needs to
be able to determine three things very quickly:
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 :
References
Wikipedia : http://en.wikipedia.org/wiki/CPU_cache
ArsTechnica : http://arstechnica.com/
http://software.intel.com