Skip to content
GATEiit

GATE CSE · Computer Organization and Architecture

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 log⁡2 of sizes: offset, index and tag bits.

  • Decoders →

    Memory chips are selected by decoding the high-order address lines.

  • Paging and page replacement →

    Cache replacement (LRU, FIFO) works the same way as page replacement.

This topic comes before: Instruction pipelining and pipeline hazards, Memory management and virtual memory

Concept notes

1. Hierarchy, locality and access time

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 h = fraction of accesses found in the cache; miss ratio =1−h.

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) T=tc+(1−h) tm
Simultaneous (start both; memory time counts only on a miss) T=h tc+(1−h) tm

The hierarchical form is the same as h tc+(1−h)(tc+tm).

Two-level cache (hierarchical), with local miss rates m1 and m2: T=t1+m1(t2+m2 tm). The global L2 miss rate is m1m2, 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 B bytes; the cache into lines of the same size. Number of lines L=cache size/B.

Mapping Where block j can go Address fields
Direct line j mod L only tag, line index, offset
k-way set associative any line of set j mod S, S=L/k tag, set index, offset
Fully associative any line tag, offset

For a P-bit physical address:

  • offset =log⁡2B bits;
  • index =log⁡2L (direct) or log⁡2S (set associative); none for fully associative;
  • tag =P− index − offset.

Tag directory size =(number of lines)×(tag bits+extra bits), where extra bits are the valid bit, a dirty bit (write-back) and any replacement bits, as the question states.

Hardware. A k-way cache compares k tags in parallel, so it needs k comparators of tag width and a k-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 L-way.

32-bit address, 64 KB cache, 64 B blocks, 4-way set associativeTag: 18 bitsSet: 8 bitsOffset: 6compared with the 4 tags in the set256 setsbyte in blocklines = 64 KB / 64 B = 1024; sets = 1024 / 4 = 256
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 N×w: N words (locations) of w bits. It has log⁡2N address lines, w data lines and a chip select (CS).

To build an M×W memory from N×w chips: chips=MN×Ww.

  • Width expansion (W/w chips side by side): all chips in a row share address and CS lines; each supplies w of the W data bits.
  • Depth expansion (M/N rows): the low log⁡2N address lines go to every chip. The remaining log⁡2(M/N) high lines drive a decoder whose outputs select one row.

So the total address lines are log⁡2M: log⁡2N to the chips plus log⁡2(M/N) to the decoder.

Memory interleaving. With m-way low-order interleaving, consecutive words sit in different modules (module = address  mod m), 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 8×108 bytes/s if a transfer completes every cycle.

Formulas to remember

Hierarchical access time
T=tc+(1−h) tm
Simultaneous access time
T=h tc+(1−h) tm
Two-level cachem1,m2 are local miss rates
T=t1+m1 (t2+m2 tm)
Lines and sets
L=cache sizeblock size,S=Lk
Tag bits (set associative)
tag=P−log⁡2S−log⁡2B
Tag directory size
L×(tag+valid+dirty+… )
Number of chips
MN×Ww

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.

  1. 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.

  1. 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.

  1. 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?

  1. 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.

Practise these 32 PYQs →

Topic test

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.