Memory interfacing and hierarchy: performance and cache memory mapping
The memory hierarchy and locality, average access time for one and two cache levels, direct, set-associative and fully associative mapping with address splits and tag sizes, replacement and write policies, and building memory from smaller chips.
Before you start
Powers of two and logarithms
Every address split is a sum of of sizes: offset, index and tag bits.
Memory is arranged as registers → cache (L1, L2, ...) → main memory → disk. Going down, each level is larger, slower and cheaper per bit. The hierarchy works because programs show locality of reference:
Temporal locality: a word used now is likely to be used again soon (loop variables).
Spatial locality: words near it are likely to be used soon (arrays, sequential code). This is why caches move whole blocks.
Hit ratio = fraction of accesses found in the cache; miss ratio .
Two access models give different formulas. Read which one the question uses.
Model
Average access time
Hierarchical (look in cache first; on a miss, then go to memory)
Simultaneous (start both; memory time counts only on a miss)
The hierarchical form is the same as .
Two-level cache (hierarchical), with local miss rates and :
The global L2 miss rate is , the fraction of all accesses that go to memory.
If a miss brings in a whole block, the miss penalty is the block transfer time, for example (words per block) × (time per word), not one memory access.
2. Cache mapping and the address split
Main memory is divided into blocks of bytes; the cache into lines of the same size. Number of lines .
Mapping
Where block can go
Address fields
Direct
line only
tag, line index, offset
-way set associative
any line of set ,
tag, set index, offset
Fully associative
any line
tag, offset
For a -bit physical address:
offset bits;
index (direct) or (set associative); none for fully associative;
tag index offset.
Tag directory size , where extra bits are the valid bit, a dirty bit (write-back) and any replacement bits, as the question states.
Hardware. A -way cache compares tags in parallel, so it needs comparators of tag width and a -to-1 multiplexer. Fully associative needs one comparator per line. Direct mapping needs just one comparator but suffers conflict misses when two busy blocks share a line.
Direct mapping is 1-way set associative; fully associative is -way.
Address split for a 64 KB, 4-way set-associative cache with 64-byte blocks
3. Replacement, write policies and types of misses
Replacement decides which line of a full set to evict (direct mapping has no choice).
LRU: evict the least recently used line. Most common in GATE.
FIFO: evict the line loaded earliest, even if it was just used.
Random.
Write policies on a hit
Write-through: update cache and memory together. Simple; memory is always up to date; more memory traffic.
Write-back: update only the cache and set a dirty bit; write the block to memory when it is evicted. Less traffic; a miss that evicts a dirty block costs an extra block write.
On a write miss
Write-allocate: bring the block into the cache, then write (usual with write-back).
No-write-allocate: write straight to memory (usual with write-through).
The three C's of misses
Miss
Cause
Reduced by
Compulsory (cold)
first reference to a block
larger blocks, prefetch
Capacity
working set larger than the cache
larger cache
Conflict
blocks compete for the same set
higher associativity
To count hits in a trace: compute each block's line or set, then simulate the set's contents in order. A fully associative cache of the same size has no conflict misses.
4. Memory interfacing: building memory from chips
A memory chip is described as : words (locations) of bits. It has address lines, data lines and a chip select (CS).
To build an memory from chips:
Width expansion ( chips side by side): all chips in a row share address and CS lines; each supplies of the data bits.
Depth expansion ( rows): the low address lines go to every chip. The remaining high lines drive a decoder whose outputs select one row.
So the total address lines are : to the chips plus to the decoder.
Memory interleaving. With -way low-order interleaving, consecutive words sit in different modules (module address ), so a block of consecutive words can be fetched from all modules in parallel. This cuts the miss penalty of a cache line fetch.
Bandwidth bytes delivered per unit time, for example a 64-bit bus at 100 MHz gives bytes/s if a transfer completes every cycle.
Formulas to remember
Hierarchical access time
Simultaneous access time
Two-level cache are local miss rates
Lines and sets
Tag bits (set associative)
Tag directory size
Number of chips
Common mistakes
Mixing up the hierarchical and simultaneous formulas; check whether a miss also pays the cache time.
Using the number of lines instead of sets for the index in a set-associative cache.
Forgetting valid, dirty or replacement bits when the question asks for tag directory size.
Treating the L2 miss rate as global when it is given as local (or the reverse).
Counting a miss penalty as one memory access when a whole multi-word block must be transferred.
Applying LRU as FIFO: a hit must move the block to most recently used.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Splitting the address
numerical
A 4-way set-associative cache of 64 KB has 64-byte blocks. Physical addresses are 32 bits. Find the offset, set-index and tag widths, and the tag directory size if each line also stores a valid bit.
Step 1: Find the number of lines and sets.
Try it on paper first.
Example 2: Two-level average access time
numerical
L1 hit time is 1 ns with miss rate 10%. L2 hit time is 10 ns with local miss rate 20%. Main memory takes 100 ns. Using hierarchical access, find the average memory access time and the fraction of accesses that reach main memory.
Step 1: Start from L2's view: what does an L1 miss cost?
Try it on paper first.
Example 3: Counting hits under three mappings
numerical
A cache has 4 lines, all empty at the start. The block reference string is 0, 1, 4, 0, 8, 1, 4. Count hits for direct mapping, 2-way set associative with LRU, and fully associative with LRU.
Step 1: Direct mapping: line = block mod 4.
Try it on paper first.
Example 4: Building 64K × 16 from 16K × 8 chips
numerical
A 64K × 16 memory is to be built from 16K × 8 chips. How many chips are needed, how many address lines go to each chip, and what decoder selects the rows?
Step 1: Count chips for depth and width.
Try it on paper first.
Previous year questions
32 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.