CPU issues address (and data for write) Memory returns data (or acknowledgment for write)

Similar documents
Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

Chapter Seven Morgan Kaufmann Publishers

Chapter Seven. SRAM: value is stored on a pair of inverting gates very fast but takes up more space than DRAM (4 to 6 transistors)

Memory Hierarchies. Instructor: Dmitri A. Gusev. Fall Lecture 10, October 8, CS 502: Computers and Communications Technology

Chapter 5 Large and Fast: Exploiting Memory Hierarchy (Part 1)

LECTURE 10: Improving Memory Access: Direct and Spatial caches

Virtual Memory. Main memory is a CACHE for disk Advantages: illusion of having more physical memory program relocation protection.

EN1640: Design of Computing Systems Topic 06: Memory System

CSE 431 Computer Architecture Fall Chapter 5A: Exploiting the Memory Hierarchy, Part 1

Chapter 7 Large and Fast: Exploiting Memory Hierarchy. Memory Hierarchy. Locality. Memories: Review

Chapter Seven. Large & Fast: Exploring Memory Hierarchy

LRU. Pseudo LRU A B C D E F G H A B C D E F G H H H C. Copyright 2012, Elsevier Inc. All rights reserved.

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Textbook: Burdea and Coiffet, Virtual Reality Technology, 2 nd Edition, Wiley, Textbook web site:

EN1640: Design of Computing Systems Topic 06: Memory System

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. 5 th. Edition. Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

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

LECTURE 11. Memory Hierarchy

Memory. Lecture 22 CS301

and data combined) is equal to 7% of the number of instructions. Miss Rate with Second- Level Cache, Direct- Mapped Speed

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Memory Technologies. Technology Trends

The Memory Hierarchy & Cache Review of Memory Hierarchy & Cache Basics (from 350):

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

EECS 322 Computer Architecture Superpipline and the Cache

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Advanced Memory Organizations

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Background. Memory Hierarchies. Register File. Background. Forecast Memory (B5) Motivation for memory hierarchy Cache ECC Virtual memory.


Chapter 5 Memory Hierarchy Design. In-Cheol Park Dept. of EE, KAIST

CSE502: Computer Architecture CSE 502: Computer Architecture

Computer Architecture A Quantitative Approach, Fifth Edition. Chapter 2. Memory Hierarchy Design. Copyright 2012, Elsevier Inc. All rights reserved.

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

Computer Architecture Computer Science & Engineering. Chapter 5. Memory Hierachy BK TP.HCM

Memory Technology. Caches 1. Static RAM (SRAM) Dynamic RAM (DRAM) Magnetic disk. Ideal memory. 0.5ns 2.5ns, $2000 $5000 per GB

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

Spring 2016 :: CSE 502 Computer Architecture. Caches. Nima Honarmand

COMPUTER ORGANIZATION AND DESIGN

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Spring 2018 :: CSE 502. Cache Design Basics. Nima Honarmand

EEC 483 Computer Organization

Multilevel Memories. Joel Emer Computer Science and Artificial Intelligence Laboratory Massachusetts Institute of Technology

CENG 3420 Computer Organization and Design. Lecture 08: Cache Review. Bei Yu

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

EE 4683/5683: COMPUTER ARCHITECTURE

Sarah L. Harris and David Money Harris. Digital Design and Computer Architecture: ARM Edition Chapter 8 <1>

1/19/2009. Data Locality. Exploiting Locality: Caches

The Memory Hierarchy & Cache

Memory Hierarchy and Caches

Memory Hierarchy: Motivation

12 Cache-Organization 1

Memory Hierarchy: The motivation

CHAPTER 4 MEMORY HIERARCHIES TYPICAL MEMORY HIERARCHY TYPICAL MEMORY HIERARCHY: THE PYRAMID CACHE PERFORMANCE MEMORY HIERARCHIES CACHE DESIGN

A Cache Hierarchy in a Computer System

Lecture 11. Virtual Memory Review: Memory Hierarchy

