Computer Systems. Memory Hierarchy. Han, Hwansoo

Similar documents
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 26, SPRING 2013

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 26, FALL 2012

Random Access Memory (RAM)

The Memory Hierarchy /18-213/15-513: Introduction to Computer Systems 11 th Lecture, October 3, Today s Instructor: Phil Gibbons

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture

Foundations of Computer Systems

Giving credit where credit is due

CISC 360. The Memory Hierarchy Nov 13, 2008

Storage Technologies and the Memory Hierarchy

Random-Access Memory (RAM) Lecture 13 The Memory Hierarchy. Conventional DRAM Organization. SRAM vs DRAM Summary. Topics. d x w DRAM: Key features

Computer Organization: A Programmer's Perspective

Key features. ! RAM is packaged as a chip.! Basic storage unit is a cell (one bit per cell).! Multiple RAM chips form a memory.

CS 33. Memory Hierarchy I. CS33 Intro to Computer Systems XVI 1 Copyright 2016 Thomas W. Doeppner. All rights reserved.

Random-Access Memory (RAM) CS429: Computer Organization and Architecture. SRAM and DRAM. Flash / RAM Summary. Storage Technologies

The Memory Hierarchy Sept 29, 2006

CS 201 The Memory Hierarchy. Gerson Robboy Portland State University

Today. The Memory Hierarchy. Random-Access Memory (RAM) Nonvolatile Memories. Traditional Bus Structure Connecting CPU and Memory

The Memory Hierarchy / : Introduction to Computer Systems 10 th Lecture, Feb 12, 2015

Today. The Memory Hierarchy. Byte Oriented Memory Organization. Simple Memory Addressing Modes

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313.

+ Random-Access Memory (RAM)

CSE 153 Design of Operating Systems

Random-Access Memory (RAM) CISC 360. The Memory Hierarchy Nov 24, Conventional DRAM Organization. SRAM vs DRAM Summary.

Read-only memory (ROM): programmed during production Programmable ROM (PROM): can be programmed once SRAM (Static RAM)

The Memory Hierarchy. Computer Organization 2/12/2015. CSC252 - Spring Memory. Conventional DRAM Organization. Reading DRAM Supercell (2,1)

The. Memory Hierarchy. Chapter 6

Announcements. Outline

CSE 153 Design of Operating Systems Fall 2018

Giving credit where credit is due

Carnegie Mellon. Carnegie Mellon

Large and Fast: Exploiting Memory Hierarchy

Memory Hierarchy. Instructor: Adam C. Champion, Ph.D. CSE 2431: Introduction to Operating Systems Reading: Chap. 6, [CSAPP]

A Computer. Computer organization - Recap. The Memory Hierarchy... Brief Overview of Memory Design. CPU has two components: Memory

Locality. CS429: Computer Organization and Architecture. Locality Example 2. Locality Example

CS 33. Architecture and Optimization (3) CS33 Intro to Computer Systems XVI 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Denison University. Cache Memories. CS-281: Introduction to Computer Systems. Instructor: Thomas C. Bressoud

Computer Organization: A Programmer's Perspective

211: Computer Architecture Summer 2016

CS 261 Fall Mike Lam, Professor. Memory

CS 153 Design of Operating Systems

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Computer Architecture and System Software Lecture 08: Assembly Language Programming + Memory Hierarchy

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

CS 261 Fall Mike Lam, Professor. Memory

CS3350B Computer Architecture

Lecture 15: Caches and Optimization Computer Architecture and Systems Programming ( )

Memory Hierarchy. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Review: Assembly Programmer s View. The Memory Hierarchy. Random- Access Memory (RAM) Today. NonvolaHle Memories. SRAM vs DRAM Summary

Computer Architecture and System Software Lecture 09: Memory Hierarchy. Instructor: Rob Bergen Applied Computer Science University of Winnipeg

Problem: Processor- Memory Bo<leneck

