Docsity

Understanding the Memory Hierarchy: SRAM, DRAM, and Cache Memories, Study notes of Engineering Science and Technology

Toggle sidebar
bg1
Chapter 6
The Memory Hierarchy
To this point in our study of systems, we have relied on a simple model of a computer system as a CPU
that executes instructions and a memory system that holds instructions and data for the CPU. In our simple
model, the memory system is a linear array of bytes, and the CPU can access each memory location in a
constant amount of time. While this is an effective model as far as it goes, it does not reflect the way that
modern systems really work.
In practice, a memory system is a hierarchy of storage devices with different capacities, costs, and access
times. CPU registers hold the most frequently used data. Small, fast cache memories nearby the CPU act as
staging areas for a subset of the data and instructions stored in the relatively slow main memory. The main
memory stages data stored on large, slowdisks, which in turn often serve asstaging areas for data stored on
the disks or tapes of other machines connected by networks.
Memory hierarchies work because well-written programs tend to access the storage at any particular level
more frequently than they access the storage at the next lower level. So the storage at the next level can be
slower, and thus larger and cheaper per bit. The overall effect is a large pool of memory that costs as much
as the cheap storage near the bottom of the hierarchy, but that serves data to programs at the rate of the fast
storage near the top of the hierarchy.
As a programmer, you need to understand the memory hierarchy because it has a big impact on the perfor-
mance of your applications. If the data your program needs are stored in a CPU register, then they can be
accessed in zero cycles during the execution of the instruction. If stored in a cache, 1 to 30 cycles. If stored
in main memory, 50 to 200 cycles. And if stored in disk tens of millions of cycles!
Here, then, is a fundamental and enduring idea in computer systems: If you understand how the system
moves data up and down the memory hierarchy, then you can write your application programs so that their
data items are stored higher in the hierarchy, where the CPU can access them more quickly.
This idea centers around a fundamental property of computer programs known as locality. Programs with
good locality tend to access the same set of data items over and over again, or they tend to access sets of
nearby data items. Programs with good locality tend to access more data items from the upper levels of the
memory hierarchy than programs with poor locality, and thus run faster. For example, the running times
of different matrix multiplication kernels that perform the same number of arithmetic operations, but have
different degrees of locality, can vary by a factor of 20!
531
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Understanding the Memory Hierarchy: SRAM, DRAM, and Cache Memories and more Study notes Engineering Science and Technology in PDF only on Docsity!

Chapter 6

The Memory Hierarchy

To this point in our study of systems, we have relied on a simple model of a computer system as a CPU that executes instructions and a memory system that holds instructions and data for the CPU. In our simple model, the memory system is a linear array of bytes, and the CPU can access each memory location in a constant amount of time. While this is an effective model as far as it goes, it does not reflect the way that modern systems really work.

In practice, a memory system is a hierarchy of storage devices with different capacities, costs, and access times. CPU registers hold the most frequently used data. Small, fast cache memories nearby the CPU act as staging areas for a subset of the data and instructions stored in the relatively slow main memory. The main memory stages data stored on large, slow disks, which in turn often serve as staging areas for data stored on the disks or tapes of other machines connected by networks.

Memory hierarchies work because well-written programs tend to access the storage at any particular level more frequently than they access the storage at the next lower level. So the storage at the next level can be slower, and thus larger and cheaper per bit. The overall effect is a large pool of memory that costs as much as the cheap storage near the bottom of the hierarchy, but that serves data to programs at the rate of the fast storage near the top of the hierarchy.

As a programmer, you need to understand the memory hierarchy because it has a big impact on the perfor- mance of your applications. If the data your program needs are stored in a CPU register, then they can be accessed in zero cycles during the execution of the instruction. If stored in a cache, 1 to 30 cycles. If stored in main memory, 50 to 200 cycles. And if stored in disk tens of millions of cycles!

