Sub topic 15
GATE Problem Patterns and Strategies
Assume you know binary and hexadecimal notation, powers of two, byte-addressable memory, word size, and basic weighted averages. This chapter focuses on how to recognize and solve common GATE questions about cache organization and access time.
A reliable solution workflow
Most cache problems become mechanical when solved in this order:
- Write down the address width, cache capacity, block size, associativity, and access times.
- Convert capacities to powers of two.
- Compute the number of blocks or lines.
- Compute the number of sets:
\[ \text{sets}=\frac{\text{cache capacity}}{\text{block size}\times\text{ways}} \]
- Find offset bits, index bits, and tag bits:
\[ \text{offset bits}=\log_2(\text{block size}) \]
\[ \text{index bits}=\log_2(\text{number of sets}) \]
\[ \text{tag bits}=\text{address bits}-\text{index bits}-\text{offset bits} \]
- Check whether the question uses bytes or words.
- For a reference string, track each set separately and apply the stated replacement policy.
- For timing, identify whether miss ratios are local or global.
Address and mapping patterns
For address A, block size B, and S sets:
- Block number =
A // B - Block offset =
A % B - Set index =
(A // B) % S - Tag =
(A // B) // S
The same block-number method works for direct-mapped and set-associative caches. In a fully associative cache, there is no index field, so every block can occupy any line.
A numerical question may give a 32-bit address, a 4 KiB cache, 16-byte blocks, and 2-way associativity. The cache has \(4096/16=256\) lines and \(256/2=128\) sets. Therefore, offset bits are 4, index bits are 7, and tag bits are \(32-4-7=21\).
Timing and miss-ratio patterns
For one cache level:
\[ \text{AMAT}=T_c+mP \]
Here, \(T_c\) is cache lookup time, \(m\) is the miss ratio, and \(P\) is the miss penalty. If main-memory access takes 100 ns after a miss, do not automatically add the cache lookup time unless the problem defines the penalty that way.
For two levels, with local miss ratios:
\[ \text{AMAT}=T{L1}+m{L1}(T{L2}+m{L2}T_M) \]
def amat_two_level(t_l1, m_l1, t_l2, m_l2, t_mem):
return t_l1 + m_l1 * (t_l2 + m_l2 * t_mem)
print(amat_two_level(1, 0.10, 10, 0.20, 100))
# 4.0 nsThe global L2 miss ratio is \(m{L1}m{L2}\), not \(m_{L2}\) alone. State this distinction before substituting values.
Trace and policy patterns
For a reference string, convert addresses to block numbers first. Then record the contents of each relevant set after every access. Under LRU, evict the least recently used block. Under FIFO, evict the block that entered earliest, even if it was recently accessed.
| Question wording | Main operation |
|---|---|
| “2-way, 8 sets” | Map each block to one of 8 sets and keep 2 tags per set |
| “hit ratio” | Hits divided by total references |
| “tag storage” | Tag bits plus valid, dirty, and replacement metadata |
| “write-back” | Write memory on eviction of a dirty line |
Final checks
Before choosing an answer, verify the units, count compulsory misses on first references, and check whether a write policy changes the access sequence. If two answers differ slightly, inspect whether one counts lookup time twice or confuses local and global miss ratios.
Exercise
A 32-bit address uses a 1 KiB direct-mapped cache with 16-byte blocks. Find the offset, index, and tag widths.
Show answer
The cache has 1024/16 = 64 lines. Offset = log2(16) = 4 bits, index = log2(64) = 6 bits, and tag = 32 - 4 - 6 = 22 bits.