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?

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

EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Virtual Memory. The Limits of Physical Addressing CPU Memory A0-A31 D0-D31 “Physical addresses” of memory locations Data All programs share one address.
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.
1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
The Memory Hierarchy (Lectures #24) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer Organization.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
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.
Translation Buffers (TLB’s)
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy (Part II)
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
Lecture 19: Virtual Memory
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
IT253: Computer Organization
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
November 23, A Real Problem  What if you wanted to run a program that needs more memory than you have?
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.
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.
The Memory Hierarchy Lecture 31 20/07/2009Lecture 31_CA&O_Engr. Umbreen Sabir.
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
Lecture 11 Virtual Memory
Memory Management Virtual Memory.
Virtual Memory Chapter 7.4.
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Lecture 12 Virtual Memory.
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Virtual Memory User memory model so far:
CS703 - Advanced Operating Systems
From Address Translation to Demand Paging
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.
Morgan Kaufmann Publishers
CS510 Operating System Foundations
Lecture 28: Virtual Memory-Address Translation
CSCI206 - Computer Organization & Programming
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Virtual Memory 4 classes to go! Today: Virtual Memory.
Translation Lookaside Buffer
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
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.
CS161 – Design and Architecture of Computer
Cache writes and examples
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory 1 1.
Presentation transcript:

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? How do we protect one program’s data from being read or written by another program? multiple programs may want to store something at the same address in particular, consider multiple copies of the same program There are two key ideas used to solve these problems: Treat the disk as an extended source of memory swap programs between disk and memory as required Programs use “fake” or “virtual” memory addresses these translate to “real” addresses, but the translation is hidden to the programmer

Indirection Many problems can be solved by adding a level of indirection a mapping between names and things allows changing the thing without notifying holders of the name Without Indirection With Indirection In the context of memory: Name = virtual address, thing = physical address, translation = page table Name Thing Name Thing

Virtual Memory We translate “virtual addresses” used by the program to “physical addresses” that represent places in the machine’s “physical” memory “translate” denotes a level of indirection Physical Memory A virtual address can be mapped to either physical memory or disk Virtual Address Disk

Virtual Memory Different processes will have different mappings from virtual to physical addresses, so programs A and B can freely use the same virtual address OS allocates distinct physical memory regions to A and B Program A Physical Memory Program B Virtual Address Virtual Address Disk

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 HUGE Hence, we try to minimize the miss rate: VM “pages” are much larger than cache blocks (why?) least significant bits of virtual address form the page offset A fully associative policy is used (why?) Should a write-through or write-back policy be used?

Finding the right page If it is fully associative, how do we find the right page without scanning all of memory? Use a 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

Page Table picture

How big is the page table? From the previous slide: Virtual page number is 20 bits How about for 64-bit addresses?

Dealing with large page tables Multi-level page tables 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 Page Table Base Pointer 2nd 1st 3rd A 3-level page table PPN PPN offset VPN1 VPN2 VPN3 offset

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)… We have too many levels of indirection! How do we deal with too many levels of indirection?

Caching Translations Virtual to Physical translations are cached in a Translation Lookaside Buffer (TLB).

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 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 OS uses a “least recently used” (LRU) strategy The replaced page will need to be written back if dirty

Memory Protection In order to prevent one process from reading/writing another process’ 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 OS runs in kernel mode Only allowing kernel mode to write to the virtual memory state: The page table The page table base pointer The TLB

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 OS will share the code pages between the programs Program A Physical Memory Program B Virtual Address Virtual Address Disk

Summary Virtual memory is great: It means that we don’t have to manage our own memory It allows different programs to use the same memory 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