Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cache Memory.

Similar presentations


Presentation on theme: "Cache Memory."— Presentation transcript:

1 Cache Memory

2 Outline Memory Hierarchy Direct-Mapped Cache Write-Through, Write-Back
Cache replacement policy Examples

3 Principal of Locality Cache work on a principal known as locality of reference. This principal states asserts that programs continually use and re-use the same locations. -Instructions: Loops, common subroutines -Data: Look-up Tables, data sets(arrays) Temporal Locality (locality in time):Same location will be referenced again soon Spatial Locality (locality in space):Nearby locations will be referenced soon

4 The Tradeoff cache virtual memory larger, slower, cheaper
CPU C a c h e C a c h e Memory 16 B 8 B 4 KB disk regs register reference L1-cache reference L2-cache reference memory reference disk memory reference size: speed: $/Mbyte: block size: 608 B 1.4 ns 4 B 128k B 4.2 ns 4 B 512kB -- 4MB 16.8 ns $90/MB 16 B 128 MB 112 ns $2-6/MB 4-8 KB 27GB 9 ms $0.01/MB larger, slower, cheaper (Numbers are for a DEC Alpha at 700MHz)

5 MOORE’s LAW Time 1000 Performance 100 10 1
Processor-DRAM Memory Gap (latency) µProc 60%/yr. (2X/1.5yr) 1000 CPU “Moore’s Law” 100 Processor-Memory Performance Gap: (grows 50% / year) Performance 10 DRAM 9%/yr. (2X/10 yrs) Y-axis is performance X-axis is time Latency Cliché: Not e that x86 didn’t have cache on chip until 1989 DRAM 1 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 Time

6 Levels in memory hierarchy
Processor Increasing Distance from Proc., Decreasing cost / MB Levels in memory hierarchy Higher Level 1 Level 2 Level n Level 3 . . . Lower Size of memory at each level

7 Cache Design How do we organize cache? Where does each memory address map to? (Remember that cache is subset of memory, so multiple memory addresses map to the same cache location.) How do we know which elements are in cache? How do we quickly locate them?

8 Cache mappings There are three types of methods for mapping between the main memory addresses and the cache addresses. Fully associative cache Direct mapped cache Set associative cache

9 Direct-Mapped Cache In a direct-mapped cache, each memory address is associated with one possible block within the cache Therefore, we only need to look in a single location in the cache for the data if it exists in the cache Block is the unit of transfer between cache and memory

10 Cache Location 0 can be occupied by data from:
Direct-Mapped Cache 4 Byte Direct Mapped Cache Cache Index 1 2 3 Memory Memory Address 1 2 3 4 5 6 7 8 9 A B C D E F Let’s look at the simplest cache one can build. A direct mapped cache that only has 4 bytes. In this direct mapped cache with only 4 bytes, location 0 of the cache can be occupied by data form memory location 0, 4, 8, C, ... and so on. While location 1 of the cache can be occupied by data from memory location 1, 5, 9, ... etc. So in general, the cache location where a memory location can map to is uniquely determined by the 2 least significant bits of the address (Cache Index). For example here, any memory location whose two least significant bits of the address are 0s can go to cache location zero. With so many memory locations to chose from, which one should we place in the cache? Of course, the one we have read or write most recently because by the principle of temporal locality, the one we just touch is most likely to be the one we will need again soon. Of all the possible memory locations that can be placed in cache Location 0, how can we tell which one is in the cache? +2 = 22 min. (Y:02) Cache Location 0 can be occupied by data from: Memory location 0, 4, 8, ... In general: any memory location that is multiple of 4

11 Issues with Direct-Mapped
Since multiple memory addresses map to same cache index, how do we tell which one is in there? What if we have a block size > 1 byte? Result: divide memory address into three fields ttttttttttttttttt iiiiiiiiii oooo tag index byte to check to offset if have select within correct block block block

12 Direct-Mapped Cache Terminology
All fields are read as unsigned integers. Index: specifies the cache index (which “row” of the cache we should look in) Offset: once we’ve found correct block, specifies which byte within the block we want Tag: the remaining bits after offset and index are determined; these are used to distinguish between all the memory addresses that map to the same location

13 Increased Miss Penalty
Block Size Tradeoff Conclusions Exploits Spatial Locality Fewer blocks: compromises temporal locality Miss Rate Block Size Average Access Time Block Size Increased Miss Penalty & Miss Rate

