CSE 490/590 Computer Architecture Virtual Memory II

Slides:



Advertisements
Similar presentations
Krste Asanovic Electrical Engineering and Computer Sciences
Advertisements

Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Cache III Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Snoopy Caches I Steve Ko Computer Sciences and Engineering University at Buffalo.
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Snoopy Caches II Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Cache II Steve Ko Computer Sciences and Engineering University at Buffalo.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Address Translation and Protection Steve Ko Computer Sciences and Engineering University at.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Virtual Memory I Steve Ko Computer Sciences and Engineering University at Buffalo.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Virtual Memory 2 P & H Chapter
February 25, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering.
CS 152 Computer Architecture and Engineering Lecture 11 - Virtual Memory and Caches Krste Asanovic Electrical Engineering and Computer Sciences University.
CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and Computer Sciences University of California.
February 23, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 9 - Virtual Memory Krste Asanovic Electrical Engineering and Computer.
Computer ArchitectureFall 2008 © November 10, 2007 Nael Abu-Ghazaleh Lecture 23 Virtual.
Computer ArchitectureFall 2007 © November 21, 2007 Karem A. Sakallah Lecture 23 Virtual Memory (2) CS : Computer Architecture.
February 16, 2011CS152, Spring 2011 CS 152 Computer Architecture and Engineering Lecture 8 - Address Translation Krste Asanovic Electrical Engineering.
CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering and Computer Sciences University of.
February 23, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 10 - Virtual Memory Krste Asanovic Electrical Engineering and.
Translation Buffers (TLB’s)
CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering and Computer Sciences University of.
February 18, 2010CS152, Spring 2010 CS 152 Computer Architecture and Engineering Lecture 9 - Address Translation Krste Asanovic Electrical Engineering.
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 15 CS252 Graduate Computer Architecture Spring 2014 Lecture 15: Virtual Memory and Caches Krste Asanovic.
CS 252 Graduate Computer Architecture Lecture 9: Address Translation and Virtual Memory Krste Asanovic Electrical Engineering and Computer Sciences University.
Lecture 19: Virtual Memory
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
CS 61C: Great Ideas in Computer Architecture Virtual Memory Instructors: Krste Asanovic, Randy H. Katz 1Fall.
ECE 552 / CPS 550 Advanced Computer Architecture I Lecture 14 Virtual Memory Benjamin Lee Electrical and Computer Engineering Duke University
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Virtual Memory Muhamed Mudawar CS 282 – KAUST – Spring 2010 Computer Architecture & Organization.
Virtual Memory: Part Deux
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
2/14/2013 CS152, Spring 2013 CS 152 Computer Architecture and Engineering Lecture 8 - Address Translation Krste Asanovic Electrical Engineering and Computer.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
ECE 252 / CPS 220 Advanced Computer Architecture I Lecture 14 Virtual Memory Benjamin Lee Electrical and Computer Engineering Duke University
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
February 21, 2012CS152, Spring 2012 CS 152 Computer Architecture and Engineering Lecture 9 - Virtual Memory Krste Asanovic Electrical Engineering and Computer.
Virtual Memory Additional Slides Slide Source: Topics Address translation Accelerating translation with TLBs class12.ppt.
Constructive Computer Architecture Virtual Memory and Interrupts Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 14 CS252 Graduate Computer Architecture Spring 2014 Lecture 14: Memory Protection and Address Translation.
Virtual Memory CENG331 - Computer Organization Instructor: Murat Manguoglu(Section 1) Adapted from:
CENG709 Computer Architecture and Operating Systems Lecture 8 - Address Translation Murat Manguoglu Department of Computer Engineering Middle East Technical.
CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.
Bernhard Boser & Randy Katz
Memory COMPUTER ARCHITECTURE
From Address Translation to Demand Paging
From Address Translation to Demand Paging
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Dr. George Michelogiannakis EECS, University of California at Berkeley
CS 61C: Great Ideas in Computer Architecture Lecture 23: Virtual Memory Krste Asanović & Randy H. Katz 11/12/2018.
Virtual Memory and Interrupts
From Address Translation to Demand Paging
CS 105 “Tour of the Black Holes of Computing!”
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Lecture 8 – Address Translation Krste Asanovic Electrical Engineering.
CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Lecture 9 – Virtual Memory Krste Asanovic Electrical Engineering and.
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CS 105 “Tour of the Black Holes of Computing!”
Address Translation and Virtual Memory CENG331 - Computer Organization
CS 105 “Tour of the Black Holes of Computing!”
Dr. George Michelogiannakis EECS, University of California at Berkeley
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