CSCI-UA.0201 Computer Systems Organization Memory Hierarchy

CS 2461: Computer Architecture 1 The Memory Hierarchy and impact on program performance

The Memory Hierarchy 10/25/16

Contents. Memory System Overview Cache Memory. Internal Memory. Virtual Memory. Memory Hierarchy. Registers In CPU Internal or Main memory

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Systems Programming and Computer Architecture ( ) Timothy Roscoe

211: Computer Architecture Summer 2016

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 13

Lecture 18: Memory Systems. Spring 2018 Jason Tang

Cache Memories. Topics. Next time. Generic cache memory organization Direct mapped caches Set associative caches Impact of caches on performance

Cache memories are small, fast SRAM-based memories managed automatically in hardware. Hold frequently accessed blocks of main memory

CS 240 Stage 3 Abstractions for Practical Systems

CS356: Discussion #9 Memory Hierarchy and Caches. Marco Paolieri Illustrations from CS:APP3e textbook

CS 31: Intro to Systems Storage and Memory. Kevin Webb Swarthmore College March 17, 2015

UNIT 2 Data Center Environment

Module 1: Basics and Background Lecture 4: Memory and Disk Accesses. The Lecture Contains: Memory organisation. Memory hierarchy. Disks.

Where Have We Been? Ch. 6 Memory Technology

Memory hierarchy Outline

Cache Memories. From Bryant and O Hallaron, Computer Systems. A Programmer s Perspective. Chapter 6.

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2014 Lecture 14

Chapter 6 Caches. Computer System. Alpha Chip Photo. Topics. Memory Hierarchy Locality of Reference SRAM Caches Direct Mapped Associative

F28HS Hardware-Software Interface: Systems Programming

CENG3420 Lecture 08: Memory Organization

Memory Hierarchy Y. K. Malaiya

Problem: Processor Memory BoJleneck

CISC 360. Cache Memories Nov 25, 2008

Cache Memories. EL2010 Organisasi dan Arsitektur Sistem Komputer Sekolah Teknik Elektro dan Informatika ITB 2010

Adapted from instructor s supplementary material from Computer. Patterson & Hennessy, 2008, MK]

Giving credit where credit is due

Show how to connect three Full Adders to implement a 3-bit ripple-carry adder

STORING DATA: DISK AND FILES

General Cache Mechanics. Memory Hierarchy: Cache. Cache Hit. Cache Miss CPU. Cache. Memory CPU CPU. Cache. Cache. Memory. Memory

UNIT-V MEMORY ORGANIZATION

Computer Organization and Assembly Language (CS-506)

k -bit address bus n-bit data bus Control lines ( R W, MFC, etc.)

ECE 341. Lecture # 16

CS241 Computer Organization Spring Principle of Locality

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Secondary storage. CS 537 Lecture 11 Secondary Storage. Disk trends. Another trip down memory lane

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

Memory Hierarchy. Announcement. Computer system model. Reference

CHAPTER 6 Memory. CMPS375 Class Notes (Chap06) Page 1 / 20 Dr. Kuo-pao Yang

Cache Memories October 8, 2007

CPE300: Digital System Architecture and Design

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 7: Memory Organization Part II

Computer Architecture and System Software Lecture 12: Review. Instructor: Rob Bergen Applied Computer Science University of Winnipeg

Memory Technology. Chapter 5. Principle of Locality. Chapter 5 Large and Fast: Exploiting Memory Hierarchy 1

Cache Memories /18-213/15-513: Introduction to Computer Systems 12 th Lecture, October 5, Today s Instructor: Phil Gibbons

UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering. Computer Architecture ECE 568

Transcription:

Computer Systems Memory Hierarchy Han, Hwansoo

Random-Access Memory (RAM) Key features RAM is traditionally packaged as a chip. Basic storage unit is normally a cell (one bit per cell). Multiple RAM chips form a memory. RAM comes in two varieties: SRAM (Static RAM) DRAM (Dynamic RAM)

