캐시: 메모리 계층적으로 가장 CPU에 가까운 메모리
캐시는 SRAM으로 만들어진다
# SRAM: 데이터 리프레쉬가 일어나지 않는 RAM
캐시에 없는 Xn에 대한 접근
캐시에 Xn이 없다면 메모리에서 Xn을 가져온다(Fetch)
그런데, 데이터가 캐시에 있는지 어떻게 알 수 있을까? 해당 챕터에서는 그것을 배우게 될 것
Direct mapped cache(직접 사상 캐시)
각각의 메모리 주소가 캐시에 직접 매핑되는 방식
Mapping method
- (블록 주소) modulo (캐시의 블록 수)
- EX) 00101 modulo (8) = 101
Q. 캐시 주소에 어떤 메모리 주소가 저장되어 있는지 어떻게 알까?
- 캐시에 태그를 추가함으로써 해결할 수 있다
- 태그는 캐시 내의 워드가 요청한 것인지 아닌지를 식별하는 데 필요한 주소 정보를 포함한다
- 상위 부분 비트를 저장하는데 이를 태그(Tag) 비트라고 한다
Q. 데이터가 캐시에 있는지는 어떻게 알까?
- 유효(Valid) 비트를 통해 해결한다
- Valid bit 1 = 데이터 있음
- Valid bit 0 = 데이터 없음
- 0으로 초기화 됨
캐시 접근
빈 8 블록 캐시가 있다고 가정하자
캐시는 비어있기 때문에, 첫 번째 참조는 miss(데이터 없음)가 발생한다
태그 비트를 확인하기 때문에 태그 비트가 다르다면 miss이다
캐시는 32비트 주소를 사용한다고 공부할 때는 가정하자
- 태그 필드는 캐시가 가진 태그와 값을 비교할 때 사용된다
- 캐시 인덱스는 블록을 셀렉팅할 때 사용된다
위의 예시는 워드가 1개일 때 캐시 비트이고 아래에서 설명하는 것은 워드가 여러 개일 때
가정
- 32비트 주소
- 직접 사상 캐시
- 캐시에 2^n블록이 존재하여 n비트가 인덱스로 사용
- 캐시 블록의 크기는 2^m워드(2^(m+2)바이트), 여기서 m은 캐시 블록 내의 워드를 참조할 때 사용됨
태그 비트의 크기는 다음과 같음
32 - (인덱스 비트 + 워드 비트 + 2(바이트 오프셋))
캐시의 전체 비트 수는
2^n(블록 수) * (블록 크기 + 태그 크기 + 유효 비트 크기)
예시 문제
32비트에서 16KiB의 데이터를 저장하는 4워드 블록 캐시에 필요한 전체 비트 수를 구하세요
16KiB = 4096Word
블록 개수 = 4096 / 4 = 1024 => log2(1024) = 10
워드 비트 = log2(4) = 2
태그 비트 크기 = 32 - (10 + 2 + 2) = 18
캐시 전체 비트 수 = 1024 * (128 + 18 + 1) = 2^10 * 147 = 147KibiBits
'School > 컴퓨터 구조' 카테고리의 다른 글
[컴퓨터 구조] 캐시(Cache) - Associative Caches (0) | 2023.05.29 |
---|---|
[컴퓨터 구조] 캐시(Cache) - 캐시 퍼포먼스 측정 (0) | 2023.05.29 |
[컴퓨터 구조] 캐시(Cache) - 캐시 미스와 쓰기 처리 (0) | 2023.05.29 |
1-1 Computer Organization (0) | 2023.03.08 |