CSE 490/590 Computer Architecture Virtual Memory II Steve Ko Computer Sciences and Engineering University at Buffalo

Last time… Virtual memory organization Page-table walk TLB Linear page table Hierarchical page table Page-table walk Software or hardware TLB Caches address translations CS252 S05

Virtual Address Caches CPU Physical Cache TLB Primary Memory VA PA Alternative: place the cache before the TLB CPU VA (StrongARM) Virtual Cache PA TLB Primary Memory one-step process in case of a hit (+) cache needs to be flushed on a context switch unless address space identifiers (ASIDs) included in tags (-) aliasing problems due to the sharing of pages (-) maintaining cache coherence (-) (see later in course) CS252 S05

Aliasing in Virtual-Address Caches Page Table Tag Data Page Table VA1 Data Pages VA1 1st Copy of Data at PA PA VA2 2nd Copy of Data at PA VA2 Virtual cache can have two copies of same physical data. Writes to one copy not visible to reads of other! Two virtual pages share one physical page Two processes sharing the same file, Map the same memory segment to different Parts of their address space. General Solution: Disallow aliases to coexist in cache Software (i.e., OS) solution for direct-mapped cache VAs of shared pages must agree in cache index bits; this ensures all VAs accessing same PA will conflict in direct-mapped cache (early SPARCs) CS252 S05

Concurrent Access to TLB & Cache VPN L b TLB Direct-map Cache 2L blocks 2b-byte block PPN Page Offset = hit? Data Physical Tag Tag VA PA Virtual Index k Index L is available without consulting the TLB cache and TLB accesses can begin simultaneously Tag comparison is made after both accesses are completed Cases: L + b = k, L + b < k, L + b > k CS252 S05

Virtual-Index Physical-Tag Caches: Associative Organization VPN a L = k-b b TLB Direct-map 2L blocks PPN Page Offset = hit? Data Phy. Tag VA PA Virtual Index k 2a Consider 4-Kbyte pages and caches with 32-byte blocks 32-Kbyte cache  2a = 8 4-Mbyte cache  2a =1024 No ! After the PPN is known, 2a physical tags are compared How does this scheme scale to larger caches? CS252 S05

Concurrent Access to TLB & Large L1 The problem with L1 > Page size Virtual Index L1 PA cache Direct-map VA VPN a Page Offset b TLB VA1 PPNa Data VA2 PPNa Data PA PPN Page Offset b = hit? Tag Can VA1 and VA2 both map to PA ? CS252 S05

A solution via Second Level Cache CPU L1 Instruction Cache Unified L2 Cache Memory Memory Memory L1 Data Cache RF Memory Usually a common L2 cache backs up both Instruction and Data L1 caches L2 is “inclusive” of both Instruction and Data caches CS252 S05

Anti-Aliasing Using L2: MIPS R10000 Virtual Index L1 PA cache Direct-map VA VPN a Page Offset b into L2 tag VA1 PPNa Data TLB VA2 PPNa Data PA PPN Page Offset b PPN = hit? Tag Suppose VA1 and VA2 both map to PA and VA1 is already in L1, L2 (VA1  VA2) After VA2 is resolved to PA, a collision will be detected in L2. VA1 will be purged from L1 and L2, and VA2 will be loaded  no aliasing ! PA a1 Data Direct-Mapped L2 CS252 S05

Virtually-Addressed L1: Anti-Aliasing using L2 Index & Tag VA VPN Page Offset b VA1 Data TLB VA2 Data PA PPN Page Offset b L1 VA Cache “Virtual Tag” Tag Physical Index & Tag PA VA1 Data Physically-addressed L2 can also be used to avoid aliases in virtually-addressed L1 L2 PA Cache L2 “contains” L1 CS252 S05

Page Fault Handler When the referenced page is not in DRAM: The missing page is located (or created) It is brought in from disk, and page table is updated Another job may be run on the CPU while the first job waits for the requested page to be read from disk If no free pages are left, a page is swapped out Pseudo-LRU replacement policy Since it takes a long time to transfer a page (msecs), page faults are handled completely in software by the OS Untranslated addressing mode is essential to allow kernel to access page tables CS252 S05

