Memory hierarchy Flashcards
What is the objective of the memory hierarchy?
Reduce the impact of the memory wall.
Illusion of having a fast and large memory.
What are the memory tradeoffs?
Speed, size and cost
CPU registers
Cache
RAM
Hard disk
Off-line storage (drivers)
Faster and smaller closest to CPU, these are more costly.
Why is the memory hierarchy efficient?
Locality: spatial and temporal
Spatial: Addresses near each other are likely to be referenced close in time, loops/arrays
Temporal: Address recently accessed, likely to be accessed again, e.g. loops
Because of locality - keep recently used data near the CPU
What are some causes of locality?
Loops
functions
stack
Code artifacts (Arrays, matrix, structs)
What 4 things needs to be taken into account when designing memory?
Block placement: Where can a block be placed?
Block identification: How is a block found?
Block replacement: Which block should be replaced on a miss?
Write strategy: What happens on a write?
What are the three ways a block can be placed in a cache?
Direct mapped
Set-associative
Fully associative
What is a direct mapped cache?
A block can only be placed one place in the cache.
Only need to compare 1 tag with the address tag to see if it is in the cache.
What is a n-way set-associative cache?
A trade off between direct mapped and fully associative.
Group entries in sets of n blocks.
An address can be placed in n possible blocks in the cache, but only in one possible set.
What is a fully associative cache?
A block can be placed anywhere in cache.
Compare tag to tags of all cache entries to find correct cache block.
What function (optimization) does the index bits of an address have?
Limit the number of places we have to search, and search all places in parallell.
What are the structure of an address?
Block addres + Block offset
Tag + index + Block offset
What does the address of a fully associative cache contain?
Tag + offset
Does not need index to limit amount of block to search, as the address can be stored in any of the blocks.
What does the index in a direct mapped- and a set associative cache do?
Direct mapped: Tell what block the address is stored in.
Set associative: Tall what set the address is stored in.
What does the offset bits do in caches?
Used to index into the data, get the correct bytes from the cache block.
How are sets organized in hardware?
The ways are seperated in their own tables. The ways contain a valid bit and a tag field.
The index bits points to rows in each way. This allows for accessing all ways within a set in parallell.
The rows pointed to by the index in the way-tables, make for the complete set.
What are the steps of identification?
- Split address into fields (offset, index, tag)
- Read tag(s) from the set indicated by the index
- Compare the tag from the address with the read tag(s)
- If hit, then select the correct data and send it to the CPU.
What are 3 examples of replacement policies?
Random
LRU: Least recently used, keep ordered list of ways in the cache. Way least recently used is evicted.
FIFO: First in first out
What are 4 examples of write strategy?
How to handle writes:
Write-through
Write-back
If we are missing when doing a write, how should we do this access:
Write allocate
No-write allocate