Caches (PPT 2 - 4) Flashcards
What are the four goals we wish to achieve?
- Fast processing
- Fast Memory
- Large Memory
- Cheap
What is the Von Neumann Bottleneck?
It takes a much longer time to read data from memory than it does to actually process it
What is a cache?
A small storage area located close to a processing unit, which stores recently used data taken from a larger, but more distant and slower, storage area.
What is the payload of a cache?
The payload is the data and instructions fetched from memory
What are the four traits of a computer cache?
- Physically very close to the processor for fast access
- Is very small
- Is accessed instead of main memory when doing a “main memory access”
- Functions automatically without software control
What is locality of reference?
- When an item is used, it will probably be used again
- When an item is used, the items around it will likely be used
How does a cache work?
It uses locality of reference, meaning it keeps a local copy of the original data and possibly the material around it to avoid going back to the original source
Examples of Locality of Reference in Computing?
-ZIP Compression exploits repeated sequences in text
-Using the same applications regularly
Program loops use the same code repeatedly
How small is the cache compared to main memory usually?
It is usually about 1% of main memory
Why does a cache work?
A cache works because if the same data is needed again, it only takes 1 clock cycle to access rather than the full 8 it would take to fetch it from main memory
How does the CPU use a cache?
When the CPU needs to fetch, it first checks the cache to see if the data is there. If it is, it gets a cache “hit”. If it isn’t, it gets a cache “miss” and has to read the data from main memory
Is the processor aware a cache exists?
No, it treats the cache in the same way it treats main memory, meaning memory addressing is the same
Name another type of caching
Disk Caching, from memory to hard disk
What are the four possible issues with using a cache?
- Usage: Must function automatically
- Mapping: Cache is small so must be able to map main memory to it
- Coherence: Cache contains a copy of memory locations and integrity must be maintained during use
- Updating: Cache is normally full so needs to be able to handle new data
What is Cache Overhead?
The cache needs additional space for housekeeping information and decoding information. This means storage is always more than the payload size but the quoted size is always the payload size only
What are the three main cache mapping methods?
- Direct mapping
- Fully associative mapping
- N-way set associative mapping
What is direct mapping?
Each main memory address maps to one specific cache address. This is found by calculation:
cache set no. = block no. mod cache size
What are the advantages and disadvantages of using Direct Mapping?
Adv: Cache only stores the data and no other info so it is efficient in silicon use
Disadv: It can be inefficient. If referencing two blocks, blocks will be continually swapped and hit ratio will be low
What is Fully-Associative Mapping?
An item can be placed anywhere in the cache and to find it we search every stored address
What are the advantages and disadvantages of using Fully-Associative Mapping?
Adv: Does not require calculation to place payload
Disadv: -Must store the original address along with the data, meaning more space is taken up on the silicon.
-Must search every stored address to find data.
What is Set Associative Mapping?
Combines the best features of Direct and Fully Associative Mapping. Cache is divided into sets(“rows”) and main memory is divided up in order to calculate the location. Some bits are used for the set, others for a partial address or tag
What do “Ways” in a Set Associative map do?
They allow multiple addresses which map to the same location to be stored at the same time.
How do you map an item using the Set Associative method?
We split the address into three sections:
(Tag Set Byte)
No. of byte bits is determined by way size = 2^byte bits
No. of set bits determined by sets = 2^set bits
The tag is what is left of the address bits
If the bytes per cache line is 16 bytes and there are 256 sets, how many bits are needed for each part of the (Tag, Set, Byte) format?
2^4 = 16 so 4 bits for the Byte portion
2^8 = 256 so 8 bits for the Set portion
Tag is the remainder so 20 bits