Docsity

Cache Memory Management: Selection, Replacement and Optimization - Prof. Alan L. Sussman, Assignments of Computer Science

Partial preview of the text

Download Cache Memory Management: Selection, Replacement and Optimization - Prof. Alan L. Sussman and more Assignments Computer Science in PDF only on Docsity!

Computer Systems Architecture

CMSC 411

Unit 5 – Memory Hierarchy

Alan Sussman

October 7, 2004

CMSC 411 - Alan Sussman 2

Administrivia

• HW #3 due today

  • questions

• Quiz 2 Tuesday, Oct. 12

  • on Unit 3, basic pipelining
  • practice quiz posted, answers posted later today
  • questions?

• Read Chapter 5

  • except 5.11-5.

CMSC 411 - Alan Sussman 3

Last time

  • Long instructions
    • can cause structural hazards, and WAW hazards – why?
    • detect hazards early, to allow precise exceptions
      • in ID pipeline stage, and delay EX cycle if problem detected
      • can delay WB, use history or future file, let OS deal with it, to enable precise exceptions
  • MIPS R4000 pipeline design
    • 8 stage pipeline – superpipelining
    • extra stages come from multi-cycle cache accesses
    • 2 cycle load delay and 3 cycle branch delay (1 delay slot, 2 cycle stall for taken branches)
    • complex FP pipeline – 8 stages used in different combinations for different operations

Cache Memory

CMSC 411 - Alan Sussman 7

Then add a cache

• Jargon: Each address of a memory location

is partitioned into

  • block address
    • tag
    • index
  • block offset

Fig. 5.

CMSC 411 - Alan Sussman 8

How does cache memory work?

• The following slides discuss:

  • what cache memory is
  • three organizations for cache memory
    • direct mapped.
    • set associative
    • fully associative
  • how the bookkeeping is done
  • Important note : All addresses shown are in

octal. Addresses in the book are usually decimal.

CMSC 411 - Alan Sussman 9

What is cache memory?

Main memory first

Main memory is divided into (cache) blocks. Each block contains many words (16-64 common now).

CMSC 411 - Alan Sussman 10

Main memory

Blocks are grouped into frames (pages), 3 frames in this picture.

CMSC 411 - Alan Sussman 13

Cache memory (cont.)

Initially, all the valid bits set to zero.

CMSC 411 - Alan Sussman 14

Cache memory (cont.)

Suppose want to load block 14 (octal) from memory into cache.

Three ways to organize cache

  • direct mapped
  • set associative
  • fully associative

CMSC 411 - Alan Sussman 15

Direct mapped cache

In direct mapped cache, block 14 can only be put in the cache block with address 4.

So the cache will no longer hold the block with memory address 74.

CMSC 411 - Alan Sussman 16

Direct mapped cache (cont.)

After the load, the contents look like this.

CMSC 411 - Alan Sussman 19

Note that the last two bits of the memory block’s address always match the set number, so do not need to be stored. This part of the address is called the index. The higher order bits are stored, and are called the tag. In these pictures, both index and tag shown.

Set 0 Set 1 Set 2 Set 3

Set associative cache (cont.)

CMSC 411 - Alan Sussman 20

Set associative cache replacement

• Which entry in the set to replace?

• Three common choices:

  • Replace an eligible random block
  • Replace the least recently used (LRU) block
    • can be hard to keep track of, so often only approximated
  • Replace the oldest eligible block (First In, First

Out, or FIFO)

CMSC 411 - Alan Sussman 21

Data cache replacement – Fig. 5.

256KB 92.2 92.1 92.5 92.1 92.1 92.5 92.1 92.1 92.

64KB 103.4 104.3 103.9 102.4 102.3 103.1 99.7 100.5 100.

16KB 114.1 117.3 115.5 111.7 115.1 113.3 109.0 111.8 110.

Size LRU Random FIFO LRU Random FIFO LRU Random FIFO

Two-way Four-way Eight-Way

SPEC2000, in misses per 1000 instructions Set associativity

Computer Systems Architecture

CMSC 411

Unit 5 – Memory Hierarchy

Alan Sussman

October 12, 2004

CMSC 411 - Alan Sussman 25

Last time (cont.)

  • Direct mapped cache
    • each memory block can only go into 1 cache block – use low order bits of block address
  • Set associative cache
    • multiple places for a memory block to go – the degree of set associativity is how many
    • don’t need to store the index (the set number), since its known from the cache block number – rest of block address is the tag
    • replacement policy determines which block to replace when new one is loaded (e.g., random, LRU, FIFO)

CMSC 411 - Alan Sussman 26

Fully associative cache

In fully associative cache, memory blocks may be stored anywhere.

So block 14 might be put in the first available block -- one with valid = 0.

CMSC 411 - Alan Sussman 27

Fully associative cache (cont.)

With this result.

CMSC 411 - Alan Sussman 28

Managing cache

Use direct mapped cache as an example.

After first read operation, cache memory looked like this.

Valid Dirty

CMSC 411 - Alan Sussman 31

Managing cache (cont.)

The block is valid in cache, so don’t need to fetch.

But the write operation sets the dirty bit for that block.

Valid Dirty

CMSC 411 - Alan Sussman 32

Managing cache (cont.)

The write operation sets the dirty bit for that block.

That means that the cached block is different from the memory block, so must eventually be written back. Valid Dirty

CMSC 411 - Alan Sussman 33

Managing cache (cont.)

Now suppose need to 10 42 53 14 25 66 77 read from a block not in cache.

If it is block 41, then must overwrite block

Valid Dirty

CMSC 411 - Alan Sussman 34

Write-through cache

In write-through caches, every write causes an immediate change both to cache and to main memory.

So the read just involves fetching the block.

Valid Dirty

CMSC 411 - Alan Sussman 37

Write through vs. write back

• Which is better?

  • Write back gives faster writes, since don't have

to wait for main memory

  • Write back is very efficient if want to modify

many bytes in a given block

  • But write back can slow down some reads,

since a cache miss might cause a write back

  • In multiprocessors, write through might be the

only correct solution. Why?

CMSC 411 - Alan Sussman 38

Cache summary

• Cache memory can be organized as direct

mapped, set associative, or fully associative

• Can be write-through or write-back

• Extra bits such as valid and dirty bits help

keep track of the status of the cache

Computer Systems Architecture

CMSC 411

Unit 5 – Memory Hierarchy

Alan Sussman

October 14, 2004

CMSC 411 - Alan Sussman 40

Administrivia

• HW for Unit 5 posted

  • due date TBD

• Quizzes returned Tuesday

  • answers already posted

• Grad school workshop Tuesday, Oct. 19, 5-

7PM, CSIC 2117

  • come ask questions to both faculty and current

grad students!