Docsity

Memory Systems: SRAM, DRAM, Caches, and Virtual Memory, Slides of Computer Science

Toggle sidebar
bg1
Memories: Review
•SRAM:
–value is stored on a pair of inverting gates
–very fast but takes up more space than DRAM (4
to 6 transistors)
•DRAM:
–value is stored as a charge on capacitor (must be
refreshed)
–very small but slower than SRAM (factor of 5 to
10)
B
AA
B
Word line
Pass transistor
Capacitor
Bit line
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Memory Systems: SRAM, DRAM, Caches, and Virtual Memory and more Slides Computer Science in PDF only on Docsity!

Memories: Review

• SRAM:

– value is stored on a pair of inverting gates

– very fast but takes up more space than DRAM (

to 6 transistors)

• DRAM:

– value is stored as a charge on capacitor (must be

refreshed)

– very small but slower than SRAM (factor of 5 to

B
A A
B

Word line

Pass transistor

Capacitor

Bit line

Exploiting Memory Hierarchy

• Users want large and fast memories!

SRAM access times are 2 - 25ns at cost of $100 to

$250 per Mbyte.

DRAM access times are 60-120ns at cost of $5 to

$10 per Mbyte.

Disk access times are 10 to 20 million ns at cost

of $.10 to $.20 per Mbyte.

• Try and give it to them anyway

– build a memory hierarchy

CPU

Level n

Level 2

Level 1

Levels in the memory hierarchy

Increasing distance from the CPU in access time

Size of the memory at each level

Cache

• Two issues:

– How do we know if a data item is in the cache?

– If it is, how do we find it?

• Our first example:

– block size is one word of data

– "direct mapped"

For each item of data at the lower level,

there is exactly one location in the cache where it might be.

e.g., lots of items at the lower level share locations in the upper level

Direct Mapped Cache

• Mapping: address is modulo the number of

blocks in the cache

Cache

Memory

Direct Mapped Cache

• Taking advantage of spatial locality:

Address (showing bit positions)

16 12 Byte offset

V Tag Data

Hit Data

4K

entries

16 bits 128 bits

Mux

Index Block offset

Tag

Hits vs. Misses

• Read hits

– this is what we want!

• Read misses

– stall the CPU, fetch block from memory, deliver to cache,

restart

• Write hits:

– can replace data in cache and memory (write-through)

– write the data only into the cache (write-back the cache

later)

• Write misses:

– read the entire block into the cache, then write the word

Hardware Issues

• Make reading multiple words easier by using banks of memory

• It can get a lot more complicated...

CPU

Cache

Bus

Memory

a. One-word-wide memory organization

CPU

Bus

b. Wide memory organization

Memory

Multiplexor

Cache

CPU

Cache

Bus

Memory bank 1

Memory bank 2

Memory bank 3

Memory bank 0

c. Interleaved memory organization

Designing the memory system to support

caches

  • Example:

1 clock cycle to send the address

15 clock cycles for each DRAM access initiated

1 clock cycle to send a word of data

Cache block of 4 words

 miss penalty:

one-word-wide bank of DRAMS  1 + 4 X 15 + 4 X1 = 65 clock cycles

#bytes transfer / clock cycle = (4 X 4) / 65 = 0.

2-word-wide bank of DRAMS  1 + 2 X 15 + 2 X1 = 33 clock cycles

#bytes transfer / clock cycle = (4 X 4) / 33 = 0.

4-word-wide bank of DRAMS  1 + 15 + 1 = 17 clock cycles

#bytes transfer / clock cycle = (4 X 4) / 17 = 0.

 wider bus: additional buffers at the memory

 Interleaving: miss penalty = send addr. To the cache + all 4 banks to access

memory simultaneously + send 4 words back to the cache

 1 + 1 X 15 + 4 X 1 = 20 clock cycles

#bytes transfer / clock cycle = (4 X 4) / 20 = 0.

Performance

• Simplified model:

execution time = (execution cycles + stall

cycles) X cycle time

stall cycles = # of instructions X miss ratio X

miss penalty

• Two ways of improving performance:

– decreasing the miss ratio

Taking advantage of spatial locality

• Increasing the block size

– decreasing miss rate  spatial locality

– increasing miss rate  decreasing # blocks that can

be held in the

cache

• Block transfer

– Early restart: to resume execution as soon as the

request word of the block is returned

– Requested word first (critical word first): the

requested word is transferred from the memory to the

cache first. The remainder of the block is then

Decreasing miss ratio with

associativity

Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data

Eight-way set associative (fully associative)

Tag Data Tag Data Tag Data Tag Data

Four-way set associative Set 0 1

Tag Data

One way set associative (direct mapped) Block 0

Tag Data

Two-way set associative Set 0 1 2 3

Tag Data

An implementation

Index V Tag 0 1 2

253 254 255

Data V Tag Data V Tag Data V Tag Data

4-to-1 multiplexor

Hit Data

Decreasing miss penalty with multilevel caches

  • Add a second level cache:
    • often primary cache is on the same chip as the processor
    • use SRAMs to add another cache above primary memory (DRAM)
    • miss penalty goes down if data is in 2nd level cache
  • Example:
    • CPI of 1.0 on a 500Mhz machine with a 5% miss rate, 200ns DRAM access
    • Adding 2nd level cache with 20ns access time decreases miss rate to 2%

 One-level cache:

miss penalty to main memory = 200 ns / (2 ns /cycle) = 100 clock cycles

-- effective CPI with one-level caching:

total CPI = base CPI + memory stall cycles per instruction

= 1.0 + 5% X 100 = 6.

 two-level cache:

miss penalty for an access to the second-level cache = 20 / 2 = 10 clock cycles

total CPI = 1 + primary stalls per instruction + secondary stalls per instruction

= 1.0 + 5% X 10 + 2% X 100 = 3.

 The machine with the secondary cache is faster by 6.0 / 3.5 = 1.

  • Using multilevel caches:
    • try and optimize the hit time on the 1st level cache
    • try and optimize the miss rate on the 2nd level cache

Virtual Memory

• Main memory can act as a cache for the

secondary storage (disk)

Physical addresses

Disk addresses

Virtual addresses Address translation