Here, then, is a fundamental and enduring idea in computer systems: If you understand how the system moves data up and down the memory hierarchy, then you can write your application programs so that their data items are stored higher in the hierarchy, where the CPU can access them more quickly.

This idea centers around a fundamental property of computer programs known as locality. Programs with good locality tend to access the same set of data items over and over again, or they tend to access sets of nearby data items. Programs with good locality tend to access more data items from the upper levels of the memory hierarchy than programs with poor locality, and thus run faster. For example, the running times of different matrix multiplication kernels that perform the same number of arithmetic operations, but have different degrees of locality, can vary by a factor of 20!

532 CHAPTER 6. THE MEMORY HIERARCHY

In this chapter, we will look at the basic storage technologies — SRAM memory, DRAM memory, ROM memory, and rotating and solid state disks — and describe how they are organized into hierarchies. In particular, we focus on the cache memories that act as staging areas between the CPU and main memory, because they have the most impact on application program performance. We show you how to analyze your C programs for locality and we introduce techniques for improving the locality in your programs. You will also learn an interesting way to characterize the performance of the memory hierarchy on a particular machine as a “memory mountain” that shows read access times as a function of locality.

6.1 Storage Technologies

Much of the success of computer technology stems from the tremendous progress in storage technology. Early computers had a few kilobytes of random-access memory. The earliest IBM PCs didn’t even have a hard disk. That changed with the introduction of the IBM PC-XT in 1982, with its 10-megabyte disk. By the year 2010, typical machines had 150,000 times as much disk storage, and the amount of storage was increasing by a factor of 2 every couple of years.

6.1.1 Random-Access Memory

Random-access memory (RAM) comes in two varieties— static and dynamic. Static RAM (SRAM) is faster and significantly more expensive than Dynamic RAM (DRAM). SRAM is used for cache memories, both on and off the CPU chip. DRAM is used for the main memory plus the frame buffer of a graphics system. Typically, a desktop system will have no more than a few megabytes of SRAM, but hundreds or thousands of megabytes of DRAM.

Static RAM

SRAM stores each bit in a bistable memory cell. Each cell is implemented with a six-transistor circuit. This circuit has the property that it can stay indefinitely in either of two different voltage configurations, or states. Any other state will be unstable—starting from there, the circuit will quickly move toward one of the stable states. Such a memory cell is analogous to the inverted pendulum illustrated in Figure 6.1.

.^.^.

Stable Left Stable Right

Unstable

Figure 6.1: Inverted pendulum. Like an SRAM cell, the pendulum has only two stable configurations, or states.

The pendulum is stable when it is tilted either all the way to the left or all the way to the right. From any

534 CHAPTER 6. THE MEMORY HIERARCHY

bits per supercell, r = 4 rows, and c = 4 columns. The shaded box denotes the supercell at address (2, 1). Information flows in and out of the chip via external connectors called pins. Each pin carries a 1-bit signal. Figure 6.3 shows two of these sets of pins: eight data pins that can transfer 1 byte in or out of the chip, and two addr pins that carry two-bit row and column supercell addresses. Other pins that carry control information are not shown.

Cols

Rows

0 1 2 3 0 1 2 3

Internal row buffer

DRAM chip

addr

data

Supercell (2,1)

(^2) /

(^8) /

Memory (to CPU) controller

Figure 6.3: High level view of a 128-bit 16 × 8 DRAM chip.

Aside: A note on terminology The storage community has never settled on a standard name for a DRAM array element. Computer architects tend to refer to it as a “cell,” overloading the term with the DRAM storage cell. Circuit designers tend to refer to it as a “word,” overloading the term with a word of main memory. To avoid confusion, we have adopted the unambiguous term “supercell.” End Aside.

Each DRAM chip is connected to some circuitry, known as the memory controller , that can transfer w bits at a time to and from each DRAM chip. To read the contents of supercell (i, j), the memory controller sends the row address i to the DRAM, followed by the column address j. The DRAM responds by sending the contents of supercell (i, j) back to the controller. The row address i is called a RAS (Row Access Strobe) request. The column address j is called a CAS (Column Access Strobe) request. Notice that the RAS and CAS requests share the same DRAM address pins.

