Cache Memory Organization Formula Sheet: Mapping, AMAT and Tag-Bit Revision Notes

Revise cache mapping, address fields, metadata overhead, multilevel AMAT, CPI, write policies and miss types through one consistent numerical example.

KnowledgeGate Team

Exam prep & CS education

Updated 25 Nov 20266 min read
Cache Memory Organization Formula Sheet: Mapping, AMAT and Tag-Bit Revision Notes

Cache numericals feel formula-heavy because one question can mix bytes, blocks, lines, sets, tag bits, hit ratios and penalties. Normalise the notation, then carry one configuration through address splitting, tag-store cost, AMAT and miss analysis. Use it alongside KnowledgeGate's learn library when revising COA. The checks below keep units, field widths and penalty conventions explicit.

The earlier Cache Memory Organization in COA: Mapping, Hit Ratio and Worked Examples owns the broad hierarchy and comparison treatment; this sheet owns the compact formula checks, tag-store accounting and nested AMAT arithmetic.

Cache memory organization formulas and notation

First convert every capacity to the same unit.

Symbol or rule

Meaning

m

Address bits

C

Cache data bytes

B

Bytes per block

k

Ways per set

L = C / B

Cache lines

S = L / k

Cache sets

offset bits = log2(B)

Byte position within a block

set bits = log2(S)

Set selector

tag bits = m - set bits - offset bits

Memory-block identifier

For block j, direct mapping has k = 1, S = L, and line = j mod L; k-way mapping uses set = j mod S; fully associative mapping has S = 1, zero set bits, and any line.

For byte addressing, block number = floor(address / B) and offset = address mod B. Bit fields require power-of-two sizes. With word addressing, the offset counts words. Unless total storage including metadata is stated, 64 KiB means data capacity.

Cache address fields in one 32-bit worked example

Take a 32-bit byte-addressable machine with C = 64 KiB = 65,536 bytes and B = 64 bytes:

L = 65,536 / 64 = 1,024 lines

  • Direct mapped: offset = log2(64) = 6, index = log2(1,024) = 10, tag = 32 - 10 - 6 = 16 bits.

  • Four-way: S = 1,024 / 4 = 256, so the split is tag 18 | set 8 | offset 6.

  • Fully associative: zero set bits, so the split is tag 26 | offset 6.

Trace byte address 0xCAFEBABE:

block = floor(0xCAFEBABE / 64) = 0x32BFAEA = 53,213,930

offset = 0xCAFEBABE mod 64 = 0x3E = 62

Direct mapping gives line = 53,213,930 mod 1,024 = 746 = 0x2EA and tag 0xCAFE. Rebuild: (0xCAFE << 16) + (0x2EA << 6) + 0x3E = 0xCAFEBABE.

Four-way mapping gives set = 53,213,930 mod 256 = 234 = 0xEA and tag 0x32BFA. Rebuild: (0x32BFA << 14) + (0xEA << 6) + 0x3E = 0xCAFEBABE.

Fully associative mapping uses the whole block number, 0x32BFAEA, as its 26-bit tag. Rebuild: (0x32BFAEA << 6) + 0x3E = 0xCAFEBABE.

For the direct-mapping-only derivation and conflict trace, see Direct Mapping in Cache Memory: Address Bits, Cache-Line Mapping and a Hit-Ratio Worked Example. That post owns the single-policy deep dive; this sheet compares direct, four-way and fully associative fields before moving to tag storage and AMAT.

Tag-store and cache-overhead formulas

total bits = L x (8B + tag bits + valid bits + dirty bits) + replacement-state bits

Also, data bits = 8C and metadata overhead = total bits - data bits. Include dirty bits for write-back and replacement state when victim selection is needed. Exact LRU requires at least ceil(log2(k!)) bits per set to distinguish recency orders. Specified tree-PLRU uses k - 1 bits per set for power-of-two k; do not swap conventions.

For the direct-mapped example, assume write-back. Each line stores 64 x 8 = 512 data bits, a 16-bit tag, one valid bit and one dirty bit:

bits per line = 512 + 16 + 1 + 1 = 530

total storage = 1,024 x 530 = 542,720 bits = 67,840 bytes = 66.25 KiB

