Lecture 03
Lecture 03
MEMORY HIERARCHY
When it comes to memory, there are two universally desirable properties:
• Large Size: ideally, we want to never have to worry about running out of memory.
• Speed of Access: we want the process of accessing memory to take as little time as
possible.
But we cannot optimize both of these properties at the same time. As our memory size
increases, the time to find a memory location and access it grows as well.
• Spatial Locality – if an item is referenced, items whose addresses are close by will
tend to be referenced soon. (ADDRESS)
• If we access the location of A[0], we will probably also be accessing A[1], A[2], etc.
• Sequential instruction access also exhibits spatial locality.
MEMORY HIERARCHY
A memory hierarchy, consisting of multiple levels of memory with varying speed and
size, exploits these principles of locality.
• Faster memory is more expensive per bit, so we use it in smaller quantities.
• Slower memory is much cheaper so we can afford to use a lot of it.
The goal is to, whenever possible, keep references in the fastest memory. However,
we also want to minimize our overall memory cost.
MEMORY HIERARCHY
Level 2
Level 3
MEMORY HIERARCHY
Speed Processor Size Cost ($/bit) Technology
Memory DRAM
Two Questions:
1. How do we know if an item is
present in the cache?
2. How do we find the item in the
cache?
CACHES
A reference to 𝑋𝑛 causes a miss, which forces the cache to fetch 𝑋𝑛 from some lower
level of the memory hierarchy, presumably main memory.
Two Questions:
1. How do we know if an item is
present in the cache?
2. How do we find the item in the
cache?
What is an obvious choice for the tag? The upper bits of the address of the block!
TAGS
For instance, in this particular example,
let’s say the block at address 01101 is
held in the cache entry with index 101.
Note that initially the valid-bit entries are all ‘N’ for not valid.
EXERCISE
The first reference is for the block at address 22, which uses
the lower bits 110 to index into the cache. The 110 cache
entry is not valid so this is a miss.
We know that 16 KB is 4K words, which is 212 words, and, with a block size of 4
words (22 ), 210 blocks.
Each block contains 4 words, or 128 bits, of data. Each block also has a tag that is
32-10-2-2 bits long, as well as one valid bit. Therefore, the total cache size is