Adapted from David Patterson s slides on graduate computer architecture

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

CENG 3420 Computer Organization and Design. Lecture 08: Memory - I. Bei Yu

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

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

CS3350B Computer Architecture

5. Memory Hierarchy Computer Architecture COMP SCI 2GA3 / SFWR ENG 2GA3. Emil Sekerinski, McMaster University, Fall Term 2015/16

Course Administration

LECTURE 5: MEMORY HIERARCHY DESIGN

Copyright 2012, Elsevier Inc. All rights reserved.

Cache Memory COE 403. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

Memory systems. Memory technology. Memory technology Memory hierarchy Virtual memory

Computer Systems Architecture I. CSE 560M Lecture 18 Guest Lecturer: Shakir James

Large and Fast: Exploiting Memory Hierarchy

Copyright 2012, Elsevier Inc. All rights reserved.

CSF Improving Cache Performance. [Adapted from Computer Organization and Design, Patterson & Hennessy, 2005]

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Computer Architecture. A Quantitative Approach, Fifth Edition. Chapter 2. Memory Hierarchy Design. Copyright 2012, Elsevier Inc. All rights reserved.

Page 1. Multilevel Memories (Improving performance using a little cash )

The Memory Hierarchy. Cache, Main Memory, and Virtual Memory (Part 2)

The levels of a memory hierarchy. Main. Memory. 500 By 1MB 4GB 500GB 0.25 ns 1ns 20ns 5ms

Memory Hierarchy. Mehran Rezaei

Handout 4 Memory Hierarchy

Memory Hierarchy Basics. Ten Advanced Optimizations. Small and Simple

V. Primary & Secondary Memory!

Modern Computer Architecture

TDT Coarse-Grained Multithreading. Review on ILP. Multi-threaded execution. Contents. Fine-Grained Multithreading

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Memory latency: Affects cache miss penalty. Measured by:

Page 1. Memory Hierarchies (Part 2)

CS 61C: Great Ideas in Computer Architecture. The Memory Hierarchy, Fully Associative Caches

Memory Hierarchy. 2/18/2016 CS 152 Sec6on 5 Colin Schmidt

Memory Hierarchy Design

Memory Hierarchy Y. K. Malaiya

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface

CMPT 300 Introduction to Operating Systems

Transcription:

The Main Memory Unit CPU and memory unit interface Address Data Control CPU Memory CPU issues address (and data for write) Memory returns data (or acknowledgment for write) Memories: Design Objectives Provide adequate storage capacity Four ways to approach this goal Use of number of different memory devices with different cost/performance ratios Automatic space-allocation methods in hierarchy Development of virtual-memory concept Design of communication links

Memories: Characteristics Location: Inside CPU, Outside CPU, External Performance: Access time, Cycle time, Transfer rate Capacity: Word size, Number of words Unit of Transfer: Word, Block Access: Sequential, Direct, Random, associative Physical Type: Semiconductor, Magnetic, Optical 3 Memories: Basic Parameters Cost: c=c/s ($/bit) Performance: Read access time (Ta), access rate (/Ta) Access Mode: random access, serial, semi-random Alterability: R/W, Read Only, PROM, EPROM, EEPROM Storage: Destructive read out, Dynamic, Volatility Hierarchy: Tape, Disk, DRUM, CCD, CORE, MOS, BiPOLAR

Exploiting Memory Hierarchy Users want large and fast memories! SRAM access times are - 5ns at cost of $ to $5 per Mbyte. DRAM access times are 6-ns at cost of $5 to $ per Mbyte. Disk access times are to million ns at cost of $. to $. per Mbyte. Try and give it to them anyway build a memory hierarchy Levels in the memory hierarchy CPU Level Level Increasing distance from the CPU in access time Level n Size of the memory at each level 5 Advantage of Memory Hierarchy Decrease cost/bit Increase capacity Improve average access time Decrease frequency of accesses to slow memory 6

