The Memory Hierarchy

Class: CSCE-312


Notes:

Today

Random-Access Memory (RAM)

SRAM vs DRAM Summary

Pasted image 20251106135829.png

Nonvolatile Memories

"read only memory"

Traditional Bus Structure Connecting CPU and Memory

Pasted image 20251111125116.png|600

Memory Read Transaction (1)

Memory Read Transaction (2)

Memory Read Transaction (3)

Memory Write Transaction

What's Inside a Disk Drive?

Pasted image 20251111131027.png|425

Disk Geometry

Pasted image 20251111131316.png|475

Disk geometry (Muliple-Platter View)

Pasted image 20251111131438.png|300

Disk Capacity

Recording zones

Pasted image 20251124125046.png|250

Computing Disk Capacity

Capacity = (# bytes/sector) x (avg. # sectors/track) x (# tracks/surface) x (# surfaces/platter) x (# platters/disk)

Example:

Capacity = 512 x 300 x 20000 x 2 x 5 = 30,720,000,000 = 30.72 GB

Disk Operation (Single-Platter View)

Pasted image 20251111131820.png|600

Disk Operation (Multi-Platter View)

Pasted image 20251124131322.png|300

Disk Access

Pasted image 20251111160233.png|120

Disk Access - Service Time Components

Pasted image 20251124131626.png|500

  1. Head in position above a track
  2. Rotation is counter-clockwise
  3. About to read sector
  4. After reading blue sector
  5. Red request scheduled next
  6. Seek to red's track
  7. Wait for red sector to rotate around
  8. Complete read of red

Disk Access Time

Notes:

Disk Access Time Example

Logical Disk Blocks

Notes;

I/O Bus

Pasted image 20251111133011.png|600

Reading Sector

Solid State Disks (SSDs)

Pasted image 20251111133412.png|600

Notes:

SSD Performance Characteristics

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

The CPU-Memory Gap

The gap widens between DRAM, disk, and CPU speeds.

Pasted image 20251111133544.png|700

Locality to the Rescue!

The key to bridging this CPU-Memory gap is a fundamental property of computer programs known as locality

Locality

Locality

Notes:

Locality Example

sum = 0;
for (i = 0; i < n; i++)
	sum += a[i];
return sum;

Qualitative Estimates of Locality

int sum_array_rows(int a[M][N])
{
    int i, j, sum = 0;

    for (i = 0; i < M; i++)
        for (j = 0; j < N; j++)
            sum += a[i][j];
    return sum;
}

Locality Example (1)

int sum_array_cols(int a[M][N])
{
    int i, j, sum = 0;

    for (j = 0; j < N; j++)
        for (i = 0; i < M; i++)
            sum += a[i][j];
    return sum;
}

Locality Example (2)

int sum_array_3d(int a[M][N][N])
{
    int i, j, k, sum = 0;
	
    for (i = 0; i < M; i++)
        for (j = 0; j < N; j++)
            for (k = 0; k < N; k++)
                sum += a[k][i][j];
    return sum;
}

In C, a 3-D array a[M][N][N] is stored so that the rightmost index varies fastest in memory. So these are contiguous:

a[x][y][0], a[x][y][1], a[x][y][2], ...

A stride-1 reference pattern means the innermost loop should change the last subscript. To fix the above code, make the loop over j innermost (so we walk contiguous memory), and move k outside:

int sum_array_3d(int a[M][N][N])
{
    int i, j, k, sum = 0;
	
    for (k = 0; k < M; k++)        // k indexes the first dimension
        for (i = 0; i < N; i++)    // i indexes the second
            for (j = 0; j < N; j++)// j indexes the last -> stride-1
                sum += a[k][i][j];
    return sum;
}

Now, for fixed k and i, j runs through:

a[k][i][0], a[k][i][1], a[k][i][2], ...

Memory Hierarchies

Notes:

Caching in the memory hierarchy

Example Memory Hierarchy

Pasted image 20251111135154.png|600

Summary:

Level Tech Size Latency Notes
Registers Flip-flops Bytes ~1 cycle Inside CPU core
L1 Cache SRAM 16–64 KB 1–4 cycles Very fast, very small
L2 Cache SRAM 256 KB–2 MB 5–12 cycles Per core usually
L3 Cache SRAM MBs 20–50 cycles Shared across cores
DRAM DRAM GBs ~200 cycles Main memory
SSD Flash TBs ~100 µs Much slower
HDD Magnetic TBs ~10 ms Very slow
Network Storage Remote TB–PB ms range Slowest level

Notes:

Caches

Notes:

General Cache Concepts

Pasted image 20251111135840.png|600

General Cache Concepts: Hit

Pasted image 20251111162256.png|550

General Cache Concepts: Miss

Pasted image 20251111162332.png|550

General Caching Concepts: Types of Cache Misses

Examples of Caching in the Mem. Hierarchy

Pasted image 20251111162909.png|600

Summary