November 23, 20151 A Real Problem  What if you wanted to run a program that needs more memory than you have?

Slides:



Advertisements
Similar presentations
Virtual Memory In this lecture, slides from lecture 16 from the course Computer Architecture ECE 201 by Professor Mike Schulte are used with permission.
Advertisements

Virtual Memory. The Limits of Physical Addressing CPU Memory A0-A31 D0-D31 “Physical addresses” of memory locations Data All programs share one address.
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
May 7, A Real Problem  What if you wanted to run a program that needs more memory than you have?
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.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - III Lecturer: Hui Wu Session 2, 2005 Modified.
CSE 490/590, Spring 2011 CSE 490/590 Computer Architecture Virtual Memory I Steve Ko Computer Sciences and Engineering University at Buffalo.
The Memory Hierarchy (Lectures #24) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer Organization.
Computer ArchitectureFall 2008 © CS : Computer Architecture Lecture 22 Virtual Memory (1) November 6, 2008 Nael Abu-Ghazaleh.
Computer ArchitectureFall 2008 © November 10, 2007 Nael Abu-Ghazaleh Lecture 23 Virtual.
Review CPSC 321 Andreas Klappenecker Announcements Tuesday, November 30, midterm exam.
Translation Buffers (TLB’s)
Mem. Hier. CSE 471 Aut 011 Evolution in Memory Management Techniques In early days, single program run on the whole machine –Used all the memory available.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy (Part II)
11/10/2005Comp 120 Fall November 10 8 classes to go! questions to me –Topics you would like covered –Things you don’t understand –Suggestions.
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Lecture 19: Virtual Memory
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui COMP 203 / NWEN 201 Computer Organisation / Computer Architectures Virtual.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
Virtual Memory Part 1 Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology May 2, 2012L22-1
1 Virtual Memory Main memory can act as a cache for the secondary storage (disk) Advantages: –illusion of having more physical memory –program relocation.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
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?
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Multilevel Caches Microprocessors are getting faster and including a small high speed cache on the same chip.
1 Chapter Seven CACHE MEMORY AND VIRTUAL MEMORY. 2 SRAM: –value is stored on a pair of inverting gates –very fast but takes up more space than DRAM (4.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
LECTURE 12 Virtual Memory. VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a “cache”
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
CS203 – Advanced Computer Architecture Virtual Memory.
CDA 5155 Virtual Memory Lecture 27. Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Virtual Memory Chapter 7.4.
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
CS 704 Advanced Computer Architecture
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.
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?
Morgan Kaufmann Publishers
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
From Address Translation to Demand Paging
Evolution in Memory Management Techniques
Virtual Memory 4 classes to go! Today: Virtual Memory.
Lecture 23: Cache, Memory, Virtual Memory
Lecture 22: Cache Hierarchies, Memory
Translation Lookaside Buffer
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Paging and Segmentation
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
Translation Buffers (TLBs)
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.
Cache writes and examples
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

November 23, A Real Problem  What if you wanted to run a program that needs more memory than you have?

November 23, 2015©2003 Craig Zilles2 Virtual Memory (and Indirection)  Finally, we get to Virtual Memory! —We’ll talk about the motivations for virtual memory —We’ll talk about how it is implemented —Lastly, we’ll talk about how to make virtual memory fast: Translation Lookaside Buffers (TLBs).  Starting Friday, we’ll turn our attention to peripheral devices and I/O.

November 23, 2015Virtual Memory3 A Real Problem  What if you wanted to run a program that needs more memory than you have? —You could store the whole program on disk, and use memory as a cache for the data on disk. This is one feature of virtual memory. —Before virtual memory, programmers had to manually manage loading “overlays” (chunks of instructions & data) off disk before they were used. This is an incredibly tedious, not to mention error- prone, process.

November 23, 2015Virtual Memory4 More Real Problems  Running multiple programs at the same time brings up more problems. 1.Even if each program fits in memory, running 10 programs might not. 2.Multiple programs may want to store something at the same address. 3.How do we protect one program’s data from being read or written by another program?

November 23, 2015Virtual Memory5 More Real Problems  Running multiple programs at the same time brings up more problems. 1.Even if each program fits in memory, running 10 programs might not. – This is really the same problem as on the previous slide. 2.Multiple programs may want to store something at the same address. – I.e., what if both Program A and B want to use address 0x as the base of their stack? – It is impractical (if not impossible) to compile every pair of programs that could get executed together to use distinct sets of addresses. 3.How do we protect one program’s data from being read or written by another program?

November 23, 2015Virtual Memory6 Indirection  “Any problem in CS can be solved by adding a level of indirection”  Without Indirection  With Indirection Name Thing Name Thing

November 23, 2015Virtual Memory7 Indirection  Indirection: Indirection is the ability to reference something using a name, reference, or container instead the value itself. A flexible mapping between a name and a thing allows changing the thing without notifying holders of the name.  Without Indirection  With Indirection  Examples: Pointers, Domain Name Service (DNS) name->IP address, phone system (e.g., cell phone number portability), snail mail (e.g., mail forwarding), 911 (routed to local office), DHCP, color maps, call centers that route calls to available operators, etc. Name Thing Name Thing

November 23, 2015Virtual Memory8  We translate “virtual addresses” used by the program to “physical addresses” that represent places in the machine’s “physical” memory. —The word “translate” denotes a level of indirection Virtual Address Physical Memory Disk A virtual address can be mapped to either physical memory or disk.

November 23, 2015Virtual Memory9  Because different processes will have different mappings from virtual to physical addresses, two programs can freely use the same virtual address.  By allocating distinct regions of physical memory to A and B, they are prevented from reading/writing each others data. Virtual Address Physical Memory Disk Virtual Address Program A Program B

November 23, 2015Virtual Memory10 Caching revisited  Once the translation infrastructure is in place, the problem boils down to caching. —We want the size of disk, but the performance of memory.  The design of virtual memory systems is really motivated by the high cost of accessing disk. —While memory latency is ~100 times that of cache, disk latency is ~100,000 times that of memory. i.e., the miss penalty is a real whopper.  Hence, we try to minimize the miss rate: —VM “pages” are much larger than cache blocks. Why? —A fully associative policy is used. With approximate LRU  Should a write-through or write-back policy be used?

November 23, 2015Virtual Memory11 Finding the right page  If it is fully associative, how do we find the right page without scanning all of memory?

November 23, 2015Virtual Memory12 Finding the right page  If it is fully associative, how do we find the right page without scanning all of memory? —Use an index, just like you would for a book.  Our index happens to be called the page table: —Each process has a separate page table A “page table register” points to the current process’s page table —The page table is indexed with the virtual page number (VPN) The VPN is all of the bits that aren’t part of the page offset. —Each entry contains a valid bit, and a physical page number (PPN) The PPN is concatenated with the page offset to get the physical address —No tag is needed because the index is the full VPN.

November 23, 2015Virtual Memory13 Page Table picture

November 23, 2015Virtual Memory14 How big is the page table?  From the previous slide: —Virtual page number is 20 bits. —Physical page number is 18 bits + valid bit -> round up to 32 bits.  How about for a 64b architecture?

November 23, 2015Virtual Memory15 Dealing with large page tables  Multi-level page tables —“Any problem in CS can be solved by adding a level of indirection”  or two…  Since most processes don’t use the whole address space, you don’t allocate the tables that aren’t needed —Also, the 2nd and 3rd level page tables can be “paged” to disk. VPN1VPN2VPN3offset Page Table Base Pointer PPN offset 1st 2nd 3rd A 3-level page table

April 28, 2003Cache writes and examples16

November 23, 2015Virtual Memory17 Waitaminute!  We’ve just replaced every memory access MEM[addr] with: MEM[MEM[MEM[MEM[PTBR + VPN1<<2] + VPN2<<2] + VPN3<<2] + offset] —i.e., 4 memory accesses  And we haven’t talked about the bad case yet (i.e., page faults)… “Any problem in CS can be solved by adding a level of indirection” —except too many levels of indirection…  How do we deal with too many levels of indirection?

November 23, 2015Virtual Memory18 Caching Translations  Virtual to Physical translations are cached in a Translation Lookaside Buffer (TLB).

November 23, 2015Virtual Memory19 What about a TLB miss?  If we miss in the TLB, we need to “walk the page table” —In MIPS, an exception is raised and software fills the TLB MIPS has “TLB_write” instructions —In x86, a “hardware page table walker” fills the TLB  What if the page is not in memory? —This situation is called a page fault. —The operating system will have to request the page from disk. —It will need to select a page to replace. The O/S tries to approximate LRU (see CS241/CS423) —The replaced page will need to be written back if dirty.

20 Putting it all together  Add arrows to indicate what happens on a lw virtual address data physical address TLB page table memory cache disk page offset virtual page number (VPN) PPN tag index block offset

21 Putting it all together  Add arrows to indicate what happens on a lw virtual address data physical address TLB page table memory cache disk page offset virtual page number (VPN) PPN tag index block offset

22 Putting it all together  Add arrows to indicate what happens on a lw virtual address data physical address TLB page table memory cache disk page offset virtual page number (VPN) PPN tag index block offset

Virtual Memory & Prefetching  Don’t want to cause page faults by prefetching  Prefetches typically dropped when they miss in the TLB —Don’t want to disrupt program’s execution for a prefetch. —May cause a hardware TLB fill on x86 platforms.  HW prefetchers don’t cross page boundaries. —They use physical addresses Don’t use the TLB. —After page boundary don’t know where next page lies —Sequential stream will have a few beginning of each page April 28, 2003Cache writes and examples23

November 23, 2015Virtual Memory24 Memory Protection  In order to prevent one process from reading/writing another process’s memory, we must ensure that a process cannot change its virtual-to- physical translations.  Typically, this is done by: —Having two processor modes: user & kernel. Only the O/S runs in kernel mode —Only allowing kernel mode to write to the virtual memory state, e.g., The page table The page table base pointer The TLB

November 23, 2015Virtual Memory25 Sharing Memory  Paged virtual memory enables sharing at the granularity of a page, by allowing two page tables to point to the same physical addresses.  For example, if you run two copies of a program, the O/S will share the code pages between the programs. Virtual Address Physical Memory Disk Virtual Address Program A Program B

November 23, 2015Virtual Memory26 Summary  Virtual memory is pure manna from heaven: —It means that we don’t have to manage our own memory. —It allows different programs to use the same (virtual) addresses. —It provides protect between different processes. —It allows controlled sharing between processes (albeit somewhat inflexibly).  The key technique is indirection: —Yet another classic CS trick you’ve seen in this class. —Many problems can be solved with indirection.  Caching made a few cameo appearances, too: —Virtual memory enables using physical memory as a cache for disk. —We used caching (in the form of the Translation Lookaside Buffer) to make Virtual Memory’s indirection fast.