14 Direct-Mapped Cache Example
Suppose we have a 16KB of data in a direct-mapped cache with 4 word blocks Determine the size of the tag, index and offset fields if we’re using a 32-bit architecture Offset need to specify correct byte within a block block contains 4 words = 16 bytes = 24 bytes need 4 bits to specify correct byte

15 Direct-Mapped Cache Example
Index: (~index into an “array of blocks”) need to specify correct row in cache cache contains 16 KB = 214 bytes block contains 24 bytes (4 words) # rows/cache =# blocks/cache (since there’s one block/row) = bytes/cache bytes/row = 214 bytes/cache bytes/row = 210 rows/cache need 10 bits to specify this many rows

16 Direct-Mapped Cache Example
Tag: use remaining bits as tag tag length = mem addr length - offset - index = bits = 18 bits so tag is leftmost 18 bits of memory address Why not full 32 bit address as tag? All bytes within block need same address (-4b) Index must be same for every address within a block, so its redundant in tag check, thus can leave off to save memory (- 10 bits in this example)

17 Accessing data in a direct mapped cache
Memory Value of Word Address (hex) C a b c d ... C e f g h C i j k l Ex.: 16KB of data, direct-mapped, 4 word blocks Read 4 addresses 0x , 0x C, 0x , 0x Memory values on right: only cache/memory level of hierarchy

18 Accessing data in a direct mapped cache
4 Addresses: 0x , 0x C, 0x , 0x 4 Addresses divided (for convenience) into Tag, Index, Byte Offset fields Tag Index Offset

19 Accessing data in a direct mapped cache
So lets go through accessing some data in this cache 16KB data, direct-mapped, 4 word blocks Will see 4 types of events: Cache loading: Before any words and tags have been loaded into the cache, all locations contains invalid information. As lines are fetched from main memory into the cache, cache entries become valid. To represent this structure a valid bit added to each cache entry. cache miss: nothing in cache in appropriate block, so fetch from memory cache hit: cache block is valid and contains proper address, so read desired word cache miss, block replacement: wrong data is in cache at appropriate block, so discard it and fetch desired data from memory

20 Cache Loading Before any words and tags have been loaded into the cache, all locations contains invalid information. As lines are fetched from main memory into the cache, cache entries become valid. To represent this structure a valid bit added to each cache entry. This valid bit indicates that the associated cache line is valid(1) or invalid(0). If the valid bit is 0, then a cache miss occurs even if the tag matches the address from CPU, required addressed word to be taken from main memory.

21 16 KB Direct Mapped Cache, 16B blocks
Valid bit: determines whether anything is stored in that row (when computer initially turned on, all entries are invalid) ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Example Block Index

22 000000000000000000 0000000001 0100 Tag field Index field Offset 1 2 3
Read 0x = 0… Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index

23 So we read block 1 ( ) Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index

24 No valid data 000000000000000000 0000000001 0100 Tag field Index field
Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index

25 So load that data into cache, setting tag, valid
Tag field ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index field Offset Index 1 a b c d

26 Read from cache at offset, return word b
Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

27 Read 0x C = 0… Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

28 Data valid, tag OK, so read offset return word d
... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

29 Read 0x = 0… Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

30 So read block 3 Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

31 No valid data 000000000000000000 0000000011 0100 Tag field Index field
Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d

32 Load that cache block, return word f
Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d 1 e f g h

33 Read 0x = 0… Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d 1 e f g h

34 So read Cache Block 1, Data is Valid
Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d 1 e f g h

35 Cache Block 1 Tag does not match (0 != 2)
Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 a b c d 1 e f g h

36 Miss, so replace block 1 with new data & tag
Tag field Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 2 i j k l 1 e f g h

37 And return word j 000000000000000010 0000000001 0100 Tag field
Index field Offset ... Valid Tag 0x0-3 0x4-7 0x8-b 0xc-f 1 2 3 4 5 6 7 1022 1023 Index 1 2 i j k l 1 e f g h

38 Vector Product Example
float dot_prod(float x[1024], y[1024]) { float sum = 0.0; int i; for (i = 0; i < 1024; i++) sum += x[i]*y[i]; return sum; } Machine DEC Station 5000 MIPS Processor with 64KB direct-mapped cache, 16 B line size Performance Good case: 24 cycles / element Bad case: 66 cycles / element

