leziwn.cs 2023. 11. 15. 17:40
Address Subdivision

Address Subdivision

  • Index: Block 구분
  • Offset: 하나의 block 내의 byte 구분
  • Tag: 나머지

 

Example: Larger Block Size

Example: Larger Block Size

 

  • Block address (index): 몇 번째 block인가?
  • Block number (offset): 진짜 몇 번째 block인가? (modulo 연산)

 

Block Size Considerations
  • Block 크기가 크면, 즉 하나의 block에서 많은 byte를 copy하면, cache miss rate ↓
  • 하지만, 하나의 block에서 너무 많은 byte를 copy하면, copy할 수 있는 block의 개수는 줄어들 수밖에 없다.
  • 또, 하나의 block에서 너무 많은 byte를 copy하면, 결국 그 block에서 쓰이지도 않을 byte까지 copy하게 된다. (pollution)
  • It also takes more time to copy from low level memory to high level cache. (miss penalty)

 

Cache Misses

▶ Cache hit: CPU proceeds normally.

▶ Cache miss: STALL the pipeline. (파이프라인의 MEM 단계에서 시간이 많이 소요된다.)

  • Instruction cache miss --> Restart instruction fetch.
  • Data cache miss: STALL 이후, complete data access.

 


Cache Write

지금까지는 cache read에 대해 이야기하였다. 이제부터 cache write에 대해 이야기해보자.

 

(1) Write-Through: 캐시와 메모리를 둘 다 업데이트 하는 방법

▶ Cache-hit: 캐시, 메모리를 둘 다 업데이트한다. (항상 똑같이 유지함!)

  • Problem: It makes writes take longer. (메모리도 업데이트 해야 하기 때문이다.)
  • Solution: write buffer
    --> write buffer에서 더 많은 write cache-hit을 기다리고, write buffer가 꽉 차면, 메모리를 업데이트한다.

▶ Cache-miss - 두 가지 방법:

  1. Allocate on miss: write-miss 시, 메모리와 캐시를 둘 다 업데이트 하는 방법
  2. Write around: write-miss 시, 메모리만 업데이트 하는 방법

 

(2) Write-Back: 우선 캐시만 업데이트하고, 나중에 캐시에서 사라질 때 메모리를 업데이트 하는 방법 (dirty bit)

▶ Cache-hit: 캐시를 업데이트하고, dirty bit = 1로 바꾼다.

▶ Cache-miss:

  1. Dirty bit을 확인하여, 만약 dirty bit = 1이면, 메모리를 업데이트한다.
  2. 메모리에서 캐시에 쓸 값을 읽어온다. (cache-miss이기 때문에 추가된 과정)
  3. 캐시를 업데이트한다.
  4. dirty bit = 1로 바꾼다.

 

Write Allocation

Write Allocation

1. Write-Through: 캐시, 메모리를 모두 업데이트 하는 방식

▶ Read

  • Cache hit: 캐시에서 데이터를 읽는다.
  • Cache miss: 캐시를 업데이트하고, 데이터를 읽는다.

 

▶ Write

  • Cache hit: 캐시, 메모리를 업데이트한다.
  • Cache miss:
    Sol 1) Allocate on miss: 캐시, 메모리를 둘 다 업데이트한다.
    Sol 2) Write around: 메모리만 업데이트한다.

 

2. Write-Back: 캐시만 업데이트하고, 메모리는 나중에 업데이트 하는 방식

▶ Read

  • Cache hit: 캐시에서 데이터를 읽는다.
  • Cache miss:
    1) 캐시를 찾는다.
    2) 그 캐시의 dirty bit을 확인한다.
    3-1) dirty이면, 메모리에 쓴다.
    4) 캐시를 업데이트한다.
    5) 캐시: "not dirty"

 

▶ Write

  • Cache hit:
    1) 캐시를 업데이트한다.
    2) 캐시: "dirty"
  • Cache miss:
    1) 캐시를 찾는다.
    2) 그 캐시의 dirty bit을 확인한다.
    3) dirty이면, 메모리에 쓴다.
    4) 캐시에 쓸 데이터를 읽어온다. (<-- chache miss)
    5) 캐시를 업데이트한다.
    6) 캐시: "dirty"

 


Example: Intrinsity FastMATH

Example: Intrinsity FastMATH

 

Main Memory Supporting Caches
  • 메인메모리(DRAM)은 data를 이동할 때, bus를 이용한다.
  • bus는 느리다.
  • --> Data 이동이 많으면, 느려진다.

Main Memory Supporting Caches

 

 

 

 

 

 

출처: 이화여자대학교 이형준교수님 컴퓨터구조