For example, to read supercell (2, 1) from the 16 × 8 DRAM in Figure 6.3, the memory controller sends row address 2, as shown in Figure 6.4(a). The DRAM responds by copying the entire contents of row 2 into an internal row buffer. Next, the memory controller sends column address 1, as shown in Figure 6.4(b). The DRAM responds by copying the 8 bits in supercell (2, 1) from the row buffer and sending them to the memory controller.

One reason circuit designers organize DRAMs as two-dimensional arrays instead of linear arrays is to reduce the number of address pins on the chip. For example, if our example 128-bit DRAM were organized as a linear array of 16 supercells with addresses 0 to 15, then the chip would need four address pins instead of two. The disadvantage of the two-dimensional array organization is that addresses must be sent in two distinct steps, which increases the access time.

6.1. STORAGE TECHNOLOGIES 535

RAS = 2

Cols

Rows

(^0 1 2 ) 0 1 2 3

Internal row buffer

DRAM chip

Row 2

addr

data

(^2) /

(^8) /

Memory controller Supercell (2,1)

Cols

Rows

(^0 1 2 ) 0 1 2 3

Internal row buffer

DRAM chip

CAS = 1 addr

data

(^2) /

(^8) /

Memory controller

(a) Select row 2 (RAS request). (b) Select column 1 (CAS request).

Figure 6.4: Reading the contents of a DRAM supercell.

Memory Modules

DRAM chips are packaged in memory modules that plug into expansion slots on the main system board (motherboard). Common packages include the 168-pin dual inline memory module (DIMM) , which transfers data to and from the memory controller in 64-bit chunks, and the 72-pin single inline memory module (SIMM) , which transfers data in 32-bit chunks.

Figure 6.5 shows the basic idea of a memory module. The example module stores a total of 64 MB (megabytes) using eight 64-Mbit 8 M × 8 DRAM chips, numbered 0 to 7. Each supercell stores 1 byte of main memory , and each 64-bit doubleword^1 at byte address A in main memory is represented by the eight supercells whose corresponding supercell address is (i, j). In the example in Figure 6.5, DRAM 0 stores the first (lower-order) byte, DRAM 1 stores the next byte, and so on.

To retrieve a 64-bit doubleword at memory address A, the memory controller converts A to a supercell address (i, j) and sends it to the memory module, which then broadcasts i and j to each DRAM. In response, each DRAM outputs the 8-bit contents of its (i, j) supercell. Circuitry in the module collects these outputs and forms them into a 64-bit doubleword, which it returns to the memory controller.

Main memory can be aggregated by connecting multiple memory modules to the memory controller. In this case, when the controller receives an address A, the controller selects the module k that contains A, converts A to its (i, j) form, and sends (i, j) to module k.

Practice Problem 6.1 : In the following, let r be the number of rows in a DRAM array, c the number of columns, br the number of bits needed to address the rows, and bc the number of bits needed to address the columns. For each of the following DRAMs, determine the power-of-two array dimensions that minimize max(br, bc), the maximum number of bits needed to address the rows or columns of the array. (^1) IA32 would call this 64-bit quantity a “quadword.”