Random-Access Memory (RAM) Static RAM (SRAM) Each cell stores bit with a six-transistor circuit Retains value indefinitely, as long as it is kept powered Relatively insensitive to disturbances such as electrical noise Faster and more expensive than DRAM Dynamic RAM (DRAM) Each cell stores bit with a capacitor and transistor Value must be refreshed every 10-100ms Sensitive to disturbances Slower and cheaper than SRAM Tran. Access Need per bit time refresh? Sensitive? Cost Applications SRAM 6 1X No No 100x cache memories DRAM 1 10X Yes Yes 1X Main memories, frame buffers

Connecting CPU and Memory Traditional bus structure btwn. CPU and memory A bus is a collection of parallel wires that carry address, data, and control signals. Buses are typically shared by multiple devices. CPU chip Register file Load operation: movq A, %rax Store operation: movq %rax, A %rax x ALU System bus I/O bridge Memory bus Main memory 0 Bus interface x A

Conventional DRAM Organization d x w DRAM: dw total bits organized as d supercells of size w bits 16 x 8 DRAM chip cols 0 1 2 3 (to CPU) memory controller 2 bits / addr 8 bits / data rows 0 1 2 3 supercell (2,1) internal row buffer

Reading DRAM Supercell (2,1) Step 1(a): Row access strobe (RAS) selects row 2. Step 1(b): Row 2 copied from DRAM array to row buffer. memory controller RAS = 2 2 / addr 16 x 8 DRAM chip 0 1 rows 2 cols 0 1 2 3 8 / data 3 internal row buffer

Reading DRAM Supercell (2,1) Step 2(a): Column access strobe (CAS) selects column 1. Step 2(b): Supercell (2,1) copied from buffer to data lines, and eventually back to the CPU. To CPU supercell (2,1) memory controller CAS = 1 2 / addr 8 / data 16 x 8 DRAM chip cols 0 1 2 3 0 1 rows 2 3 supercell (2,1) internal row buffer

Memory Modules (DIMMs) addr (row = i, col = j) DRAM 7 DRAM 0 : supercell (i,j) 64 MB memory module consisting of eight 8Mx8 DRAMs bits 56-63 bits 48-55 bits 40-47 bits 32-39 bits 24-31 bits 16-23 bits 8-15 bits 0-7 63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 0 64-bit doubleword at main memory address A Memory controller 64-bit doubleword

Nonvolatile Memories Nonvolatile memories retain value even if powered off. Generic name is read-only memory (ROM). Misleading because some ROMs can be read and modified. Types of ROMs Programmable ROM (PROM) Eraseable programming ROM (EPROM) Electrically eraseable PROM (EEPROM) Flash memory Firmware Program stored in a ROM Boot time code, BIOS (Basic Input/Output System) Graphics cards, disk controllers, etc.

What s Inside A Disk Drive? Arm Spindle Platters Actuator SCSI connector Electronics (including a processor and memory!) [Image courtesy of Seagate Technology]

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

Multiple-platter View Aligned tracks form a cylinder platter 0 platter 1 platter 2 surface 0 surface 1 surface 2 surface 3 surface 4 surface 5 cylinder k read/write heads move in unison from cylinder to cylinder arm spindle

spindle Disk Operation Disk Operation (Single-platter view) 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. spindle spindle spindle By moving radially, the arm can position the read/write head over any track.

Disk Capacity Capacity: maximum number of bits that can be stored Vendors express capacity in units of gigabytes (GB), where 1 GB = 10 9 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/in 2 ): 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 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

