Understand CPU cache


CPU Caches

Small amounts of unusually fast memory.

  • Gnererally hold contents recently accessed memory locations
  • Access latency much smaller than for main memory

Three common types

  • Data (D-cache)
  • Instruction(I-cache)
  • Translation lookaside buffer(TLB)
    • Caches virtual->real address translations

Cache-lines are the key! Undoubtedly! If you will make even single error in data layout, you will get 100x slower solution! No jokes!

Cache Hierarchies

Cache hierarchies are common.

E.g., Intel Core i7-9xx processor:

  • 32KB L1 I-cache, 32 KB L1 D-cache per core
    • Shared by 2 HW threads
  • 256 KB L2 cache per core
    • Holds both instructions and data
    • Shared by 2 HW threads
  • 8MB L3 cache
    • Holds both instructions and data
    • Shared by 4 cores(8 HW threads)

Resources