6.1. STORAGE TECHNOLOGIES 537

  • Extended data out DRAM (EDO DRAM). An enhanced form of FPM DRAM that allows the individual CAS signals to be spaced closer together in time.
  • Synchronous DRAM (SDRAM). Conventional, FPM, and EDO DRAMs are asynchronous in the sense that they communicate with the memory controller using a set of explicit control signals. SDRAM replaces many of these control signals with the rising edges of the same external clock signal that drives the memory controller. Without going into detail, the net effect is that an SDRAM can output the contents of its supercells at a faster rate than its asynchronous counterparts.
  • Double Data-Rate Synchronous DRAM (DDR SDRAM). DDR SDRAM is an enhancement of SDRAM that doubles the speed of the DRAM by using both clock edges as control signals. Different types of DDR SDRAMs are characterized by the size of a small prefetch buffer that increases the effective bandwidth: DDR (2 bits), DDR2 (4 bits), and DDR3 (8 bits).
  • Rambus DRAM (RDRAM). This is an alternative proprietary technology with a higher maximum bandwidth than DDR SDRAM.
  • Video RAM (VRAM). Used in the frame buffers of graphics systems. VRAM is similar in spirit to FPM DRAM. Two major differences are that (1) VRAM output is produced by shifting the entire contents of the internal buffer in sequence, and (2) VRAM allows concurrent reads and writes to the memory. Thus, the system can be painting the screen with the pixels in the frame buffer (reads) while concurrently writing new values for the next update (writes).

Aside: Historical popularity of DRAM technologies Until 1995, most PCs were built with FPM DRAMs. From 1996 to 1999, EDO DRAMs dominated the market, while FPM DRAMs all but disappeared. SDRAMs first appeared in 1995 in high-end systems, and by 2002 most PCs were built with SDRAMs and DDR SDRAMs. By 2010, most server and desktop systems were built with DDR3 SDRAMs. In fact, the Intel Core i7 supports only DDR3 SDRAM. End Aside.

Nonvolatile Memory

DRAMs and SRAMs are volatile in the sense that they lose their information if the supply voltage is turned off. Nonvolatile memories , on the other hand, retain their information even when they are powered off. There are a variety of nonvolatile memories. For historical reasons, they are referred to collectively as read-only memories (ROMs) , even though some types of ROMs can be written to as well as read. ROMs are distinguished by the number of times they can be reprogrammed (written to) and by the mechanism for reprogramming them.

A programmable ROM (PROM) can be programmed exactly once. PROMs include a sort of fuse with each memory cell that can be blown once by zapping it with a high current.

An erasable programmable ROM (EPROM) has a transparent quartz window that permits light to reach the storage cells. The EPROM cells are cleared to zeros by shining ultraviolet light through the window. Programming an EPROM is done by using a special device to write ones into the EPROM. An EPROM can be erased and reprogrammed on the order of 1000 times. An electrically erasable PROM (EEPROM) is akin to an EPROM, but does not require a physically separate programming device, and thus can be

538 CHAPTER 6. THE MEMORY HIERARCHY

reprogrammed in-place on printed circuit cards. An EEPROM can be reprogrammed on the order of 105 times before it wears out.

Flash memory is a type of nonvolatile memory, based on EEPROMs, that has become an important storage technology. Flash memories are everywhere, providing fast and durable nonvolatile storage for a slew of electronic devices, including digital cameras, cell phones, music players, PDAs, and laptop, desktop, and server computer systems. In Section 6.1.3, we will look in detail at a new form of flash-based disk drive, known as a solid state disk (SSD) , that provides a faster, sturdier, and less power-hungry alternative to conventional rotating disks.

Programs stored in ROM devices are often referred to as firmware. When a computer system is powered up, it runs firmware stored in a ROM. Some systems provide a small set of primitive input and output functions in firmware, for example, a PC’s BIOS (basic input/output system) routines. Complicated devices such as graphics cards and disk drive controllers also rely on firmware to translate I/O (input/output) requests from the CPU.

Accessing Main Memory

Data flows back and forth between the processor and the DRAM main memory over shared electrical con- duits called buses. Each transfer of data between the CPU and memory is accomplished with a series of steps called a bus transaction. A read transaction transfers data from the main memory to the CPU. A write transaction transfers data from the CPU to the main memory.

A bus is a collection of parallel wires that carry address, data, and control signals. Depending on the particular bus design, data and address signals can share the same set of wires, or they can use different sets. Also, more than two devices can share the same bus. The control wires carry signals that synchronize the transaction and identify what kind of transaction is currently being performed. For example, is this transaction of interest to the main memory, or to some other I/O device such as a disk controller? Is the transaction a read or a write? Is the information on the bus an address or a data item?