Memories: Review SRAM: value is stored on a pair of inverting gates very fast but takes up more space than DRAM DRAM: value is stored as a charge on capacitor very small but slower than SRAM (factor of 5/) A B A B Word line Pass transistor Capacitor Bit line 7 Memories: Array Organization Storage cells are organized in a rectangular array The address is divided into row and column parts There are M (= r ) rows of N bits each The row address (r bits) selects a full row of N bits The column address (c bits) selects k bits out of N M and N are generally powers of Total size of a memory chip = M*N bits It is organized as A= r+c addresses of k-bit words To design an R addresses W-bit words memory, we need R/A * W/k chips 8

Mx6-bit Memory using Mx memory chip : Data in B 5 3 9 8 7 6 5 3 B 5 3 9 8 7 6 5 3 B 5 3 9 8 7 6 5 3 B3 5 3 9 8 7 6 5 3 Addr lines 3-3 - 3 Bank Addr Row Addresses Column Addresses Byte Addr Data out Decoder B3 B B B To all chips row addresses To all chips column addresses To select a byte in 6 bit word 9 Locality A principle that makes memory hierarchy a good idea If an item is referenced temporal locality: it will tend to be referenced again soon spatial locality: nearby items will tend to be referenced soon. Why does code have locality? Our initial focus: two levels (upper, lower) block: minimum unit of data hit: data requested is in the upper level miss: data requested is not in the upper level

Memory Hierarchy and Access Time ti is time for access at level i on-chip cache, off-chip cache, main memory, disk, tape N accesses ni satisfied at level i a higher level can always satisfy any access that is satisfied by a lower level N = n + n + n3 + n + n5 Hit Ratio number of accesses satisfied/number of accesses made Could be confusing For example for level 3 is it n3/n or (n+n+n3)/n or n3/(nn-n) We will take the second definition Average Access Time ti is time for access at level i ni satisfied at level i hi is hit ratio at level i hi = (n + n + + ni) /N We will also assume that data are transferred from level i+ to level i before satisfying the request Total time = n*t + n*(t+t) + n3*(t+t+t3) + n* (t+t+t3+t) + n5*(t+t+t3+t+t5) Average time = Total time/n t(avr) = t+t*(i-h)+t3*(-h)+t*(-h3)+t5*(-h) Total Cost = C*S+C*S+C3*S3+C*S+C5*S5

Cache Two issues: How do we know if a data item is in the cache? If it is, how do we find it? Our first example: block size is one word of data "direct mapped" For each item of data at the lower level, there is exactly one location in the cache where it might be. e.g., lots of items at the lower level share locations in the upper level 3 Direct Mapped Cache Mapping: address is modulo the number of blocks in the cache Cache Memory

Direct Mapped Cache For MIPS: Address (showing bit positions) 3 3 3 Byte offset Hit Tag Data Index Index Valid Tag Data 3 3 What kind of locality are we taking advantage of? 5 Direct Mapped Cache Taking advantage of spatial locality: Address (showing bit positions) 3 6 5 3 Hit Tag 6 Byte offset Data Index Block offset 6 bits 8 bits V Tag Data K entries 6 3 3 3 3 Mux 3 6

Hits vs. Misses Read hits this is what we want! Read misses stall the CPU, fetch block from memory, deliver to cache, restart Write hits: can replace data in cache and memory (write-through) write the data only into the cache (write-back the cache later) Write misses: read the entire block into the cache, then write the word 7 Hardware Issues Make reading multiple words easier by using banks CPU CPU CPU Cache Multiplexor Cache Cache Bus Bus Bus Memory Memory Memory Memory Memory bank bank bank bank 3 Memory b. Wide memory organization c. Interleaved memory organization It can get a a. One-word-wide lot more complicated... memory organization 8

Performance Increase in block size tend to decrease miss rate: Miss rate % 35% 3% 5% % 5% % 5% % 6 6 56 Block size (bytes) KB 8 KB 6 KB 6 KB 56 KB Use split caches (more spatial locality in code) Program Block size in words Instruction miss rate Data miss rate Effective combined miss rate gcc 6.%.% 5.%.%.7%.9% spice.%.3%.%.3%.6%.% 9 Performance Simplified model: execution time=(execution cycles + stall cycles) cct stall cycles= #of instructions miss ratio*miss penalty Two ways of improving performance: decreasing the miss ratio decreasing the miss penalty What happens if we increase block size?

