summer_light 2020. 12. 21. 12:54

//Cache
The Cache is a place where recently accessed data can be stored so that it can be accessed more quickly next time

현재 사용한 데이터를 임시로 저장하는 공간이며, 다음에 더 빨리 해당 데이터를 찾기 쉽게하기 위한 메모리이다.   

 

 

//Memory Hierarchy

Registers
L1 Primary Cache
L2 Secondary Cache
Main Memory
Virtual Memory

 

 

//How to move data between Cache and Memory? 캐시와 메모리 사이에서 데이터를 이동시키는 방법
Cache: Faster, smaller 빠르지만, 용량이 작다. 

Memory: Slower, Bigger 느리지만, 용량이 크다. 

 

//Locality of Reference 참조의 지역성
Locality of Space 공간의 지역성
- If data is accessed once, then the next access is probably at a nearby memory address 
- Store a Block of Memory in the Cache, and the nearby Memory will already be in the cache
Locality of time 시간의 지역성
- If data is accessed once then it is likely to be accessed again
- So keep recently accessed data in the cache

 


//Read Request to memory
1) Check if data is in the cache
2) If yes, then Read data from the cache, and update the time stamp of that data
3) If data is not in the cache
a) Evict(Remove) a Block Data from the cache(How to evict?)
b) Copy the requested Block from memory to the new empty space in the cache(How to choose which block to evict?)
c) Read data from the cache

 


//Write Request
1) Check if the Block which we want to write into is in the cache
2) If yes,
    a) Write Into the cache
    b) Write Through : Also Write into Memory 캐시를 통과하여, 메모리에'도' 기록
      Write Back : 캐시에'만' 기록하고, 돌아감
        - Mark the cache block as Dirty / Changed
        - When the Block is evicted Copy the Block to Memory

    *Write Back has a bigger Miss Penalty
    *Write Through has a bigger Hit Time when writing

3) If the Block is no in the Cache,
    a) Evict a Block from the cache  *evict: 쫓아내다   

    b) Write to Memory
    c) Copy the Block to the empty space in the cache

 


//Tradeoffs
- Write Through has a faster Eviction time
- Write Back has a faster write time

 


//How to choose which Block to evict?

Replacement Algorithm: The Method used to choose which Block to Evict

1) Direct Mapping
2) Fully Associative
3) Set Associative

 

//Direct Mapping
1) Choose to evict the Block which has the most similar address to the Block which is being Read or Written
(그림)
Direct Mapping Address
(그림)


//Fully Associative

(그림)
- Always evict the Block which was Least Recently accessed
- Each Block has an age
- The age is set to zero when the Block is accessed
- Evict the Block with the highest age
(그림)
-> A Cache Block can come from anywhere in Memory
Fully Associative Address

//Set Associative cache

(그림)

- Has features of a Direct Mapped Cache and a Fully Associative Cache
- Memory and the Cache are Divided into sets
- Choose the Set with the most similar address to the requested address
- Evict the oldest Block in the Set
(그림)
Set Associative Address

//Terms

- Cache Hit: Data is found in the Cache
- Cache Miss: Block is not found in the Cache
- Hit Rate = # of Cache Hits / # of Requests
- Miss Rate = # of Cache Misses / # of Requests
- Hit Time = Time to access Data in the Cache
- Miss Time = Time to access Data in Memory
- Miss Penalty = Miss Time - Hit Time

//Memory Access Time
Access Time

= (Hit Time x Hit Rate) + (Miss Time x Miss Rate)
= (Hit Time x Hit Rate ) + ( (1 - Hit Rate) x Miss Time))
= Hit Rate x Hit Time + Miss Time - Hit Rate xMiss Time
= Miss Time - Hit Rate x Miss Penalty

//How does Block Size affect Access Time?
 (그림)

//Direct Mapped has no Locality of Time and so has a higher Miss Rate compared with Set Associative or Fully Associative
Direct Mapped is easier to build

Write Back has a bigger Miss Penalty
Write Through has a bigger Hit Time when writing