Figure 6.6 shows the configuration of an example computer system. The main components are the CPU chip, a chipset that we will call an I/O bridge (which includes the memory controller), and the DRAM memory modules that make up main memory. These components are connected by a pair of buses: a system bus that connects the CPU to the I/O bridge, and a memory bus that connects the I/O bridge to the main memory.

The I/O bridge translates the electrical signals of the system bus into the electrical signals of the memory bus. As we will see, the I/O bridge also connects the system bus and memory bus to an I/O bus that is shared by I/O devices such as disks and graphics cards. For now, though, we will focus on the memory bus.

Aside: A note on bus designs Bus design is a complex and rapidly changing aspect of computer systems. Different vendors develop different bus architectures as a way to differentiate their products. For example, Intel systems use chipsets known as the northbridge and the southbridge to connect the CPU to memory and I/O devices, respectively. In older Pentium and Core 2 systems, a front side bus (FSB) connects the CPU to the northbridge. Systems from AMD replace the FSB with the HyperTransport interconnect, while newer Intel Core i7 systems use the QuickPath interconnect. The details of these different bus architectures are beyond the scope of this text. Instead, we will use the high-level bus architecture from Figure 6.6 as a running example throughout the text. It is a simple but useful abstraction that

540 CHAPTER 6. THE MEMORY HIERARCHY

ALU

Register file

Bus interface

A^0 x A

Main memory I/O bridge

%eax

(a) CPU places address A on the memory bus.

ALU

Register file

Bus interface

x^0 x A

Main memory

%eax

I/O bridge

(b) Main memory reads A from the bus, retrieves word x, and places it on the bus.

x ALU

Register file

Bus interface (^) x

Main memory 0

A

%eax

I/O bridge

(c) CPU reads word x from the bus, and copies it into register %eax.

Figure 6.7: Memory read transaction for a load operation: movl A,%eax.

6.1. STORAGE TECHNOLOGIES 541

y ALU

Register file

Bus interface

A

Main memory 0 A

%eax

I/O bridge

(a) CPU places address A on the memory bus. Main memory reads it and waits for the data word.

y ALU

Register file

Bus interface

y

Main memory 0

A

%eax

I/O bridge

(b) CPU places data word y on the bus.

y ALU

Register file

Bus interface (^) y

Main memory 0

A

%eax

I/O bridge

(c) Main memory reads data word y from the bus and stores it at address A.

Figure 6.8: Memory write transaction for a store operation: movl %eax,A.

6.1. STORAGE TECHNOLOGIES 543

  • Areal density ( bits / in^2 ): The product of the recording density and the track density.

Disk manufacturers work tirelessly to increase areal density (and thus capacity), and this is doubling every few years. The original disks, designed in an age of low areal density, partitioned every track into the same number of sectors, which was determined by the number of sectors that could be recorded on the innermost track. To maintain a fixed number of sectors per track, the sectors were spaced farther apart on the outer tracks. This was a reasonable approach when areal densities were relatively low. However, as areal densities increased, the gaps between sectors (where no data bits were stored) became unacceptably large. Thus, modern high-capacity disks use a technique known as multiple zone recording , where the set of cylinders is partitioned into disjoint subsets known as recording zones. Each zone consists of a contiguous collection of cylinders. Each track in each cylinder in a zone has the same number of sectors, which is determined by the number of sectors that can be packed into the innermost track of the zone. Note that diskettes (floppy disks) still use the old-fashioned approach, with a constant number of sectors per track.

The capacity of a disk is given by the following formula:

Disk capacity =

bytes

sector

×

average # sectors track

×

tracks

surface

×

surfaces

platter

×

platters

disk

For example, suppose we have a disk with five platters, 512 bytes per sector, 20,000 tracks per surface, and an average of 300 sectors per track. Then the capacity of the disk is

