11 Memory Hierarchy
11 Memory Hierarchy
11 Memory Hierarchy
Instructors:
Randal E. Bryant and David. R. O’Hallaron
Today
Storage technologies and trends
Locality of reference
Caching in the memory hierarchy
Nonvolatile Memories
DRAM and SRAM are volatile memories
▪ Lose information if powered off.
Nonvolatile memories retain value even if powered off
▪ Read-only memory (ROM): programmed during production
▪ Programmable ROM (PROM): can be programmed once
▪ Eraseable PROM (EPROM): can be bulk erased (UV, X-Ray)
▪ Electrically eraseable PROM (EEPROM): electronic erase capability
▪ Flash memory: EEPROMs. with partial (block-level) erase capability
▪ Wears out after about 100,000 erasings
Uses for Nonvolatile Memories
▪ Firmware programs stored in a ROM (BIOS, controllers for disks,
network cards, graphics accelerators, security subsystems,…)
▪ Solid state disks (replace rotating disks in thumb drives, smart
phones, mp3 players, tablets, laptops,…)
▪ Disk caches
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 5
Carnegie Mellon
CPU chip
Register file
ALU
I/O Main
Bus interface
bridge memory
ALU
%rax
Main memory
I/O bridge 0
A
Bus interface x A
ALU
%rax
Main memory
I/O bridge x 0
Bus interface x A
ALU
%rax x
Main memory
I/O bridge 0
Bus interface x A
ALU
%rax y
Main memory
I/O bridge 0
A
Bus interface A
ALU
%rax y
Main memory
I/O bridge 0
y
Bus interface A
ALU
%rax y
main memory
I/O bridge 0
Bus interface y A
Actuator
Electronics
(including a
processor
SCSI and memory!)
connector
Image courtesy of Seagate Technology
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 13
Carnegie Mellon
Disk Geometry
Disks consist of platters, each with two surfaces.
Each surface consists of concentric rings called tracks.
Each track consists of sectors separated by gaps.
Tracks
Surface
Track k Gaps
Spindle
Sectors
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 14
Carnegie Mellon
Surface 0
Platter 0
Surface 1
Surface 2
Platter 1
Surface 3
Surface 4
Platter 2
Surface 5
Spindle
Disk Capacity
Capacity: maximum number of bits that can be stored.
▪ Vendors express capacity in units of gigabytes (GB), where
1 GB = 109 Bytes.
Capacity is determined by these technology factors:
▪ Recording density (bits/in): number of bits that can be squeezed
into a 1 inch segment of a track.
▪ Track density (tracks/in): number of tracks that can be squeezed
into a 1 inch radial segment.
▪ Areal density (bits/in2): product of recording and track density.
Recording zones
Modern disks partition tracks
into disjoint subsets called
recording zones
…
▪ Each track in a zone has the same
number of sectors, determined
by the circumference of
innermost track. Spindle
▪ Each zone has a different number
of sectors/track, outer zones
have more sectors/track than
inner zones.
▪ So we use average number of
sectors/track when computing
capacity.
spindle
spindle
spindle
spindle
Arm
Spindle
Disk Access
Disk Access
Rotation is counter-clockwise
After BLUE read Seek for RED Rotational latency After RED read
After BLUE read Seek for RED Rotational latency After RED read
I/O Bus
CPU chip
Register file
ALU
System bus Memory bus
I/O Main
Bus interface
bridge memory
Main
Bus interface
memory
I/O bus
Main
Bus interface
memory
I/O bus
Main
Bus interface
memory
I/O bus
Sequential read tput 550 MB/s Sequential write tput 470 MB/s
Random read tput 365 MB/s Random write tput 303 MB/s
Avg seq read time 50 us Avg seq write time 60 us
Disadvantages
▪ Have the potential to wear out
Mitigated by “wear leveling logic” in flash translation layer
▪
▪ E.g. Intel SSD 730 guarantees 128 petabyte (128 x 1015 bytes) of
writes before they wear out
▪ In 2015, about 30 times more expensive per byte
Applications
▪ MP3 players, smart phones, laptops
▪ Beginning to appear in desktops and servers
100,000,000.0
10,000,000.0 Disk
1,000,000.0
100,000.0
SSD
1.0
0.1
CPU
0.0
1985 1990 1995 2000 2003 2005 2010 2015
Year
Today
Storage technologies and trends
Locality of reference
Caching in the memory hierarchy
Locality
Principle of Locality: Programs tend to use data and
instructions with addresses near or equal to those they
have used recently
Temporal locality:
▪ Recently referenced items are likely
to be referenced again in the near future
Spatial locality:
▪ Items with nearby addresses tend
to be referenced close together in time
Locality Example
sum = 0;
for (i = 0; i < n; i++)
sum += a[i];
return sum;
Data references
▪ Reference array elements in succession
(stride-1 reference pattern). Spatial locality
▪ Reference variable sum each iteration. Temporal locality
Instruction references
▪ Reference instructions in sequence. Spatial locality
▪ Cycle through loop repeatedly. Temporal locality
Locality Example
Question: Does this function have good locality with
respect to array a?
Locality Example
Question: Can you permute the loops so that the function
scans the 3-d array a with a stride-1 reference pattern
(and thus has good spatial locality)?
Memory Hierarchies
Some fundamental and enduring properties of hardware
and software:
▪ Fast storage technologies cost more per byte, have less capacity,
and require more power (heat!).
▪ The gap between CPU and main memory speed is widening.
▪ Well-written programs tend to exhibit good locality.
Today
Storage technologies and trends
Locality of reference
Caching in the memory hierarchy
Example Memory
Hierarchy L0:
Regs CPU registers hold words
Smaller, retrieved from the L1 cache.
faster, L1: L1 cache
and (SRAM) L1 cache holds cache lines
costlier retrieved from the L2 cache.
L2: L2 cache
(per byte)
(SRAM)
storage L2 cache holds cache lines
devices retrieved from L3 cache
L3: L3 cache
(SRAM)
L3 cache holds cache lines
retrieved from main memory.
Larger,
slower, L4: Main memory
and (DRAM) Main memory holds
cheaper disk blocks retrieved
(per byte) from local disks.
storage L5: Local secondary storage
devices (local disks)
Local disks hold files
retrieved from disks
on remote servers
L6: Remote secondary storage
(e.g., Web servers)
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 51
Carnegie Mellon
Caches
Cache: A smaller, faster storage device that acts as a staging
area for a subset of the data in a larger, slower device.
Fundamental idea of a memory hierarchy:
▪ For each k, the faster, smaller device at level k serves as a cache for the
larger, slower device at level k+1.
Why do memory hierarchies work?
▪ Because of locality, programs tend to access the data at level k more
often than they access the data at level k+1.
▪ Thus, the storage at level k+1 can be slower, and thus larger and
cheaper per bit.
Big Idea: The memory hierarchy creates a large pool of
storage that costs as much as the cheap storage near the
bottom, but that serves data to programs at the rate of the
fast storage near the top.
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 52
Carnegie Mellon
4 5 6 7
8 9 10 11
12 13 14 15
Block b is in cache:
Cache 8 9 14 3
Hit!
Memory 0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Capacity miss
▪ Occurs when the set of active cache blocks (working set) is larger than
the cache.
Web cache Web pages Remote server disks 1,000,000,000 Web proxy
server
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 57
Carnegie Mellon
Summary
The speed gap between CPU, memory and mass storage
continues to widen.
Supplemental slides
16 x 8 DRAM chip
Cols
0 1 2 3
RAS = 2
2
/ 0
addr
1
Rows
Memory
controller 2
8 3
/
data
supercell 3
8
(2,1) /
data
supercell
Internal row buffer
(2,1)
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 62
Carnegie Mellon
Memory Modules
addr (row = i, col = j)
: supercell (i,j)
DRAM 0
64 MB
memory module
DRAM 7
consisting of
eight 8Mx8 DRAMs
63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 0
Memory
controller
64-bit word main memory address A
64-bit word
Enhanced DRAMs
Basic DRAM cell has not changed since its invention in 1966.
▪ Commercialized by Intel in 1970.
DRAM cores with better interface logic and faster I/O :
▪ Synchronous DRAM (SDRAM)
▪ Uses a conventional clock signal instead of asynchronous control
▪ Allows reuse of the row addresses (e.g., RAS, CAS, CAS, CAS)
Storage Trends
SRAM
Metric 1985 1990 1995 2000 2005 2010 2015 2015:1985
Disk
Metric 1985 1990 1995 2000 2005 2010 2015 2015:1985
CPU 80286 80386 Pentium P-4 Core 2 Core i7(n) Core i7(h)
Clock
rate (MHz) 6 20 150 3,300 2,000 2,500 3,000 500
Cycle
time (ns) 166 50 6 0.30 0.50 0.4 0.33 500
Cores 1 1 1 1 2 4 4 4
Effective
cycle 166 50 6 0.30 0.25 0.10 0.08 2,075
time (ns)