cache

Complete

Summary

Locality

  • temporal locality
    • data tends to be referenced again soon
    • ie. counter for loops
  • spatial locality
    • nearby data tends to be referenced soon
    • ie. items in arrays

Average access time

  • hit -> when data is found in cache
  • miss -> when data is not found in cache, need to look in memory

Cache block

  • unit of transfer between memory and cache
  • usually in words
  • larger block sizes can improve spatial locality at the cost of more latency
o®setn-1:0blocknumber...:n

like how with 4-byte blocks(words), we can ignore the last memory address bits, unless we desire a particular byte within that word

Memory sizes

SizeNumber of bytes
1KB2¹⁰
1MB2²⁰
1GB2³⁰
1TB2⁴⁰

Cache types

Direct mappedSet associativeFully associative
Block placementone block per indexn blocks per indexany cache block
Block searchcheck tag at corresponding blocksearch tag within setsearch tag in whole cache
Blok replacementoverwritechoose by replacement policychoose by replacement policy

Concept

Types of memory

Dynamic RAMStatic RAM
High density - 1 transistor per cellLow density - 6 transistors per cell
Slow access - 50-70nsFast access - 0.5-5ns
CheaperMore expensive
Principle of lcaility
  • program only accesses a small portion of the memory address space within a small time interval
  • keep frequently/recently used data in a smaller but faster memory(cache)

Working set

  • set of memory locations accessed during a time period
  • the goal of cache is to capture the working set to reduce latency

Write policy

  • write-through
    • write to both cache and memory
    • delayed by main memory, reduce latency with a write buffer
  • write-back
    • write to cache, write to memory when cache block is replaced
    • additional bit to track write state, write to memory if bit is 1