Decreasing miss ratio with associativity One way set associative (direct mapped) Block Tag Data 3 5 6 7 Two-way set associative Set Tag Data Tag Data 3 Four-way set associative Set Tag Data Tag Data Tag Data Tag Data Eight-way set associative (fully associative) Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Compared to direct mapped, give a series of references that: results in a lower miss ratio using a -way set associative cache results in a higher miss ratio using a -way set associative cache assuming we use the least recently used replacement strategy An implementation 3 3 9 8 3 8 Index V Tag Data V Tag Data V Tag Data V Tag Data 53 5 55 3 -to- multiplexor Hit Data

Performance 5% % 9% Miss rate 6% 3% % One-way Two-way Four-way Eight-way Associativity KB 6 KB KB 3 KB KB 6 KB 8 KB 8 KB 3 Decreasing miss penalty with multilevel caches Add a second level cache: often primary cache is on the same chip as the processor use SRAMs to add another cache above primary memory (DRAM) miss penalty goes down if data is in nd level cache Example: CPI of. on a 5Mhz machine with a 5% miss rate, ns DRAM access Adding nd level cache with ns access time decreases miss rate to % Using multilevel caches: try and optimize the hit time on the st level cache try and optimize the miss rate on the nd level cache

Virtual Memory Main memory can act as a cache for the secondary storage (disk) Virtual addresses Address translation Physical addresses Disk addresses Advantages: illusion of having more physical memory program relocation protection 5 Pages: virtual memory blocks Page faults: the data is not in memory, retrieve it from disk huge miss penalty, thus pages should be fairly large (e.g., KB) reducing page faults is important (LRU is worth the price) can handle the faults in software instead of hardware using write-through is too expensive so we use writeback Virtual address 3 3 9 8 7 5 3 9 8 3 Virtual page number Page offset Translation 9 8 7 5 3 9 8 3 Physical page number Page offset Physical address 6

Page Tables Virtual page number Page table Physical page or Valid disk address Physical memory Disk storage 7 Page Tables Page table register Virtual address 3 3 9 8 7 5 3 9 8 3 Virtual page number Page offset Valid Physical page number Page table If then page is not present in memory 8 9 8 7 5 3 9 8 3 Physical page number Page offset Physical address 8

Making Address Translation Fast A cache for address translations: translation lookaside buffer Virtual page number Valid Tag TLB Physical page address Physical memory Page table Physical page Valid or disk address Disk storage 9 TLBs and Caches Virtual address TLB access TLB miss exception No TLB hit? Yes Physical address No Write? Yes Try to read data from cache No Write access bit on? Yes Cache miss stall No Cache hit? Yes Write protection exception Write data into cache, update the tag, and put the data and the address into the write buffer Deliver data to the CPU 3

Replacement Policies Replacement Policies in Multi-way Set Associative caches Random: Replace any line arbitrarily Least Recently Used (LRU): Find the least recently used line to replace Keep Most Recently Used (MRU): Keep the last used line in the set and replace any other randomly LRU performs the best MRU does equally well 3 LRU Scheme We explain LRU with an example of a -way set associative cache Associate a -bit counter with each line (log k bit for k-way cache) Initially all lines are invalid For a miss bring a new line in an invalid line, make it valid, set its counter to zero, increment all other counters If no invalid line, replace the line with counter value = 3, set its counter to zero, increment all other counters For a hit, set the accessed line s counter to zero and increment counters of those lines whose values is smaller than the accessed line Try this algorithm for an examples where lines read are, 6, 8, 6, 9, 56, 8,, 56, 9, 6 There are 6 lines in each cache and it is -way set associative 3

