[CS] Cache, Memory Layer

seunghyunΒ·2023λ…„ 5μ›” 7일
0

πŸ’»

λͺ©λ‘ 보기
6/15

Memory Hierarchy

πŸ’‘ Register < Cache (L1<L2<L3) < Main Memory (DRAM) < Disk (SSD/HDD) < Network/Cloud

가상메λͺ¨λ¦¬λž€ λ””μŠ€ν¬μ—μ„œ λ©”λͺ¨λ¦¬λ‘œ μ–΄λ–»κ²Œ κ°€μ Έμ˜¬ 것? (운영체제)
λ©”λͺ¨λ¦¬μ—μ„œ μΊμ‹œλ‘œ μ–΄λ–»κ²Œ κ°€μ Έμ˜¬ 것? (컴퓨터ꡬ쑰)

Motivated by

  • Principle of Locality
  • Speed vs. size vs. cost tradeoff

Locality principle

πŸ’‘ 졜근 자주 μ‚¬μš©λ˜λŠ” 것듀은 λ‹€μ‹œ μ‚¬μš©λ  κ°€λŠ₯성이 μžˆλ‹€.

βœ”οΈ Spatial Locality: nearby references are likely to occur soon

  • ex) arrays, program codes
  • Access a block of contiguous words

βœ”οΈ Temporal Locality : the same references is likely to occur soon

  • ex) loops, reuse of variables
  • Keep recently accessed data to closer to the processor (Cache)

βœ”οΈ Speed vs. Size tradeoff

  • Bigger memory is slower : SRAM - DRAM - Disk - Tape
  • Fast memory is more expensive

Cache

πŸ’‘ A small but fast memory located between processor and main memory

βœ”οΈ Benefits

  • Reduce load latency
  • Reduce store latency
  • Reduce bus traffic (on-chip caches)

βœ”οΈ Cache Block Allocation (when to place)

  • On a read miss
  • On a write miss

βœ”οΈ Cache Block Placement (where to place)

  • Fully-assosiative cache
  • Direct-mapped cache
  • Set-associative cache

βœ”οΈ Cache Block Replacement

  • Random

    • Just pick one and replace it
    • Pseudo-random: use simple hash algorithm using address
  • LRU (least recently used)

    • κ³Όκ±°λŠ” 미래의 거울. κ°€μž₯ μ˜€λž«λ™μ•ˆ μ°Έμ‘°ν•˜μ§€ μ•Šμ€ 것을 μ«“μ•„λ‚Έλ‹€
    • need to keep timestamp
    • expensive due to global compare
    • Pseudo-LRU: use LFU using bit tags
  • Replacement policy critical for small caches

Cache misses

βœ”οΈ Cold-start misses (or compulsory misses)

  • the first access to a block is always not in the cache

βœ”οΈ Capacity misses

  • if the memory blocks needed by a program is bigger than the cache size, the capacity misses will occur due to cache block replacement

βœ”οΈ Conflict misses (or collision misses)

  • for direct-mapped or set-associative cache, too many blocks can be mapped to the same set

βœ”οΈ Invalidation misses (or sharing misses)

  • cache blocks can be invalidated due to coherence traffic


πŸ”— Reference

[KUOCW] 졜린 κ΅μˆ˜λ‹˜μ˜ 운영체제 κ°•μ˜λ₯Ό μˆ˜κ°•ν•˜κ³  μ •λ¦¬ν•œ λ‚΄μš©μž…λ‹ˆλ‹€. 잘λͺ»λœ λ‚΄μš©μ΄ μžˆλ‹€λ©΄ λŒ“κΈ€λ‘œ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€ 😊

profile
dododo

0개의 λŒ“κΈ€