1/52
Obsidian Q4 notes through Lesson 4: bytes, locality, cache variables and designs, and address splitting with division and remainder.
How many bits does one hexadecimal digit represent?
4 bits.
Increasing latency, what are the fastest places for memory retrieval?
Registers → L1/L2/L3 cache → RAM → SSD → hard disk. Fastest to slowest, or increasing latency.
Real Legends Rarely Skip Dessert
What is bandwidth?
The amount of data transferred per unit of time, such as bytes/second or GB/s.
What is the usual storage size/speed/cost tradeoff?
Small storage near the CPU is generally faster and more expensive per byte; larger storage is generally slower and cheaper per byte.
What is temporal locality?
Reusing the SAME memory location soon. Example: access A, B, A, A. It describes an access pattern.
What is spatial locality?
Accessing NEARBY memory locations within a short time. They need not be adjacent, and each location may be used only once.
How does fetching a whole cache block take advantage of spatial locality?
Fetching one byte also brings nearby bytes into the cache, so later nearby accesses may already be cached.
What is a machine word?
A natural processor data unit; often 8 bytes on a 64-bit machine. The size depends on the architecture.
What is a common cache-block size?
64 bytes is common, but use the block size specified by the problem.
What is a virtual-memory page, and what size is common?
An operating-system memory-mapping unit; commonly 4096 bytes, though sizes vary.
What is a memory block?
An aligned B-byte region of consecutive memory. With B=4, blocks cover addresses 0–3, 4–7, 8–11, and so on.
What is a cache line?
One cache slot that can hold a copy of ONE memory block plus bookkeeping, such as a valid bit and stored tag.
What is a cache set?
A group of E cache lines. A block maps to a particular set and can occupy an eligible line within that set.
How are a cache, its sets, and its lines organized?
A cache contains sets; each set contains cache lines; each line holds one block plus bookkeeping.
What does uppercase S represent?
S = number of sets in the cache.
What does lowercase s represent?
s = log₂(S) = number of set-index bits needed to identify a set. It is not the selected set number.
What does E represent?
E = number of cache lines PER set (associativity).
What does uppercase B represent?
B = number of bytes PER block, not the number of blocks.
What does lowercase b represent?
b = log₂(B) = number of offset bits needed to identify a byte within a block. It is not the offset value.
What does C represent, and how is it calculated?
C = S × E × B = cache DATA capacity in bytes
How many total cache lines are there?
S × E. Each line can hold one block.
What is a direct-mapped cache?
One line per set: E=1. Each block has exactly one possible line; different blocks can compete for that same line.
What is a set-associative cache?
multiple lines per set. A block's address determines its set, but the block can occupy any of the E lines within that set.
What is a fully associative cache?
All cache lines belong to ONE set: S=1. Any block can occupy any line; s=log₂(1)=0 set-index bits.
Set 0: [line] [line] [line] [line]
What are the address fields from most significant to least significant?
Tag | set index | block offset.
What does the set index identify?
Which set in the cache to check. Lowercase s counts the bits used for this field.
What does the tag identify?
Which memory block is wanted among the blocks assigned to the selected set. Compare it with the tags stored in that set's valid lines.
What does the block offset identify?
Which byte within the block is wanted, counting from 0. Lowercase b counts the bits used for this field.
What does lowercase t represent?
t = number of tag bits; t = m − s − b.
How do you calculate the number of tag bits?
t = m − s - b
m = how many bits are in the address
s = # of bits in S
b = # of bits in B
What information does a cache line contain in the hardware model?
A valid bit, a stored tag, and the block's data bytes; additional bookkeeping may also exist.
What does a cache line's valid bit mean?
1 =usable block; 0 = contents are not valid.
How is a requested address different from a cache line?
address: tag, set index, and offset (to locate a byte).
cache line: validity bit, a tag, and the copied block data.
How do you calculate the block offset?
offset = address % B.
How do you calculate the memory block number?
block_number = address // B
How do you calculate the set index?
set = block_number % S.
How do you calculate the tag?
tag = block_number // S
What is write-through?
[Writing to cached block] Update the cached data and immediately forward the write to the next level. (“I’ll write.. but you’re going right through me”)
What is write-back?
[Writing to cached block] Update cached data; send the changes to the next level later, such as when the block is evicted. (“I’ll write back to you”)
What is no-write-allocate?
[Writing to uncached block] Forward the write to the next level without loading the block into this cache; the next level follows its own policy. (“No, I will not write, you do it!”)