39 Thrashing Example Access one element from each array per iteration
Cache Line y[1] Cache Line x[2] y[2] x[3] y[3] Cache Line Cache Line x[1020] y[1020] x[1021] Cache Line y[1021] Cache Line x[1022] y[1022] x[1023] y[1023] Access one element from each array per iteration

40 Thrashing Example: Good Case
y[0] x[1] y[1] Cache Line x[2] y[2] x[3] y[3] Access Sequence Read x[0] x[0], x[1], x[2], x[3] loaded Read y[0] y[0], y[1], y[2], y[3] loaded Read x[1] Hit Read y[1] • • • 2 misses / 8 reads Analysis x[i] and y[i] map to different cache lines Miss rate = 25% Two memory accesses / iteration On every 4th iteration have two misses

41 Thrashing Example: Bad Case
y[0] x[1] y[1] Cache Line x[2] y[2] x[3] y[3] Access Pattern Read x[0] x[0], x[1], x[2], x[3] loaded Read y[0] y[0], y[1], y[2], y[3] loaded Read x[1] Read y[1] 8 misses / 8 reads Analysis x[i] and y[i] map to same cache lines Miss rate = 100% Two memory accesses / iteration On every iteration have two misses

42 Average access time Average access time, ta, given by: ta = tc + (1 - h)tm assuming again that the first access must be to the cache before an access is made to the main memory. Only read requests are consider so far. Example If hit ratio is 0.85 (a typical value), main memory access time is 50 ns and cache access time is 5 ns, then average access time is *50 = 12.5 ns. THROUGHOUT tc is the time to access the cache, get (or write) the data if a hit or recognize a miss. In practice, these times could be different.

43 Example-1 Assume Average memory access time=tc+m*tm or =tc*h+(tm+tc)*m
Hit Time = 1 cycle Miss rate = 5% Miss penalty = 20 cycles Average memory access time=tc+m*tm (m:miss rate, h:hit rate, tm: main memory access time, tc: Cache access time) Average memory access time = x 20=2 cycle or =tc*h+(tm+tc)*m 1x x0.05=2 cycle

44 Example-2 Assume L1 miss penalty = 5 + 0.15 * 100 = 20
L1 Hit Time = 1 cycle L1 Miss rate = 5% L2 Hit Time = 5 cycles L2 Miss rate = 15% (% L1 misses that miss) L2 Miss Penalty = 100 cycles L1 miss penalty = * 100 = 20 Average memory access time = x = 2 cycle

45 Replacement Algorithms
When a block is fetched, which block in the target set should be replaced? Optimal algorithm: replace the block that will not be used for the longest time (must know the future) Usage based algorithms: Least recently used (LRU) replace the block that has been referenced least recently hard to implement Non-usage based algorithms: First-in First-out (FIFO) treat the set as a circular queue, replace head of queue. easy to implement Random (RAND) replace a random block in the set even easier to implement

46 Implementing RAND and FIFO
maintain a modulo E counter for each set. counter in each set points to next block for replacement. increment counter with each replacement. RAND: maintain a single modulo E counter. counter points to next block for replacement in any set. increment counter according to some schedule: each clock cycle, each mem reference, or each replacement. LRU Need state machine for each set Encodes usage ordering of each element in set E! possibilities ==> ~ E log E bits of state

47 What Happens on a Write? Need to keep cache consistent with the main memory Reads are easy - require no modification Writes- when does the update occur Write-Through On cache write- always update main memory as well Write-Back On cache write- remember that block is modified (dirty) Update main memory when dirty block is replaced Sometimes need to flush cache (I/O, multiprocessing)

48 Performance trade-offs?
What to do on a write hit? Write-through update the word in cache block and corresponding word in memory Write-back update word in cache block allow memory word to be “stale” => add ‘dirty’ bit to each line indicating that memory needs to be updated when block is replaced => OS flushes cache before I/O !!! Performance trade-offs?

49 Write Through Store by processor updates cache and memory
Memory always consistent with cache ~2X more loads than stores WT always combined with write buffers so that don’t wait for lower level memory Memory Store Processor Cache Load Cache Load

