EN1640: Design of Computing Systems Topic 06: Memory System

Similar documents
EN1640: Design of Computing Systems Topic 06: Memory System


Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

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

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Digital Logic & Computer Design CS Professor Dan Moldovan Spring Copyright 2007 Elsevier 8-<1>

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

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

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

COMPUTER ORGANIZATION AND DESIGN

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 8 :: Topics. Chapter 8 :: Memory Systems. Introduction Memory System Performance Analysis Caches Virtual Memory Memory-Mapped I/O Summary

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Direct Mapped Cache Hardware. Direct Mapped Cache. Direct Mapped Cache Performance. Direct Mapped Cache Performance. Miss Rate = 3/15 = 20%

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

V. Primary & Secondary Memory!

Chapter 3. SEQUENTIAL Logic Design. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris.

CSE 2021: Computer Organization

Chapter 8. Digital Design and Computer Architecture, 2 nd Edition. David Money Harris and Sarah L. Harris. Chapter 8 <1>

CSE 2021: Computer Organization

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

CS/ECE 3330 Computer Architecture. Chapter 5 Memory

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Memory Hierarchy. Reading. Sections 5.1, 5.2, 5.3, 5.4, 5.8 (some elements), 5.9 (2) Lecture notes from MKP, H. H. Lee and S.

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

Main Memory Supporting Caches

Caches. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 5. Large and Fast: Exploiting Memory Hierarchy. Jiang Jiang

Chapter 8 Virtual Memory

Chapter 5. Memory Technology

Chapter 8. Chapter 8:: Topics. Introduction. Processor Memory Gap

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

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

Memory. Principle of Locality. It is impossible to have memory that is both. We create an illusion for the programmer. Employ memory hierarchy

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

CS161 Design and Architecture of Computer Systems. Cache $$$$$

Computer Systems Laboratory Sungkyunkwan University

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

EN2910A: Advanced Computer Architecture Topic 02: Review of classical concepts

Chapter 5. Large and Fast: Exploiting Memory Hierarchy. Part II Virtual Memory

Cache Optimization. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS3350B Computer Architecture

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

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

Memory Hierarchy. ENG3380 Computer Organization and Architecture Cache Memory Part II. Topics. References. Memory Hierarchy

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

Chapter 8 Memory Hierarchy and Cache Memory

COMPUTER ORGANIZATION AND DESIGN ARM

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

Memory Hierarchy and Caches

EE 4683/5683: COMPUTER ARCHITECTURE

The Memory Hierarchy Cache, Main Memory, and Virtual Memory

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

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

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

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

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

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

COEN-4730 Computer Architecture Lecture 3 Review of Caches and Virtual Memory

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

Fundamentals of Computer Systems

Memory Hierarchy Y. K. Malaiya

Course Administration

Advanced Memory Organizations

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

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

LECTURE 11. Memory Hierarchy

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)

registers data 1 registers MEMORY ADDRESS on-chip cache off-chip cache main memory: real address space part of virtual addr. sp.

Memory Technologies. Technology Trends

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

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

COMPUTER ORGANIZATION AND DESIGN

ECE331: Hardware Organization and Design

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

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

Adapted from David Patterson s slides on graduate computer architecture

ECE331: Hardware Organization and Design

registers data 1 registers MEMORY ADDRESS on-chip cache off-chip cache main memory: real address space part of virtual addr. sp.

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

LECTURE 5: MEMORY HIERARCHY DESIGN

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

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