Disk capacity = 512 bytes sector

×

300 sectors track

×

20,000 tracks surface

×

2 surfaces platter

×

5 platters disk = 30,720,000,000 bytes = 30.72 GB.

Notice that manufacturers express disk capacity in units of gigabytes (GB), where 1 GB = 10^9 bytes.

Aside: How much is a gigabyte? Unfortunately, the meanings of prefixes such as kilo (K), mega (M ), giga (G), and tera (T ) depend on the context. For measures that relate to the capacity of DRAMs and SRAMs, typically K = 2^10 , M = 2^20 , G = 2^30 , and T = 2^40. For measures related to the capacity of I/O devices such as disks and networks, typically K = 10^3 , M = 10^6 , G = 10^9 , and T = 10^12. Rates and throughputs usually use these prefix values as well. Fortunately, for the back-of-the-envelope estimates that we typically rely on, either assumption works fine in prac- tice. For example, the relative difference between 220 = 1, 048 , 576 and 106 = 1, 000 , 000 is small: (2^20 − 106 )/ 106 ≈ 5%. Similarly for 230 = 1, 073 , 741 , 824 and 109 = 1, 000 , 000 , 000 : (2^30 − 109 )/ 109 ≈ 7%. End Aside.

Practice Problem 6.2 : What is the capacity of a disk with two platters, 10,000 cylinders, an average of 400 sectors per track, and 512 bytes per sector?

Disk Operation

Disks read and write bits stored on the magnetic surface using a read/write head connected to the end of an actuator arm , as shown in Figure 6.10(a). By moving the arm back and forth along its radial axis, the

544 CHAPTER 6. THE MEMORY HIERARCHY

drive can position the head over any track on the surface. This mechanical motion is known as a seek. Once the head is positioned over the desired track, then as each bit on the track passes underneath, the head can either sense the value of the bit (read the bit) or alter the value of the bit (write the bit). Disks with multiple platters have a separate read/write head for each surface, as shown in Figure 6.10(b). The heads are lined up vertically and move in unison. At any point in time, all heads are positioned on the same cylinder.

By moving radially, the arm can position the read/write head over any track

Spindle

The disk surface spins at a fixed rotational rate

The read/write head is attached to the end of the arm and flies over the disk surface on a thin cushion of air

(a) Single-platter view

Arm

Read/write heads

Spindle

(b) Multiple-platter view

Figure 6.10: Disk dynamics.

The read/write head at the end of the arm flies (literally) on a thin cushion of air over the disk surface at a height of about 0.1 microns and a speed of about 80 km/h. This is analogous to placing the Sears Tower on its side and flying it around the world at a height of 2.5 cm (1 inch) above the ground, with each orbit of the earth taking only 8 seconds! At these tolerances, a tiny piece of dust on the surface is like a huge boulder. If the head were to strike one of these boulders, the head would cease flying and crash into the surface (a so-called head crash ). For this reason, disks are always sealed in airtight packages. Disks read and write data in sector-sized blocks. The access time for a sector has three main components: seek time , rotational latency , and transfer time :

  • Seek time: To read the contents of some target sector, the arm first positions the head over the track that contains the target sector. The time required to move the arm is called the seek time. The seek time, Tseek, depends on the previous position of the head and the speed that the arm moves across the surface. The average seek time in modern drives, Tavg seek, measured by taking the mean of several thousand seeks to random sectors, is typically on the order of 3 to 9 ms. The maximum time for a single seek, Tmax seek, can be as high as 20 ms.
  • Rotational latency: Once the head is in position over the track, the drive waits for the first bit of the target sector to pass under the head. The performance of this step depends on both the position of the surface when the head arrives at the target sector and the rotational speed of the disk. In the worst case, the head just misses the target sector and waits for the disk to make a full rotation. Thus, the maximum rotational latency, in seconds, is given by

Tmax rotation =

RPM

×

60 secs 1 min