ECM 1413 Cache & Virtual Memory Flashcards
Temporal Locality
Items accessed recently are likely to be accessed again soon (e.g. loops)
If you want to discard data, start with the one that has not been requested in a long time
Spatial Locality
Items located near each other in memory are likely to be accessed within a short period of time (Most programs exhibit spatial locality)
Copy additional nearby memory locations into the cache
A memory request may be a
- Cache hit - the cache contains the data (faster data return)
- Cache miss - the cache does not contain the requested data - first read from memory
Cache designs
- Direct Mapping
- Fully-associative Mapping
- Set-associative Mapping
Direct-Mapped Cache
Each block of main memory maps to one unique cache line
+Simple, easy to implement & search
-Inefficient use of the cache space
Fully-Associative Cache
Each block of main memory can map to any line of the cache
Replacement Algorithm: LRU
+Flexible
-Takes a long time to search
S-Way Set-Associative Cache
The cache is divided into N cache sets
Each cache set consists of S lines
Each block of main memory maps to one unique cache set
Replacement algorithm: LRU
A write request may be a:
- Write hit - the address we want to write to is present in the cache
- Write miss - the address we want to write to is not present in the cache
For a write hit, there are two options:
Write-back
Write-through
Write-back:
initially write only to cache
Write into memory if being replaced
+fast writes
-mechanism for cache coherence
Write-through
write into both cache and memory
+consistency between the cache and memory
-slow writes
For a write miss, there are two options:
Write around
Write allocate
Write around (no-write allocate):
Write into memory only
+Avoids unnecessary cache access and cache pollution
-Does not utilise temporal locality
Write allocate:
write into both cache and memory
+exploits spatial and temporal locality
-Potential unnecessary cache access and cache pollution
High temporal Locality indicates
Write-Back + Write-Allocate