50 Write Back Store by processor only updates cache line
Modified line written to memory only when it is evicted Requires “dirty bit” for each line Set when line in cache is modified Indicates that line in memory is stale Memory not always consistent with cache No writes of repeated writes Processor Write Back Memory Store Cache Load Cache Load

51 Store Miss? Write-Allocate No-write Allocate
Bring written block into cache Update word in block Anticipate further use of block No-write Allocate Main memory is updated Cache contents unmodified

52 Handling stores (write-through)
Processor Cache Memory 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 150 162 173 18 21 33 R0 R1 R2 R3 28 19 Misses: 0 Hits: 200 210 225

53 write-through (REF 1) Processor Cache Memory 78 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 150 162 173 18 21 33 R0 R1 R2 R3 28 19 Misses: 0 Hits: 200 210 225

54 write-through (REF 1) Processor Cache Memory 78 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 78 150 29 162 lru 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 1 Hits: 200 210 225

55 write-through (REF 2) Processor Cache Memory 78 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 78 150 29 162 lru 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 1 Hits: 200 210 225

56 write-through (REF 2) Processor Cache Memory 78 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 78 150 29 162 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

57 write-through (REF 3) Processor Cache Memory 78 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 78 150 29 162 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

58 write-through (REF 3) Processor Cache Memory 173 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 173 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 173 1 150 29 162 lru 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

59 write-through (REF 4) Processor Cache Memory 173 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 173 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 173 150 29 162 lru 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

60 write-through (REF 4) Processor Cache Memory 173 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 173 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 173 29 150 29 162 1 2 71 173 29 150 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 3 Hits: 173 200 210 225

61 write-through (REF 5) Processor Cache Memory 173 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 173 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 173 29 29 162 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 3 Hits: 173 200 210 225

62 write-through (REF 5) Processor Cache Memory 173 29 120 123 V tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 173 29 120 123 V tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 5 33 29 28 162 lru 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 4 Hits: 33 200 210 225

63 How many memory references?
Each miss reads a block 2 bytes in this cache Each store writes a byte Total reads: 8 bytes Total writes: 2 bytes but caches generally miss < 20%

64 Write-through vs. write-back
D the cache to NOT write all stores to memory immediately? Keep the most current copy in the cache and update the memory when that data is evicted from the cache (a write-back policy). write-back all evicted lines? No, only blocks that have been stored into Keep a “dirty bit”, reset when the line is allocated, set when the block is stored into. If a block is “dirty” when evicted, write its data back into memory.

65 Handling stores (write-back)
Processor Cache Memory 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 150 162 173 18 21 33 R0 R1 R2 R3 28 19 Misses: 0 Hits: 200 210 225

66 write-back (REF 1) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 150 162 173 18 21 33 R0 R1 R2 R3 28 19 Misses: 0 Hits: 200 210 225

67 write-back (REF 1) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 78 150 29 162 lru 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 1 Hits: 200 210 225

68 write-back (REF 2) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 78 150 29 162 lru 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 1 Hits: 200 210 225

69 write-back (REF 2) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 78 150 29 162 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

70 write-back (REF 3) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 78 150 29 162 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

71 write-back (REF 3) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 1 173 150 29 162 lru 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

72 write-back (REF 4) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 1 173 150 29 162 lru 1 3 162 173 173 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 2 Hits: 173 200 210 225

73 write-back (REF 4) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 1 173 150 29 162 1 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 3 Hits: 173 200 210 225

74 write-back (REF 5) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 1 173 150 29 162 1 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 3 Hits: 173 200 210 225

75 write-back (REF 5) Processor Cache Memory 78 173 29 120 123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 173 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 lru 1 1 173 150 29 162 1 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 4 Hits: 173 200 210 225

76 write-back (REF 5) Processor Cache Memory 78 29 120 123 V d tag data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 78 29 120 123 V d tag data Ld R1  M[ ] Ld R2  M[ ] St R2  M[ ] St R1  M[ ] Ld R2  M[ 10 ] 71 1 5 33 150 28 162 lru 1 1 2 71 173 29 18 21 33 R0 R1 R2 R3 28 29 19 Misses: 4 Hits: 33 200 210 225

77 How many memory references?
Each miss reads a block 2 bytes in this cache Each evicted dirty cache line writes a block Total reads: 8 bytes Total writes: 4 bytes (after final eviction) Choose write-back or write-through?


Download ppt "Cache Memory."

Similar presentations


Ads by Google