Chapter 2: Memory Hierarchy Design (Part 3) Introduction Caches Main Memory (Section 2.2) Virtual Memory (Section 2.4, Appendix B.4, B.

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

Computer Architecture. Memory Hierarchy. Lynn Choi Korea University

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

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

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

Computer Architecture Review. Jo, Heeseung

Page 1. Memory Hierarchies (Part 2)

Fundamentals of Computer Systems

Transcription:

EN164: Design of Computing Systems Topic 6: Memory System Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University Spring 214 [ material from Patterson & Hennessy, 4th ed and Harris 1st ed ] 1

Introduction Computer performance depends on: Processor performance Memory system performance Memory Interface CLK CLK MemWrite WE Processor Address WriteData Memory ReadData 2

Introduction Up until now, assumed memory could be accessed in 1 clock cycle 3

Memory hierarchy Technology cost / GB Access time Speed Cache Main Memory magnetic hard Virtual disk Memory SRAM ~ $1, ~ 1 ns DRAM ~ $1 ~ 1 ns Hard magnetic Disk ~ $1 ~ 1,, ns hard disk Size Ideal memory Access time of SRAM Capacity and cost/gb of disk 26 prices 4

SRAM and DRAM cells Classical 6T SRAM cell Classical 1T+1C DRAM cell SRAM cell takes more silicon area than 1T DRAM cellà more memory capacity per unit area for DRAM à cheaper memory per bit. SRAM holds its charge, more stable and much faster than DRAM. DRAM requires constant refreshing due to leakage. 5

Principle of locality Exploit locality to make memory accesses fast Temporal Locality: Locality in time (e.g., if looked at a Web page recently, likely to look at it again soon) If data used recently, likely to use it again soon How to exploit: keep recently accessed data in higher levels of memory hierarchy Spatial Locality: Locality in space (e.g., if read one page of book recently, likely to read nearby pages soon) If data used recently, likely to use nearby data soon How to exploit: when access data, bring nearby data into higher levels of memory hierarchy too 6

Memory hierarchy levels Block (aka line): unit of copying May be multiple words If accessed data is present in upper level Hit: access satisfied by upper level Hit ratio: hits/accesses If accessed data is absent Miss: block copied from lower level Time taken: miss penalty Miss ratio: misses/accesses = 1 hit ratio Then accessed data supplied from upper level 7

Example A program has 2, load and store instructions 1,25 of these data values found in cache The rest are supplied by other levels of memory hierarchy What are the hit and miss rates for the cache? Hit Rate = 125/2 =.625 Miss Rate = 75/2 =.375 = 1 Hit Rate 8

Example Suppose processor has 2 levels of hierarchy: cache and main memory t cache = 1 cycle, t MM = 1 cycles What is the average memory access time (AMAT) of the program from Example 1? AMAT = t cache + MR cache (t MM ) = [1 +.375(1)] cycles = 38.5 cycles 9

Cache memory n n Cache memory n The level of the memory hierarchy closest to the CPU n n Fast (typically ~ 1 cycle access time) Made out of SRAM cells Given accesses X 1,, X n 1, X n What data is held in the cache? How is data found? What data is replaced? 1

Direct mapped cache Location determined by address Direct mapped: only one choice (Block address) modulo (#Blocks in cache) n #Blocks is a power of 2 n Use low-order address bits 11

Example Address 11...111111 11...11111 11...11111 11...1111 11...11111 11...1111 11...1111 11...111 mem[xff...fc] mem[xff...f8] mem[xff...f4] mem[xff...f] mem[xff...ec] mem[xff...e8] mem[xff...e4] mem[xff...e]...11...1...111...11...11...1...11...1...1... mem[x...24] mem[x..2] mem[x..1c] mem[x...18] mem[x...14] mem[x...1] mem[x...c] mem[x...8] mem[x...4] mem[x...] 2 3 Word Main Memory 2 3 Word Cache Set Number 7 (111) 6 (11) 5 (11) 4 (1) 3 (11) 2 (1) 1 (1) () 12

Tag and valid bits n How do we know which particular block is stored in a cache location? n Store block address as well as the data n Actually, only need the high-order bits n Called the tag n What if there is no data in a location? n Valid bit: 1 = present, = not present n Initially 13

Cache hardware design Memory Address Tag Set 27 3 Byte Offset V Tag Data 8-entry x (1+27+32)-bit SRAM = 27 32 Hit Data 14

Example How many total bits are required for a direct-mapped cache with 16 KB of data and 4-word blocks, assuming a 32-bit address? 15

Direct cache performance example # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done done: lw lw lw $t1, x4($) $t2, xc($) $t3, x8($) addi $t, $t, -1 j Memory Address loop Tag... Set 1 3 Byte Offset V Tag Data Set 7 (111) Set 6 (11) Set 5 (11) Set 4 (1) Set 3 (11) Set 2 (1) Set 1 (1) Set () 16

Direct cache performance example # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done done: lw lw lw $t1, x4($) $t2, xc($) $t3, x8($) addi $t, $t, -1 j Memory Address loop Tag... Set 1 3 Byte Offset V Tag Data 1... mem[x...c] 1... mem[x...8] 1... mem[x...4] Miss Rate = 3/15 = 2% Temporal Locality Compulsory Misses Set 7 (111) Set 6 (11) Set 5 (11) Set 4 (1) Set 3 (11) Set 2 (1) Set 1 (1) Set () 17

Direct mapped cache: conflict # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done done: lw lw $t1, x4($) $t2, x24($) addi $t, $t, -1 j Memory Address loop Tag...1 Set 1 3 Byte Offset V Tag Data Set 7 (111) Set 6 (11) Set 5 (11) Set 4 (1) Set 3 (11) Set 2 (1) Set 1 (1) Set () 18

Direct cache map: conflict # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done done: lw lw $t1, x4($) $t2, x24($) addi $t, $t, -1 j Memory Address loop Tag...1 Set 1 3 Byte Offset V 1 Tag... Data mem[x...4] mem[x...24] Miss Rate = 1/1 = 1% Conflict Misses Set 7 (111) Set 6 (11) Set 5 (11) Set 4 (1) Set 3 (11) Set 2 (1) Set 1 (1) Set () 19

Impact of larger block sizes n 64 blocks, 16 bytes/block n To what block number does address 12 map? n Block address = 12/16 = 75 n Block number = 75 modulo 64 = 11 31 1 9 4 3 Tag Index Offset 22 bits 6 bits 4 bits 2

Block Size Considerations n Larger blocks should reduce miss rate n Due to spatial locality n But in a fixed-sized cache n Larger blocks fewer of them n More competition increased miss rate 21

Fully associative cache V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data V Tag Data tag byte hit selection lines 8x1 MUX No conflict misses Expensive to build 22

N-way set associate cache Memory Address Tag Set 28 2 Byte Offset V Tag Way 1 Way Data V Tag Data 28 32 28 32 = = Hit 1 Hit Hit 1 1 32 Hit Data 23

N-way set associative cache example # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done lw $t1, x4($) lw $t2, x24($) addi $t, $t, -1 j loop done: Way 1 Way V Tag Data V Tag Data 24

N-way set associative cache example # MIPS assembly code addi $t, $, 5 loop: beq $t, $, done done: lw lw $t1, x4($) $t2, x24($) addi $t, $t, -1 j V Tag loop Way 1 Way Data V Tag Data 1...1 mem[x...24] 1... mem[x...4] Miss Rate = 2/1 = 2% Associativity reduces conflict misses Set 3 Set 2 Set 1 Set 25

4-way associative 26

Spectrum of associativity n For a cache with 8 entries 27

Comparison example n Compare 4-block caches n Direct mapped, 2-way set associative, fully associative n Block access sequence:, 8,, 6, 8 n Direct mapped Block address Cache index Hit/miss Cache content after access 1 2 3 miss Mem[] 8 miss Mem[8] miss Mem[] 6 2 miss Mem[] Mem[6] 8 miss Mem[8] Mem[6] 28

Comparison example n 2-way set associative Block address Cache index Hit/miss miss Mem[] 8 miss Mem[] Mem[8] hit Mem[] Mem[8] 6 miss Mem[] Mem[6] 8 miss Mem[8] Mem[6] Cache content after access Set Set 1 n Fully associative Block address Hit/miss Cache content after access miss Mem[] 8 miss Mem[] Mem[8] hit Mem[] Mem[8] 6 miss Mem[] Mem[8] Mem[6] 8 hit Mem[] Mem[8] Mem[6] 29

How much associativity? n Increased associativity decreases miss rate n But with diminishing returns n Simulation of a system with 64KB D-cache, 16-word blocks, SPEC2 n 1-way: 1.3% n 2-way: 8.6% n 4-way: 8.3% n 8-way: 8.1% 3

Handling cache writes How to handle cache writes? Write through Write back How to handle write misses? 31

Write through n On data-write hit, could just update the block in cache n But then cache and memory would be inconsistent n Write through: also update memory n But makes writes take longer n e.g., if base CPI = 1, 1% of instructions are stores, write to memory takes 1 cycles n Effective CPI = 1 +.1 1 = 11 n Solution: write buffer n n Holds data waiting to be written to memory CPU continues immediately n Only stalls on write if write buffer is already full 32

Write back n Alternative: On data-write hit, just update the block in cache n Keep track of whether each block is dirty n When a dirty block is replaced n Write it back to memory n Can use a write buffer to allow replacing block to be read first 33

Write allocation on write misses n What should happen on a write miss? n Alternatives for write-through n Allocate on miss: fetch the block n Write around: don t fetch the block n Since programs often write a whole block before reading it (e.g., initialization) n For write-back n Usually fetch the block 34

Sources of misses n n n Compulsory misses (aka cold start misses) n First access to a block Capacity misses n n Due to finite cache size A replaced block is later accessed again Conflict misses (aka collision misses) n n n In a non-fully associative cache Due to competition for entries in a set Would not occur in a fully associative cache of the same total size 35

Cache design trade-offs Design change Effect on miss rate Negative performance effect Increase cache size Increase associativity Increase block size Decrease capacity misses Decrease conflict misses Decrease compulsory misses May increase access time May increase access time Increases miss penalty. 36

Replacement choices n Direct mapped: no choice n Set associative n Prefer non-valid entry, if there is one n Otherwise, choose among entries in the set n What is the optimal entry to remove? n Random n Least-recently used (LRU) n Choose the one unused for the longest time n Simple for 2-way, manageable for 4-way, too hard beyond that 37

LRU Replacement example # MIPS assembly lw $t, x4($) lw $t1, x24($) lw $t2, x54($) V U Tag Data V Tag Data Set Number 3 (11) (a) 2 (1) 1 (1) () V U Tag Data V Tag Data Set Number 3 (11) (b) 2 (1) 1 (1) () 38

LRU Replacement example # MIPS assembly lw $t, x4($) lw $t1, x24($) lw $t2, x54($) Way 1 Way (a) V U Tag Data V Tag Data 1...1 mem[x...24] 1... mem[x...4] Way 1 Way Set 3 (11) Set 2 (1) Set 1 (1) Set () (b) V U Tag Data V Tag 1 1...1 mem[x...24] 1...11 Data mem[x...54] Set 3 (11) Set 2 (1) Set 1 (1) Set () 39

Multi-level caches n Primary cache attached to CPU n Small, but fast n Level-2 cache services misses from primary cache n Larger, slower, but still faster than main memory n Main memory services L-2 cache misses n Some high-end systems include L-3 cache 4

Multi-level cache example n Given n CPU base CPI = 1, clock rate = 4GHz n Miss rate/instruction = 2% n Main memory access time = 1ns n With just primary cache n Miss penalty = 1ns/.25ns = 4 cycles n Effective CPI = 1 +.2 4 = 9 41

Multi-level cache example n Now add L-2 cache n Access time = 5ns n Global miss rate to main memory =.5% n Primary miss with L-2 hit n Penalty = 5ns/.25ns = 2 cycles n Primary miss with L-2 miss n Extra penalty = 5 cycles n CPI = 1 +.2 2 +.5 4 = 3.4 n Performance ratio = 9/3.4 = 2.6 42

Cache summary Cache is on-chip memory built using 6T SRAM cells Cache organization: Direct Fully associative N-way set associative Cache write techniques Cache block replacement techniques (for associative) Multi-level cache 43

Main memory: DRAM DRAM is usually a shared resource among multiple processors, GPU and I/O devices à a controller is need to coordinate the access 44

DRAM organization (1-bit array) Reads are destructive; content must be restored after reading Capacitors are leaky so they must be periodically refreshed DRAM controller must each refresh each row (by reading and rewriting it) every 64 ms or less Refreshing contributes to the slow access of DRAMs 45

Multiple bit DRAM organization In a x4 DRAM part, four arrays each read 1 data bit in unison, and the part sends out 4 bits of data each time the memory controller makes a column read request 46

DRAM operation: bus transmission 47

DRAM operation: row access 48

DRAM operation: column access 49

DRAM operation: data transfer 5

DRAM operation: bus transmission 51

Simple asynchronous memory reading Lower pin count (cost) by using same pins for row and column addresses 52

Synchronous DRAM (SDRAM) read Clock RAS CAS Row Activation Column Read Transfer Overlap DataTransfer Address Row Addr Col Addr DQ Valid Data Valid Data Valid Data Valid Data To increase throughput, SDRAM outputs the data of sequential columns of the same row into the data bus (BURST mode). Now needs a clock Matches well with cache blocks with multiple bytes 53

Double Data Rate (DDR) SDRAM Transfer data on positive and negative edges of the clock 54

DRAM memory bus organization bank 55

Memory interleaving n n 4-word wide memory n n Miss penalty = 1 + 15 + 1 = 17 bus cycles Bandwidth = 16 bytes / 17 cycles =.94 B/cycle 4-bank interleaved memory n n Miss penalty = 1 + 15 + 4 1 = 2 bus cycles Bandwidth = 16 bytes / 2 cycles =.8 B/cycle 56

DRAM connections In PC DRAM slots In smart phones/ tablets DRAM die Processor die A PoP implementation 57

Virtual memory Each program uses virtual addresses Entire virtual address space stored on a hard disk. Subset of virtual address data in DRAM CPU translates virtual addresses into physical addresses Data not in DRAM is fetched from the hard disk Each program has its own virtual to physical mapping Two programs can use the same virtual address for different data Programs don t need to be aware that others are running One program (or virus) can t corrupt the memory used by another This is called memory protection 58

Virtual and physical addresses Most accesses hit in physical memory But programs have the large capacity of virtual memory 59

Virtual memory definitions Page size: amount of memory transferred from hard disk to DRAM at once Address translation: determining the physical address from the virtual address Page table: lookup table used to translate virtual addresses to physical addresses 6

Address translation 61

Virtual memory example System: Virtual memory size: 2 GB = 2 31 bytes Physical memory size: 128 MB = 2 27 bytes Page size: 4 KB = 2 12 bytes Organization: Virtual address: 31 bits Physical address: 27 bits Page offset: 12 bits # Virtual pages = 2 31 /2 12 = 2 19 (VPN = 19 bits) # Physical pages = 2 27 /2 12 = 2 15 (PPN = 15 bits) 62

Virtual memory example What is the physical address of virtual address x247c? VPN = x2 VPN x2 maps to PPN x7fff The lower 12 bits (page offset) is the same for virtual and physical addresses (x47c) Physical address = x7fff47c 19-bit virtual page numbers - 15-bit physical page numbers 63

Using page tables to translate addresses Page Table stores placement information Array of page table entries, indexed by virtual page number Page table register in CPU points to page table in physical memory If page is present in memory PTE stores the physical page number Plus other status bits (referenced, dirty, ) If page is not present PTE can refer to location in swap space on disk 64

Translation using page table 65

Mapping pages to storage 66

Page table example 1 What is the physical address of virtual address x5f2? VPN = 5 Entry 5 in page table indicates VPN 5 is in physical page 1 Physical address is x1f2 Virtual Address Virtual Page Number x5 19 Page Offset F2 12 V 1 x 1 x7ffe 1 x1 1 x7fff Hit Physical Address Physical Page Number Page Table 15 12 x1 F2 67

Page table example 2 What is the physical address of virtual address x73e? VPN = 7 Entry 7 in page table is invalid, so the page is not in physical memory The virtual page must be swapped into physical memory from disk Virtual Address Virtual Page Number x7 19 Page Offset 3E V Physical Page Number 1 x 1 x7ffe 1 x1 1 x7fff Page Table Hit 15 68

Page table challenges Page table is large usually located in physical memory Each load/store requires two main memory accesses: one for translation (page table read) one to access data (after translation) Cuts memory performance in half Unless we get clever 69

Last lecture summary 7

Replacement and writes Replacement: To reduce page fault rate, prefer least-recently used (LRU) replacement Reference bit (aka use bit) in PTE set to 1 on access to page Periodically cleared to by OS A page with reference bit = has not been used recently Writes: Disk writes take millions of cycles Block at once, not individual locations Write through is impractical; use write-back Dirty bit in PTE set when page is written Write a physical page and reloading a different virtual page is called swapping 71

Fast translation using TLB Use a translation lookaside buffer (TLB) Small cache of most recent translations Reduces number of memory accesses required for most loads/stores from two to one TLB Small: accessed in < 1 cycle Typically 16-512 entries Fully associative > 99 % hit rates typical Reduces # of memory accesses for most loads and stores from 2 to 1 72

Example: Two-entry TLB Virtual Address Virtual Page Number x2 19 Page Offset 47C 12 Entry 1 Entry V Virtual Page Number Physical Page Number 1 x7fffd x 1 x2 x7fff V Virtual Page Number Physical Page Number 19 15 19 15 TLB = = Hit 1 Hit 1 Hit 1 Hit 15 Physical Address x7fff 47C 12 73

TLB misses n If page is in memory n Load the PTE from memory and retry n Could be handled in hardware n Can get complex for more complicated page table structures n Or in software n Raise a special exception, with optimized handler n If page is not in memory (page fault) n OS handles fetching the page and updating the page table n Then restart the faulting instruction 74

Memory protection Multiple programs (processes) run at once Each process has its own page table special register holds the starting address of the table Each process can use entire virtual address space without worrying about where other programs are A process can only access physical pages mapped in its page table can t overwrite memory from another process Modifications to TLB: Invalidate the TLB every time there is a context switch Or augment TLB with process id 75

1. TLB/Cache: physical tag, physical index virtual address page offset 2 bits 12 bits 4 KB page size 1 cycle Translate TLB 1 cycle 2 bits 12 bits 18 bits 12 bits 2 bits Tag 16 KB cache size 4 bytes / block Direct mapped 496 blocks hit data 76

2. TLB/Cache: virtual tag, virtual index virtual address page offset 2 bits 12 bits 4 KB page size 1 cycle 18 bits 12 bits 2 bits Tag 16 KB cache size 4 bytes / block Direct mapped 496 blocks hit data TLB is only accessed in case of miss Complications due to aliasing: Different virtual addresses for shared physical address 77

3. TLB/Cache: physical tag, virtual index virtual address page offset 2 bits 12 bits 4 KB page size 1 cycle Translate TLB 2 bits 12 bits first design attempt 1 cycle 2bits Tag 1 bits 2 bits 4KB cache size 4 bytes / block Direct mapped 124 blocks hit data 78

3. TLB/Cache: physical tag, virtual index 1 cycle virtual address 2 bits Translate TLB page offset 12 bits 2 bits 12 bits 2bits 1 bits 2 bits 4 KB page size 4KB cache size 4 bytes / block Direct mapped Tag 124 blocks hit data TLB can now be accessed in parallel with cache Constrain cache design: fundamental cache size (# sets * block size = page size). Only way to increase cache size is by increasing associativity 79

Virtual memory summary Virtual memory increases capacity and essential for multitasking OS A subset of virtual pages are located in physical memory A page table maps virtual pages to physical pages this is called address translation A TLB speeds up address translation Using different page tables for different programs provides memory protection 8

Pentium Pro memory hierarchy Address Size: 32 bits VM Page Size: 4 KB, 4 MB TLB organization: separate I and D TLBs (I-TLB: 32 entries, D-TLB: 64 entries) 4-way set associative LRU approximated hardware handles miss L1 Cache: 8 KB, separate I, D 4-way set associative LRU 32 byte block write back L2 Cache: 256 or 512 KB 81

Memory subsystem summary Fast memories are small, large memories are slow We really want fast, large memories Caching gives this illusion Principle of locality Programs use a small part of their memory space frequently Memory hierarchy L1 cache L2 cache DRAM memory disk Virtual memory 82