Docsity

Memory Optimization lec, Lecture notes of Computer Networks

Partial preview of the text

Download Memory Optimization lec and more Lecture notes Computer Networks in PDF only on Docsity!

Chapter 2

Memory Hierarchy Design

Computer Architecture

A Quantitative Approach, Fifth Edition

Memory Hierarchy

◼ Desire to have faster memory leads to memory

hierarchy

◼ Takes advantage of:

◼ Locality (temporal and spatial)

◼ Trade-offs in the cost performance of memory

technologies

◼ Principles of locality plus the implementation

technology guidelines and power budget leads

to:

◼ Smaller hardware can be faster

◼ Each smaller, faster, and more expensive per byte

memory than the next lower level (farther from the

processor)

Memory Hierarchy

◼ Inclusion property

◼ Data contained in a lower level is a superset of the next higher level

◼ It is required for the lowest level of hierarchy

◼ Main memory in the case of caches ◼ Disk memory in the case of virtual memory

Memory Hierarchy

◼ 1980 performance as a baseline 64 KB DRAM ◼ Gap in performance as the difference in time between processor memory requests (for 1 core/processor) and latency of a DRAM access plotted over time ◼ Vertical axis is a log-scale to record the size of the processor–DRAM performance gap ◼ Baseline memory in 1980 with a 1.07 per year performance improvement in latency ◼ The processor line assumes: ◼ 1.25 improvement per year until 1986 ◼ 1.52 improvement per year until 2000 ◼ 1.20 improvement between 2000 and 2005 ◼ No change in processor performance (on a per-core basis) between 2005 and 2010

Memory Hierarchy

◼ Recently power became a major consideration

◼ 10 MB on-chip cache, and a large second- or third-level

cache consumes power in forms such as:

◼ Static power when not operating caused by leakage current ◼ Dynamic (active) power when performing a read/write (called dynamic power)

◼ Power problem is apparent in PMDs

◼ CPU is less aggressive and the power budget may be 20

to 50 times smaller than server or desktop computer

◼ Caches can account for 25% to 50% of the total power consumption ◼ Designers must consider both performance and power trade-offs

◼ Word (not found) must be fetched from a lower level in the

hierarchy (may be another cache or main memory), and

placed in the cache before continuing

◼ A block (line) consists of multiple words that are moved for

efficiency reasons, and because they are likely to be

needed soon due to spatial locality

◼ Each cache block includes a tag to indicate which memory address it corresponds to. ◼ A key design decision is where blocks can be placed in a cache

Memory Hierarchy

Memory Hierarchy

◼ Time required for cache miss depends on the latency and

bandwidth of the memory

◼ Latency: determines the time to retrieve the first word of the block ◼ Bandwidth: determines the time to retrieve the rest of the block

◼ Principle of Locality

◼ Temporal locality: Requested word might be needed again in the near future, place it in the cache where it can be accessed quickly ◼ Spatial locality: There is a high probability that the other data in the block will be needed soon

Memory Hierarchy

◼ A cache miss is handled by hardware

◼ With out-of-order execution, it causes processors to stall until data is available ◼ Without out-of-order execution, it causes processors to behave as: ◼ Result instruction must still wait ◼ Other instructions may proceed during the miss

Memory Hierarchy

◼ Four common questions for the first level (cache) of the

memory hierarchy

◼ Q1: Where can a block be placed in the upper level? (block placement) ◼ Q2: How is a block found if it is in the upper level? (block identification) ◼ Q3: Which block should be replaced on a miss? (block replacement) ◼ Q4: What happens on a write? (write strategy)

Memory Hierarchy

◼ Q1: Where can a block be placed in a cache?

◼ Block is placed according three cache organization:

◼ Direct Mapped: Each block has only one place it can appear in the cache with mapping: ◼ (Block address) MOD (Number of blocks in cache) ◼ Fully Associative: A block can be placed anywhere in the cache ◼ Set Associative: A block can be placed in a restricted set of places in the cache

◼ Most popular scheme is n-way set associative, where a set

is a group of blocks in the cache

◼ A block is first mapped onto a set, and placed anywhere in it

◼ Finding a block consists of first mapping the block address to

the set

◼ Searching the set—usually in parallel—to find the block

◼ The set is chosen by the address of the data as

◼ (Block address) MOD (Number of sets in cache)

◼ If there are n blocks in a set, the cache placement is called n-

way set associative

◼ Direct-mapped cache has just one block per set (so a

block is always placed in the same location)

◼ Fully associative cache has just one set (so a

block can be placed anywhere)

Memory Hierarchy Basics

Memory Hierarchy

Figure B.2 This example cache has 8 block frames and memory has 32 blocks

  • In fully associative, block 12 from the lower level can go into any of the eight block frames of the cache.
  • With direct-mapped, block 12 can only be placed into block frame 4 (12 modulo 8).
  • Set associative, which has some of both features, allows the block to be placed anywhere in set 0 (12 modulo 4). With two blocks per set, this means block 12 can be placed either in block 0 or in block 1 of the cache
  • Real caches contain thousands of block frames
  • Real memories contain millions of blocks
  • The set associative organization has 4 sets with 2 blocks per set, called two-way set associative. Assume that there is nothing in the cache and that the block address in question identifies lower-level block 12

Causes of misses

◼ 3 categories (3C) to gain insights into the causes of high

miss rates to inspire better cache design

◼ Compulsory

◼ First reference to a block (first access to a block cannot be in the cache, so the block must be brought into the cache)

◼ Capacity

◼ Blocks discarded and later retrieved (If the cache cannot contain all the blocks needed during execution of a program)

◼ Conflict

◼ Program makes repeated references to multiple addresses from different blocks that map to the same location in the cache ◼ If the block placement strategy is not fully associative, conflict misses will occur because a block may be discarded and later retrieved if multiple blocks map to its set and accesses to the different blocks are intermingled

Causes of misses

Figure B.8 Total miss rate for each size cache and percentage

of each according to the 3 C’s.

◼ Compulsory misses are independent of cache size ◼ Capacity misses decrease as capacity increases ◼ Conflict misses decrease as associativity increases ◼ Note that a direct-mapped cache of size N has about the same miss rate as a two-way set-associative cache of size N /2 up through 128 K. ◼ Caches larger than 128 KB do not prove that rule. Note that the Capacity column is also the fully associative miss rate. Data were collected as in Figure B.4 using LRU replacement