Summary
# ContextIf operands are in memory, it has to be loaded into the registers of the processor, and then operated, and stored back into memory.
Memory Technology
DDR SDRAM
Double Data Rate Synchronous Dynamic Random Access Memory
Motivation
Requirement: Big and fast memory
# CacheKey concept
Hierarchy of memory technologies should be used:
- Small but fast near CPU
- Large but slow farther away from CPU (for cost)
Keep frequently and recently used data in smaller but faster memory
Principle of locality
Program accesses only a small portion of the memory address space within a small time interval
Temporal locality
If an item is referenced, it will tend to be referenced again soon
Spatial locality
If an item is referenced, nearby items will tend to be referenced soon.
Working Set
Working set
Set of locations accessed during
Aim
Capture working set and keep it in memory closest to CPU
Memory Access
To make slow main memory appear faster:
- Cache
- Hardware management
To make small main memory appear bigger:
- Virtual memory
- OS managed
Terminology
Hit
Data is in cache
Hit rate
Fraction of memory that is in cache
Hit time
Time to access cache
Miss
Data is not in cache
Miss rate
1 - Hit rate
)Fraction of memory not in cache (
Miss penalty
By definition
hit time
Average access time:
Memory-Cache Mapping
## Direct Mapped Cache Multiple memory blocks map to the same cache block (and have the same cache index), but have unique tag numbers.Cache block/line
Unit of transfer between memory and cache
Reading Data
Cache Misses | |
---|---|
Compulsory misses (cold start/first reference) | Occurs at first access to a block, as block must be brought into cache. |
Conflict misses (collision/interference) | Occurs in direct mapped/set associative, when several blocks are mapped to the same block/set |
Capacity misses | Occurs when blocks are discarded from cache as cache cannot contain all blocks |
Writing Policy
Motivation
When writing data, the modified data is only in cache, but not in memory.
Solutions:
- Write-through cache
- Write-back cache
Write-through cache
Write data both to cache and to main memory
Write-back cache
Only writes to cache during write operation, and only writes to main memory when cache block is evicted.
Handling Cache Misses
Write allocate
- load complete block into cache
- change only required word in cache
- write to main memory (based on write policy)
Write around
- write directly to main memory
Block Size Trade-offs
Set-Associative Cache
Motivation
Address conflict misses.
N-
way set associative cacheA memory block can be placed in a fixed number
of locations in the cache, where .
Effective idea:
- instead of mapping to a cache block, it maps to a unique set of cache blocks where it can be placed in any of the
cache blocks in that set. - requires searching of both to look for memory block
Advantage of associativity
A direct-mapped cache of size
has the same miss rate of a 2-way set associative cache of size .
Fully-Associative Cache
Fully-associative cache
Can be placed in any location in cache
Block number serves as tag in FA cache.
No conflict misses
No conflict misses happens since data can go anywhere
Capacity misses
Cache cannot contain all blocks needed
Cache Performance
- Cold/compulsory miss remains the same irrespective of cache size/associativity
- Conflict miss goes down with increasing associativity on the same cache size
- Conflict miss is 0 for FA caches
- For same cache size, capacity miss remains the same irrespective of associativity
- Capacity miss decreases with increasing cache size
Cache Misses | |
---|---|
Cold/compulsory | same irrespective of cache size/associativity |
Conflict miss | for same cache size, decreases with increasing associativity |
Capacity miss | decreases with increasing cache size |
Block Replacement Policy
Motivation
In set associative and fully associative caches, a memory block can choose where to be placed, potentially replacing another cache block if full.
Least recently used
When replacing a block, choose one which has not been accessed for the longest time. (Temporal locality)
Hard to track if there are many choices
- FIFO
- RR
- LFU