Swapping a Page of a Page Table A PTE in primary memory contains primary or secondary memory addresses A PTE in secondary memory contains only secondary memory addresses  a page of a PT can be swapped out only if none its PTE’s point to pages in the primary memory Why?__________________________________ What is the worst thing you can do with respect to storing page tables? Storing page table on disk for whose entries point to phys. Mem. CS252 S05

Virtual Memory Use Today - 1 Desktops/servers have full demand-paged virtual memory Portability between machines with different memory sizes Protection between multiple users or multiple tasks Share small physical memory among active tasks Simplifies implementation of some OS features Vector supercomputers have translation and protection but not demand-paging (Older Crays: base&bound, Japanese & Cray X1/X2: pages) Don’t waste expensive CPU time thrashing to disk (make jobs fit in memory) Mostly run in batch mode (run set of jobs that fits in memory) Difficult to implement restartable vector instructions CS252 S05

Virtual Memory Use Today - 2 Most embedded processors and DSPs provide physical addressing only Can’t afford area/speed/power budget for virtual memory support Often there is no secondary storage to swap to! Programs custom written for particular memory configuration in product Difficult to implement restartable instructions for exposed architectures CS252 S05

CSE 490/590 Administrivia Midterm on Friday, 3/4 Project 1 deadline: Friday, 3/11 Quiz 1 regrading  Jangyoung CSE machines are available for projects Thin clients & SSH only for simulation Linux & Windows machines @ 216 Bell for board

Address Translation in CPU Pipeline PC D E M W Inst TLB Inst. Cache Decode Data TLB Data Cache + TLB miss? Page Fault? Protection violation? TLB miss? Page Fault? Protection violation? Software handlers need restartable exception on page fault or protection violation Handling a TLB miss needs a hardware or software mechanism to refill TLB Need mechanisms to cope with the additional latency of a TLB: slow down the clock pipeline the TLB and cache access virtual address caches parallel TLB/cache access CS252 S05

Address Translation: putting it all together Virtual Address hardware hardware or software software Restart instruction TLB Lookup miss hit Page Table Walk Protection Check the page is Ï memory Î memory denied Need to restart instruction. Soft and hard page faults. permitted Page Fault (OS loads page) Protection Fault Update TLB Physical Address (to cache) SEGFAULT CS252 S05

Translation Lookaside Buffers Address translation is very expensive! In a two-level page table, each reference becomes several memory accesses Solution: Cache translations in TLB TLB hit  Single Cycle Translation TLB miss  Page-Table Walk to refill virtual address VPN offset V R W D tag PPN (VPN = virtual page number) 3 memory references 2 page faults (disk accesses) + .. Actually used in IBM before paged memory. (PPN = physical page number) hit? physical address PPN offset CS252 S05

Linear Page Table Page Table Entry (PTE) contains: Data word Data Pages Page Table Entry (PTE) contains: A bit to indicate if a page exists PPN (physical page number) for a memory-resident page DPN (disk page number) for a page on the disk Status bits for protection and usage OS sets the Page Table Base Register whenever active user process changes Page Table PPN PPN DPN PPN Offset DPN PPN PPN DPN DPN VPN DPN PPN PPN PT Base Register VPN Offset Virtual address CS252 S05

Hierarchical Page Table Virtual Address 31 22 21 12 11 p1 p2 offset 10-bit L1 index 10-bit L2 index offset Root of the Current Page Table p2 p1 Physical Memory (Processor Register) Level 1 Page Table Level 2 Page Tables page in primary memory page in secondary memory PTE of a nonexistent page Data Pages CS252 S05

Hierarchical Page Table Virtual Address 31 22 21 12 11 A program that traverses the page table needs a “no translation” addressing mode. p1 p2 offset 10-bit L1 index 10-bit L2 index offset Root of the Current Page Table p2 p1 (Processor Register) Level 1 Page Table Level 2 Page Tables page in primary memory page in secondary memory PTE of a nonexistent page Data Pages CS252 S05

Acknowledgements These slides heavily contain material developed and copyright by Krste Asanovic (MIT/UCB) David Patterson (UCB) And also by: Arvind (MIT) Joel Emer (Intel/MIT) James Hoe (CMU) John Kubiatowicz (UCB) MIT material derived from course 6.823 UCB material derived from course CS252