Computing Disk Capacity Capacity = (# bytes/sector) x (avg. # sectors/track) x (# tracks/surface) x (# surfaces/platter) x (# platters/disk) Example: 512 bytes/sector 300 sectors/track (on average) 20,000 tracks/surface 2 surfaces/platter 5 platters/disk Capacity = 512 x 300 x 20000 x 2 x 5 = 30,720,000,000 = 30.72 GB

Disk Access Time Components After BLUE read Seek for RED Rotational latency After RED read Data transfer Seek Rotational latency Data transfer

Disk Access Time Average time to access some target sector approximated by : T access = T avg_seek + T avg_rotation + T avg_transfer Seek time Time to position heads over cylinder containing target sector. Typically 9ms Rotational latency Time waiting for first bit of target sector to pass under r/w head. ½ x 1/RPMs x 60 sec/1min Transfer time Time to read the bits in the target sector. 1/RPM x 1/(avg #sectors/track) x 60sec/1min Important points: Access time dominated by seek time. First bit in a sector is the most expensive, the rest are free.

Disk Access Time Example Given: Rotational rate = 7,200 RPM Average seek time = 9 ms Avg # sectors/track = 400 Derived: Tavg rotation = 1/2 x (60 secs/7200 RPM) x 1000 ms/sec = 4 ms. Tavg transfer = 60/7200 RPM x 1/400 secs/track x 1000 ms/sec = 0.02 ms Taccess = 9 ms + 4 ms + 0.02 ms Important points: Access time dominated by seek time and rotational latency. First bit in a sector is the most expensive, the rest are free. SRAM access time is about 4 ns/doubleword, DRAM about 60 ns Disk is about 40,000 times slower than SRAM, 2,500 times slower then DRAM

Logical Disk Blocks Modern disks present a simple abstract view of the complex sector geometry: The set of available sectors is modeled as a sequence of blocksized logical blocks (0, 1, 2, ) Mapping between logical blocks and actual (physical) sectors Maintained by hardware/firmware device called disk controller. Converts requests for logical blocks into (surface, track, sector) triples Disk controller also performs some intelligent functions Buffering, caching, prefetching, scheduling, etc.

I/O Bus CPU chip register file ALU system bus memory bus bus interface I/O bridge main memory USB controller graphics adapter I/O bus disk controller Expansion slots for other devices such as network adapters. mouse keyboard monitor disk

Reading a Disk Sector (1) CPU chip Register file ALU CPU initiates a disk read by writing a command, logical block number, and destination memory address to a port (address) associated with disk controller. Bus interface Main memory I/O bus USB controller mouse keyboard Graphics adapter Monitor Disk controller Disk

Reading a Disk Sector (2) CPU chip Register file ALU Disk controller reads the sector and performs a direct memory access (DMA) transfer into main memory. Bus interface Main memory I/O bus USB controller Mouse Keyboard Graphics adapter Monitor Disk controller Disk

Reading a Disk Sector (3) CPU chip Register file ALU When the DMA transfer completes, the disk controller notifies the CPU with an interrupt (i.e., asserts a special interrupt pin on the CPU) Bus interface Main memory I/O bus USB controller Mouse Keyboard Graphics adapter Monitor Disk controller Disk

Solid State Disks (SSDs) I/O bus Solid State Disk (SSD) Flash memory Block 0 Page 0 Page 1 Page P-1 Flash translation layer Requests to read and write logical disk blocks Block B-1 Page 0 Page 1 Page P-1 Pages: 512KB to 4KB, Blocks: 32 to 128 pages Data read/written in units of pages. Page can be written only after its block has been erased A block wears out after about 100,000 repeated writes.

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 Sequential access faster than random access Common theme in the memory hierarchy Random writes are somewhat slower Erasing a block takes a long time (~1 ms) Modifying a block page requires all other pages to be copied to new block In earlier SSDs, the read/write gap was much larger. [Source: Intel SSD 730 product specification]

SSD Tradeoffs vs. Rotating Disks 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 E.g. Intel SSD 730 guarantees 128 petabyte (128 x 10 15 bytes) of writes before they wear out In 2017, about 7 times more expensive per byte 1TB: SSD (\400,000), HDD (\60,000) Applications MP3 players, smart phones, laptops Beginning to appear in desktops and servers

Time (ns) The CPU-Memory Gap The gap between DRAM, disk, and CPU speeds. 100,000,000.0 10,000,000.0 1,000,000.0 100,000.0 10,000.0 1,000.0 100.0 10.0 1.0 0.1 0.0 Disk SSD DRAM CPU 1985 1990 1995 2000 2003 2005 2010 2015 Year Disk seek time SSD access time DRAM access time SRAM access time CPU cycle time Effective CPU cycle time

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. Instruction references Reference instructions in sequence. Cycle through loop repeatedly. Temporal locality Spatial locality Temporal locality

Qualitative Estimates of Locality Claim: Being able to look at code and get a qualitative sense of its locality is a key skill for a professional programmer. Question: Does this function have good locality with respect to array a? 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 Question: Does this function have good locality with respect to array a? 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 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)? 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;

Observations on Code Locality Programmer can optimize for cache performance How data structures are organized How data are accessed Nested loop structure Blocking is a general technique All systems favor cache friendly code Getting absolute optimum performance is very platform specific Cache sizes, line sizes, associativities, etc. Can get most of the advantage with generic code Keep working set reasonably small (temporal locality) Use small strides (spatial locality)

Memory Hierarchies Some fundamental and enduring properties of hardware and software: Fast storage technologies cost more per byte and have less capacity. The gap between CPU and main memory speed is widening. Well-written programs tend to exhibit good locality. Memory hierarchy Efficient way of organizing memory and storage systems

Example Memory Hierarchy Smaller, faster, and costlier (per byte) storage devices Larger, slower, and cheaper (per byte) storage L5: devices L6: L4: L3: L2: L1: L0: Regs L1 cache (SRAM) L2 cache (SRAM) L3 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Remote secondary storage (e.g., Web servers) CPU registers hold words retrieved from the L1 cache. L1 cache holds cache lines retrieved from the L2 cache. L2 cache holds cache lines retrieved from L3 cache L3 cache holds cache lines retrieved from main memory. Main memory holds disk blocks retrieved from local disks. Local disks hold files retrieved from disks on remote servers

Caching 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? Programs tend to access the data at level k more often than the data at level k+1 Thus, the storage at level k+1 can be slower, and thus larger and cheaper per bit Net effect: A large pool of memory 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

General Cache Concepts: Hit Cache Request: 14 4 9 14 3 Data in block b is needed Block b is in cache: Hit! Memory 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

General Cache Concepts: Miss Cache Request: 12 4 12 9 14 3 Data in block b is needed Block b is not in cache: Miss! 12 Request: 12 Block b is fetched from memory Memory 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Block b is stored in cache Placement policy: determines where b goes Replacement policy: determines which block gets evicted (victim)

Cache Memories Cache memories are small, fast SRAM-based memories managed automatically in hardware. Hold frequently accessed blocks of main memory CPU looks first for data in L1, then in L2, then in main memory. Typical bus structure: CPU chip register file L1 ALU cache cache bus system bus memory bus L2 cache bus interface I/O bridge main memory

General Org of a Cache Memory Cache is an array of sets. 1 valid bit per line t tag bits per line B = 2 b bytes per cache block Each set contains one or more lines. set 0: valid valid tag tag 0 0 1 1 B 1 B 1 E lines per set Each line holds a block of data. valid tag 0 1 B 1 S = 2 s sets set 1: valid tag 0 1 B 1 valid tag 0 1 B 1 set S-1: valid tag 0 1 B 1 Cache size: C = B x E x S data bytes

Addressing Caches Address A: t bits s bits b bits v tag 0 1 B 1 m-1 0 set 0: v tag 0 1 B 1 <tag> <set index> <block offset> v tag 0 1 B 1 set 1: v v tag tag 0 0 1 1 B 1 B 1 The word at address A is in the cache if the tag bits in one of the <valid> lines in set <set index> match <tag>. set S-1: v tag 0 1 B 1 The word contents begin at offset <block offset> bytes from the beginning of the block.

Direct-Mapped Cache Simplest kind of cache Characterized by exactly one line per set. set 0: valid tag cache block E=1 lines per set set 1: valid tag cache block set S-1: valid tag cache block

Accessing Direct-Mapped Caches Set selection Use the set index bits to determine the set of interest. set 0: valid tag cache block selected set set 1: valid tag cache block t bits s bits 0 0 0 0 1 b bits set S-1: valid tag cache block m-1 tag set index block offset 0

Accessing Direct-Mapped Caches Line matching and word selection Line matching: Find a valid line in the selected set with a matching tag Word selection: Then extract the word =1? (1) The valid bit must be set 0 1 2 3 4 5 6 7 selected set (i): 1 0110 w 0 w 1 w 2 w 3 (2) The tag bits in the cache line must match the tag bits in the address =? t bits 0110 s bits i b bits 100 (3) If (1) and (2), then cache hit, and block offset selects starting byte. m-1 tag set index block offset 0

Why Use Middle Bits as Index? 00 01 10 11 4-line Cache High-Order Bit Indexing Adjacent memory lines would map to same cache entry Poor use of spatial locality Middle-Order Bit Indexing Consecutive memory lines map to different cache lines Can hold C-byte region of address space in cache at one time 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 High-Order Bit Indexing 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Middle-Order Bit Indexing

Set Associative Caches Characterized by more than one line per set set 0: valid tag cache block valid tag cache block E=2 lines per set set 1: set S-1: valid tag cache block valid tag cache block valid tag cache block valid tag cache block

Accessing Set Associative Caches Set selection identical to direct-mapped cache set 0: valid valid tag tag cache block cache block Selected set set 1: valid valid tag tag cache block cache block t bits s bits 0 0 0 0 1 b bits set S-1: valid valid tag tag cache block cache block m-1 tag set index block offset 0

Accessing Set Associative Caches Line matching and word selection must compare the tag in each valid line in the selected set. =1? (1) The valid bit must be set. 0 1 2 3 4 5 6 7 selected set (i): 1 1001 1 0110 w 0 w 1 w 2 w 3 (2) The tag bits in one of the cache lines must match the tag bits in the address =? t bits s bits b bits (3) If (1) and (2), then cache hit, and block offset selects starting byte. 0110 i 100 m-1 tag set index block offset 0

Cache Performance Metrics Miss Rate Fraction of memory references not found in cache (misses/references) Typical numbers: Hit Time 3-10% for L1 can be quite small (e.g., < 1%) for L2, depending on size, etc. Time to deliver a line in the cache to the processor (includes time to determine whether the line is in the cache) Typical numbers: 1 clock cycle for L1 3-8 clock cycles for L2 Miss Penalty Additional time required because of a miss Typically 25-100 cycles for main memory

Examples of Caching Cache Type What is Cached? Where is it Cached? Latency (cycles) Managed By Registers TLB L1 cache L2 cache Virtual Memory Buffer cache Network buffer cache Browser cache 4-8 bytes words Address translations 64-byte blocks 64-byte blocks 4-KB pages Parts of files Parts of files Web pages CPU core On-Chip TLB On-Chip L1 On-Chip L2 Main memory Main memory Local disk Local disk 0 4 10 100 100 10,000,000 10,000,000 Compiler Hardware MMU Hardware Hardware Hardware + OS Disk cache Disk sectors Disk controller 100,000 Disk firmware 0 OS NFS client Web browser Web cache Web pages Remote server disks 1,000,000,000 Web proxy server

Summary Devices with various access times & capacities SRAM DRAM Disk (SSD/HDD) Hierarchy works Need to hold large data Need to access data fast Caching principle for hierarchy Temporal locality Spatial locality