Reading or Writing a Memory word Check the address in TLB If not there, get the physical translation and also store the entry in TLB Penalty -5 cycles If page itself is not present, page fault occurs Read the page, update page table and TLB Penalty s of thousands cycles Once physical address is there If there, perform read or write in cache If cache miss Read the line in cache for read May need to replace a dirty or clean line Penalty - cycles For Write read the line if write allocate, else write around If cache hit read or write in cache Also write in main memory if write through 33 A Big Example Instruction Frequency: LW(%), SW(%), R(5%), BR(5%), J(5%) Branch Penalty: 3 cycles on % mis-predictions = 5*.*3 = 9 cycles Data Cache : Miss rate % (of load/store), write back, write around, 5% dirty replacement, penalty for reading or writing a line cycles Load penalty = *.*.5* + *.*.5*(+) = 6 cycles Store Penalty = (because of write around, otherwise will be 3) Data Cache : Miss rate 5% (of load/store), write back, write allocation, 5% dirty replacement, penalty for reading or writing a line cycles Load penalty = *.5*.5* + *.5*.5*(+) = 5 cycles Store Penalty = *.5*.5* + *.5*.5*(+) = 75 cycles TLB: Miss Rate % (of load/store), Miss Penalty cycles Total Penalty = (+)*.* = 6 cycles Page faults:.% (of load/store), Penalty 3, cycles Total Penalty = (+)*.*3, = 9 cycles Total Time = +9+6+5+75+6+9 = 35 cycles, or CPI=3.5 Notice that miss rates can be spacified per instruction or per load/store 3

Misses and Replacement Policies 3 C Misses Compulsory: Miss will have to occur on first read (or write) Capacity: A line is replaced and then brought back Conflict: a miss occurs as some other line is occupying that line Example Suppose we read line a first time (no line is in cache), then read line b that replaces line a, and then read line a again The first and second misses are compulsory, second miss is also capacity and conflict, and the third miss is capacity (and also conflict) The terminology can be confusing here The first read is always classified as compulsory The replacement and read back is conflict if there was place in cache elsewhere but you had to bring it at that place due to mapping If there was no place at all then it is capacity miss (like cache is full in a fully associative cache) 35 Virtual Memory: Other Translation Schemes In a single-level translation 3 bit virtual address KB Page size ( bit address in each page) Leaves -bit page address => Million Pages =>MB for Table One alternate is to only have a limited size page table with Hi and Lo Checks But program use many addresses segments Alternate is to have a two level page table Divide page addresses in two parts of bits each There are K tables of K entries each (total is still M entries) Most significant bits points to a table (with K entries, each bytes long, a total of KB that fits in a page) that contains the address of that part of table Least significant bits are used to access a particular entry in the selected table We only need to keep the first table (pointing to real tables) and some of the second level tables in memory 36

Modern Systems Very complicated memory systems: Characteristic Intel Pentium Pro PowerPC 6 Virtual address 3 bits 5 bits Physical address 3 bits 3 bits Page size KB, MB KB, selectable, and 56 MB TLB organization A TLB for instructions and a TLB for data A TLB for instructions and a TLB for data Both four-way set associative Both two-way set associative Pseudo-LRU replacement LRU replacement Instruction TLB: 3 entries Instruction TLB: 8 entries Data TLB: 6 entries Data TLB: 8 entries TLB misses handled in hardware TLB misses handled in hardware Characteristic Intel Pentium Pro PowerPC 6 Cache organization Split instruction and data caches Split intruction and data caches Cache size 8 KB each for instructions/data 6 KB each for instructions/data Cache associativity Four-way set associative Four-way set associative Replacement Approximated LRU replacement LRU replacement Block size 3 bytes 3 bytes Write policy Write-back Write-back or write-through 37 Some Issues Processor speeds continue to increase very fast much faster than either DRAM or disk access times Design challenge: dealing with this growing disparity Trends: synchronous SRAMs (provide a burst of data) redesign DRAM chips to provide higher bandwidth or processing restructure code to increase locality use prefetching (make cache visible to ISA) 38