You are on page 1of 16

Lecture 10: Memory Organization y g

Todays topics: Cache hierarchies Cache Direct Map

1 M. Safayani

Locality y
Temporal l T l locality: if you used some d t recently, you lit d data tl will likely use it again

Spatial locality: if you used some data recently, you p y y y y will likely access its neighbors

2 M. Safayani

Memory Hierarchy y y
The faster Th f t memories are more expensive per bit th i i than the slower memories and thus smaller.

3 M. Safayani

Memory Hierarchy y y
A you go f th capacity and latency increase As further, it dl t i

Registers 1KB 1 cycle y

L1 data or instruction Cache 3 32KB 2 cycles

L2 cache 2MB 15 cycles 5 cyc es

Memory 1GB 300 cycles y

Disk 80 GB 10M cycles

4 M. Safayani

Cache
Wh d caches work? Why do h k? assume that there are two-level memory No hierarchy: average access time for data = 300 cycles 32KB 1-cycle L1 cache that has a hit rate of 95%: average access time = 0.95 x 1 + 0.05 x (301) = 16 cycles l
CPU Word access cache 512 x 8 Main Memory 32K x 8 Block transfer
5 M. Safayani

Accessing the Cache ( g (direct-mapped) pp )

6 M. Safayani

Accessing the Cache ( g (direct-mapped) pp )

00000

1220 2340 3450 4560 5670 6710 777 27 Cache 6710 Index 000 Tag 00 Data 1220

00777 01000

01777 02000 27777

Main memory
7 M. Safayani

Example ( p (direct-mapped) pp )
22(10110) 26(11010) 22(10110) 26(11010) 16(10000) 3 (00011) 16(10000) 18(10010)

8 M. Safayani

Example ( p (direct-mapped) pp )
22(10110) 26(11010) 22(10110) 26(11010) 16(10000) 3 (00011) 16(10000) 18(10010)

9 M. Safayani

Direct-mapped pp

10 M. Safayani

Direct-mapped pp

11 M. Safayani

Example ( p (Bits in a cache) )


How many total bits are required for a direct mapped cache with 16 KB of direct-mapped data and 4-word blocks, assuming a 32-bit address? Number f blocks=2^10 N b of bl k 2^10 Number of bits in each block:128 bits Tag=32-10-2-2 Valid bit=1 Total cache size:

12 M. Safayani

Computing Cache blocks p g

Block address=

13 M. Safayani

Direct-mapped pp

14 M. Safayani

Handling Cache Misses


1. Send the original PC value ( g (current PC 4) to the memory. ) y 2. Instruct main memory to perform a read and wait for the memory to complete its access. 3. Write the cache entry, putting the data from memory in the data portion of the entry writing the upper bits of the address (from the entry, ALU) into the tag field, and turning the valid bit on. 4. 4 Restart the instruction execution at the first step which will refetch step, the instruction, this time finding it in the cache.

15 M. Safayani

Handling Write
1. Write-through g Example: 10% of the instructions are stores the CPI without cache misses was 1.0 100 extra cycles on every write CPI becomes: 1.0 + 100 * 10% = 11 Solution: write buffer 2. Write-back

16 M. Safayani

You might also like