Metadata is 18 x 1,024 = 18,432 bits = 2,304 bytes = 2.25 KiB. Direct mapping has no replacement bits.

Cache hit ratio, AMAT and memory-stall formulas

  • hit ratio h = hits / accesses

  • miss rate = 1 - h

  • AMAT = hit time + miss rate x miss penalty, for extra time after miss detection

  • Two levels: AMAT = tL1 + mL1 x (tL2 + mL2 x Pmemory)

  • stall CPI = I-cache misses/instruction x penaltyI + data accesses/instruction x D-cache miss rate x penaltyD

  • CPI = base CPI + stall CPI

  • At the same clock rate, speedup = old CPI / new CPI

For tL1 = 1 ns, mL1 = 4%, tL2 = 8 ns, local mL2 = 20%, and extra Pmemory = 80 ns:

AMAT = 1 + 0.04 x (8 + 0.20 x 80) = 1 + 0.04 x 24 = 1.96 ns

Now use base CPI 1.2, I-cache miss rate 2%, data accesses per instruction 0.30, D-cache miss rate 5%, and both penalties 50 cycles:

stall CPI = 0.02 x 50 + 0.30 x 0.05 x 50 = 1 + 0.75 = 1.75

total CPI = 1.2 + 1.75 = 2.95

If D-cache misses fall to 2%, new CPI = 1.2 + 1 + (0.30 x 0.02 x 50) = 2.50. Speedup = 2.95 / 2.50 = 1.18x.

Nested AMAT tree showing a 1 ns L1 lookup, 4% L1 miss path, 8 ns L2 lookup, 20% local L2 miss path, 80 ns memory penalty, and final AMAT of 1.96 ns.

For a separate seven-mistake repair drill, see Cache Memory Organization Mistakes: 7 Mark-Losing Traps and Fixes . That post owns the why, consequence and repair for each mistake; this sheet keeps traps as a compact checksum after the formulas.

Write policies, replacement rules and the three miss types

Choice

What happens

Write-through

Updates cache and next-level memory on every write, usually through a write buffer; normally no dirty bit

Write-back

Updates cache first and writes an evicted dirty block later; needs one dirty bit per line

Write-allocate

Fetches the missed block, then writes it in cache

No-write-allocate

Bypasses cache on a write miss

Write-back plus write-allocate and write-through plus no-write-allocate are common pairings, not laws.

A compulsory miss is a block's first reference. A capacity miss means the working set exceeds cache capacity. A conflict miss means blocks compete for one set despite space elsewhere. Replacement matters only with multiple ways: LRU evicts the least recently used line, FIFO the earliest inserted line, and random uses no recency state.

Trace blocks 0, 4, 0, 4 with four-block data capacity. In a four-line direct-mapped cache, both select line 0, giving M, M, M, M: zero hits and two repeated conflict misses. In a two-way cache with two sets, both select set 0 but occupy separate ways, giving M, M, H, H: two hits and a 50% hit ratio. Each block's first reference is compulsory.

Cache memory organization exam patterns and fast trap checks

Expect address mapping, tag-store overhead, AMAT or CPI, and block traces with replacement or write policy. Timed practice should alternate a field-splitting question with a performance calculation.

Before solving, correct these common traps:

  • Bytes versus words: identify what one address selects.

  • Binary capacity: 1 KiB = 2^10 bytes, not 1,000 bytes.

  • Lines versus sets: calculate L first, then divide by k to get S.

  • Local versus global L2 miss rate: local L2 rate applies only among L1 misses.

  • Penalty convention: write whether lookup time is included or extra.

  • Data versus physical capacity: add metadata only for physical storage.

  • Logarithm: field widths use base 2.

  • Sum-back check: make tag + set + offset = m, and verify units before moving on.

The 60-second order is: normalise units, compute L and S, split the address, map the block, then define each penalty before applying a performance formula.

Cache memory formula sheet: the short revision sequence

  1. L = C / B

  2. S = L / k

  3. address = tag + set + offset

  4. direct line or set = block number mod destination count

  5. AMAT = hit time + miss rate x extra miss cost

Valid, dirty and replacement bits belong to physical-storage calculations, not the advertised data capacity. If you want the COA sequence around cache, memory hierarchy and pipelining, GATE Guidance by Sanchit Sir provides that next step.