Docsity

Cache Basics: Understanding Memory Hierarchy and Cache Organization in Computer Science, Study notes of Computer Science

Partial preview of the text

Download Cache Basics: Understanding Memory Hierarchy and Cache Organization in Computer Science and more Study notes Computer Science in PDF only on Docsity!

CS240 Computer Organization

Department of Computer Science

Wellesley College

Exploiting memory hierarchy

Cache basics

Cache basics 20-

< ns 32 high CPU

Basic structure of memory hierarchy

CPU

registers

Cache

Main

memory

Magnetic

disk

Speed Size Cost ($/bits) Technology

0.5-5 ns KB-MB $4K-$10K SRAM

per GB

50-70 ns MB-GB $100-$200 DRAM

per GB

5M-10M ns GB-TB $.50-$2 Magnetic

per GB disk

Cache basics 20-

Copying blocks of information

o A memory hierarchy can

consist of many levels,

but data is copied

between only two

adjacent levels at a time.

o We focus on just two

levels: the upper -- the

one closer to the

processor -- and the

lower.

Processor

Data block is

transferred

Cache basics 20-

Batting average

o If the data requested by the

processor appears in the

some block in the upper

level, it’s a hit. Otherwise,

it’s a miss.

o The hit ratio is the fraction

hits to total requests.

o Hit time is the time to access

the upper level of memory.

o Miss penalty is the time to

replace a block in the upper

level with the corresponding

block from the lower level,

plus the time to deliver this

block

Processor

Data block is

transferred

Cache basics 20-

Miss rate versus block size

o Larger blocks exploit

spatial locality to lower

the miss rates.

o However, the miss rate

may increase if the block

size becomes significant

fractional of the cache

size. Why?

o Increased block size also

increases the miss

penalty.

1 KB

8 KB

16 KB

64 KB

256 KB

M

i

s

s

r

a

t

e

Block size (bytes)

Cache basics 20-

Handling cache misses

  1. Send the original PC value

(current PC - 4) to the

memory.

  1. Instruct main memory to

perform a read and wait for

the memory to complete its

access.

  1. Write the cache, putting the

data from memory in the

data portion, writing the

upper bits of the address

into the tag field, and turning

the valid bit on.

  1. Restart the instruction

execution at the first step,

which will refetch the

instruction.

Cache basics 20-

What’s wrong with this picture?

Processor

A store

instruction

writes data

into the cache

Cache basics 20-

Write-through

Processor

A store

instruction

writes data

into the cache

and memory

at the same

time

Cache basics 20-

An example: Intrinsity FastMATH

o MIPS architecture with a

12-stage pipeline and a

simple cache

implementation.

o To pipeline without

stalling, separate

instruction and data

caches are used.

o Each cache is 16 KB, or 4K

words, with 16-word

blocks.

Cache basics 20-

256 block cache with 16 words per block

Address (showing bit positions)

Data Hit

Data

Tag

V Tag

Index

18 8 Byte

offset

Block offset

entries

18 bits 512 bits

Mux

Cache basics 20-

Approximate instruction and data

misses for SPEC2000 benchmarks

Instruction Data Effective

miss rate miss rate combined miss rate

0.4% 11.4% 3.2%

*This isn’t the whole story, the ultimate measure is the effect of

memory on program execution time. More soon...

Cache basics 20-

Increasing physical or logical memory width

CPU

Cache

Memory

Bus

One-word-wide

memory organization

a.

b. Wide memory organization

CPU

Cache

Memory

Bus

Multiplexor

CPU

Cache

Bus

Memory

bank 0

Memory

bank 1

Memory

bank 2

Memory

bank 3

c. Interleaved memory organization

*Assume four word cache block; 1 bus cycle to send address; 15 bus

cycles for each DRAM access initiate; 1 bus cycle to send word.