LEC07 Memory Hierarchy
LEC07 Memory Hierarchy
Memory Hierarchy
Locality of reference
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
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 12
Disk Geometry
Disks consist of platters, each with two surfaces
Each surface consists of concentric rings called tracks
Each track consists of sectors
Aligned tracks form a cylinder
Cylinder k
Tracks
Surface
Surface 0 Track k
Surface 1 Platter 0
Surface 2
Surface 3 Platter 1
Surface 4
Surface 5
Platter 2
Sectors
Spindle
spindle
spindle
Arm
3. About to read
blue sector 4. After reading
blue sector
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
Advantages
No moving parts faster, less power, more rugged
Disadvantages
Have the potential to wear out
Mitigated by “wear leveling logic” in flash translation layer
In 2015, about 30 times more expensive per byte
Applications
MP3 players, smart phones, laptops
Recent desktops and servers
Clock
rate (MHz) 1 20 150 600 3300 2000 2500 2500
Cycle
time (ns) 1000 50 6 1.6 0.3 0.50 0.4 2500
Cores 1 1 1 1 1 2 4 4
Effective
cycle 1000 50 6 1.6 0.3 0.25 0.1 10,000
time (ns)
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
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition 27
Outline
Locality of reference
Larger, slower,
Main memory holds
and cheaper L4: Main memory disk blocks retrieved
(per byte) (DRAM) from local disks.
storage devices
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 30
Caches
Cache: A smaller, faster storage device that acts as a staging
area for a subset of the data in a larger, slower device.
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 31
General Cache Concepts
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
Locality of reference
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
Data references
Reference array elements in succession Spatial locality
(stride-1 reference pattern)
Reference variable sum each iteration Temporal locality
Instruction references
Reference instructions in sequence Spatial locality
Cycle through loop repeatedly Temporal locality
[ ]
𝒂 𝟎𝟎 𝒂 𝟎𝟏 𝒂 𝟎𝟐 𝒂 𝟎𝟑 a[0][1] 0x04
𝒂 𝟏𝟎 𝒂 𝟏𝟏 𝒂 𝟏𝟐 𝒂 𝟏𝟑
a[0][2] 0x08
𝒂 𝟐𝟎 𝒂 𝟐𝟏 𝒂 𝟐𝟐 𝒂 𝟐𝟑
a[0][3] 0x0C
a[1][0] 0x10
a[1][1] 0x14
a[1][2] 0x18
a[1][3] 0x1C
a[2][0] 0x20
a[2][1] 0x24
a[2][2] 0x28
a[2][3] 0x2C
[ ]
𝒂 𝟎𝟎 𝒂 𝟎𝟏 𝒂 𝟎𝟐 𝒂 𝟎𝟑 a[0][1] 0x04
𝒂 𝟏𝟎 𝒂 𝟏𝟏 𝒂 𝟏𝟐 𝒂 𝟏𝟑
a[0][2] 0x08
𝒂 𝟐𝟎 𝒂 𝟐𝟏 𝒂 𝟐𝟐 𝒂 𝟐𝟑
a[0][3] 0x0C
a[1][0] 0x10
a[1][1] 0x14
a[1][2] 0x18
a[1][3] 0x1C
a[2][0] 0x20
a[2][1] 0x24
a[2][2] 0x28
a[2][3] 0x2C