8. Memory Hierarchy Flashcards
Define spatial locality.
Memory locations close to a recently accessed location are likely to be accessed again in the near future.
Define temporal locality.
Recently accessed memory locations are likely to be accessed again in the near future.
Why does locality exist in programs?
Instruction reuse: loops, functions.
Data working sets: arrays, objects.
Describe the common memory hierarchy in a computer.
Registers (100s of bytes, ~1ns)
Cache (SRAM, 1KB-10MB, 1-10ns)
Main Memory (DRAM, 1-64GB, ~100ns)
Disk/SSD (100s GB SSD/1-2TB disk, ~100μs - 10ms)
How does memory hierarchy take advantage of temporal locality and spatial locality?
Temporal locality:
- If accessing data from slower memory, move it to faster memory.
- If data in faster memory unused recently, move it to slower memory.
Spatial locality:
- If need to move a word from slower to faster memory, move adjacent words at same time.
- Gives rise to blocks and pages: units of storage within the memory hierarchy composed of multiple contiguous words.
Between which memories does the software move the data, and which the hardware?
The software transfers between the registers and cache. (compiler)
The hardware transfers between the cache and main memory.
The software transfers between the main memory and disk. (operating system)
How are hardware-managed transfers performed?
Data moved between levels automatically in response to the program’s memory accesses.
Memory always has a copy of cached data, but data in the cache may be more recent.
In terms of caches, define block.
A block is the unit of data stored in the cache (normally in the range of 32-128 bytes). The block size is larger than a word to help exploit spatial locality.
In terms of caches, define miss.
A miss is where the data is not found. The search needs to be performed in the next level of hierarchy (maybe another cache, or maybe main memory). Once the data is located, it is copied to the memory level where the miss happened.
In terms of caches, define hit.
A hit is where data is found (so is completed quickly).
In terms of caches, define hit rate.
The proportion of memory accesses that are hits at a given level of the memory hierarchy.
In terms of caches, define miss rate.
The proportion of memory accesses that are misses at a given level of the memory hierarchy.
In terms of caches, define allocation.
Placement of a new block into the caches, usually evicting another block.
In terms of caches, define eviction.
Displacement of a block from the cache, which occurs when a new block is allocated in its place.
Compare LRU and FIFO policies.
LRU (Least Recently Used) evicts the cache block that hasn’t been accessed for the longest.
FIFO (First In, First Out) replaces in the same order as filled.