CDA 5155 Virtual Memory Lecture 27. Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess.

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

1 Lecture 13: Cache and Virtual Memroy Review Cache optimization approaches, cache miss classification, Adapted from UCB CS252 S01.
Virtual Memory. The Limits of Physical Addressing CPU Memory A0-A31 D0-D31 “Physical addresses” of memory locations Data All programs share one address.
16.317: Microprocessor System Design I
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.
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?
The Memory Hierarchy (Lectures #24) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer Organization.
1 Lecture 20: Cache Hierarchies, Virtual Memory Today’s topics:  Cache hierarchies  Virtual memory Reminder:  Assignment 8 will be posted soon (due.
CSCE 212 Chapter 7 Memory Hierarchy Instructor: Jason D. Bakos.
Virtual Memory.
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
Computer ArchitectureFall 2008 © CS : Computer Architecture Lecture 22 Virtual Memory (1) November 6, 2008 Nael Abu-Ghazaleh.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
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.
1 Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Technical University of Lodz Department of Microelectronics and Computer Science Elements of high performance microprocessor architecture Virtual memory.
©UCB CS 162 Ch 7: Virtual Memory LECTURE 13 Instructor: L.N. Bhuyan
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Some VM Complications Extra memory accesses Page tables are huge
Lecture 19: Virtual Memory
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
1  2004 Morgan Kaufmann Publishers Multilevel cache Used to reduce miss penalty to main memory First level designed –to reduce hit time –to be of small.
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
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
3-May-2006cse cache © DW Johnson and University of Washington1 Cache Memory CSE 410, Spring 2006 Computer Systems
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)
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.
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory.
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.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
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.
3/1/2002CSE Virtual Memory Virtual Memory CPU On-chip cache Off-chip cache DRAM memory Disk memory Note: Some of the material in this lecture are.
Memory Management memory hierarchy programs exhibit locality of reference - non-uniform reference patterns temporal locality - a program that references.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Lecture 11 Virtual Memory
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Lecture 12 Virtual Memory.
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?
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Lecture 23: Cache, Memory, Virtual Memory
Lecture 22: Cache Hierarchies, Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Paging and Segmentation
Virtual Memory Lecture notes from MKP and S. Yalamanchili.
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
Virtual Memory 1 1.
Presentation transcript:

CDA 5155 Virtual Memory Lecture 27

Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess

The problem(s) DRAM is too expensive to buy gigabytes –Yet we want our programs to work even if they require more storage than we bought. –We also don ’ t want a program that works on a machine with 128 megabytes to stop working if we try to run it on a machine with only 64 megabytes of memory. We run more than one program on the machine.

Solution 1: User control Leave the problem to the programmer –Assume the programmer knows the exact configuration of the machine. Programmer must either make sure the program fits in memory, or break the program up into pieces that do fit and load each other off the disk when necessary Not a bad solution in some domains –Playstation 2, cell phones, etc.

Solution 2: Overlays A little automation to help the programmer –build the application in overlays Two pieces of code/data may be overlayed iff –They are not active at the same time –They are placed in the same memory region Managing overlays is performed by the compiler –Good compilers may determine overlay regions –Compiler adds code to read the required overlay memory off the disk when necessary

Overlay example Memory Code Overlays

Solution 3: Virtual memory Build new hardware and software that automatically translates each memory reference from a virtual address (that the programmer sees as an array of bytes) to a physical address (that the hardware uses to either index DRAM or identify where the storage resides on disk)

Basics of Virtual Memory Any time you see the word virtual in computer science and architecture it means “ using a level of indirection ” Virtual memory hardware changes the virtual address the programmer sees into the physical ones the memory chips see. 0x800 Virtual address 0x3C00 Physical address Disk ID 803C4

Virtual Memory View Virtual memory lets the programmer “ see ” a memory array larger than the DRAM available on a particular computer system. Virtual memory enables multiple programs to share the physical memory without: –Knowing other programs exist (transparency). –Worrying about one program modifying the data contents of another (protection).

Managing virtual memory Managed by hardware logic and operating system software. –Hardware for speed –Software for flexibility and because disk storage is controlled by the operating system.

Virtual Memory Treat main memory like a cache –Misses go to the disk How do we minimize disk accesses? –Buy lots of memory. –Exploit temporal locality Fully associative? Set associative? Direct mapped? –Exploit spatial locality How big should a block be? –Write-back or write-through?

Virtual memory terminology Blocks are called Pages –A virtual address consists of A virtual page number A page offset field (low order bits of the address) Misses are call Page faults –and they are generally handled as an exception Virtual page numberPage offset 01131

Address Translation Virtual address Physical Disk addresses Address translation page table: contains address translation info of the program.

Page table components Page table register Virtual page numberPage offset 1 Physical page number Page offset valid Physical page number

Page table components Page table register 0x000040x0F3 1 0x020C0 0x0F3 valid Physical page number Physical address = 0x020C00F3

Page table components Page table register 0x000020x082 0Disk address valid Physical page number Exception: page fault 1.Stop this process 2.Pick page to replace 3.Write back data 4.Get referenced page 5.Update page table 6.Reschedule process

How do we find it on disk? That is not a hardware problem! Most operating systems partition the disk into logical devices (C:, D:, /home, etc.) They also have a hidden partition to support the disk portion of virtual memory –Swap partition on UNIX machines –You then index into the correct page in the swap partition.

Size of page table How big is a page table entry? –For MIPS the virtual address is 32 bits If the machine can support 1GB = 2 30 of physical memory and we use pages of size 4KB = 2 12, then the physical page number is = 18 bits. Plus another valid bit + other useful stuff (read only, dirty, etc.) Let say about 3 bytes. How many entries in the page table? –MIPS virtual address is 32 bits – 12 bit page offset = 2 20 or ~1,000,000 entries Total size of page table: 2 20 x 18 bits ~ 3 MB

How can you organize the page table? 1.Continuous 3MB region of physical memory 2.Use a hash function instead of an array Slower, but less memory 3.Page the page table! (Build a hierarchical page table) Super page table in physical memory Second (and maybe third) level page tables in virtual address space. Virtual SuperpageVirtual pagePage offset

Putting it all together Loading your program in memory Ask operating system to create a new process Construct a page table for this process Mark all page table entries as invalid with a pointer to the disk image of the program That is, point to the executable file containing the binary. Run the program and get an immediate page fault on the first instruction.

Page replacement strategies Page table indirection enables a fully associative mapping between virtual and physical pages. How do we implement LRU? –True LRU is expensive, but LRU is a heuristic anyway, so approximating LRU is fine –Reference bit on page, cleared occasionally by operating system. Then pick any “ unreferenced ” page to evict.

Performance of virtual memory To translate a virtual address into a physical address, we must first access the page table in physical memory. Then we access physical memory again to get (or store) the data A load instruction performs at least 2 memory reads A store instruction performs at least 1 read and then a write. Every memory access performs at least one slow access to main memory!

Translation lookaside buffer We fix this performance problem by avoiding main memory in the translation from virtual to physical pages. We buffer the common translations in a Translation lookaside buffer (TLB), a fast cache memory dedicated to storing a small subset of valid VtoP translations.

TLB Virtual page vtagPhysical page Pg offset

Where is the TLB lookup? We put the TLB lookup in the pipeline after the virtual address is calculated and before the memory reference is performed. –This may be before or during the data cache access. –Without a TLB we need to perform the translation during the memory stage of the pipeline.

Other VM translation functions Page data location –Physical memory, disk, uninitialized data Access permissions –Read only pages for instructions Gathering access information –Identifying dirty pages by tracking stores –Identifying accesses to help determine LRU candidate

Placing caches in a VM system VM systems give us two different addresses: virtual and physical Which address should we use to access the data cache? –Virtual address (before VM translation) Faster access? More complex? –Physical address (after VM translations) Delayed access?

Where is the TLB lookup? We put the TLB lookup in the pipeline after the virtual address is calculated and before the memory reference is performed. –This may be before or during the data cache access. –Without a TLB we need to perform the translation during the memory stage of the pipeline.

Placing caches in a VM system VM systems give us two different addresses: virtual and physical Which address should we use to access the data cache? –Virtual address (before VM translation) Faster access? More complex? –Physical address (after VM translations) Delayed access?

Physically addressed caches Perform TLB lookup before cache tag comparison. –Use bits from physical address to index set –Use bits from physical address to compare tag Slower access? –Tag lookup takes place after the TLB lookup. Simplifies some VM management –When switching processes, TLB must be invalidated, but cache OK to stay as is.

Page offsetVirtual page Picture of Physical caches Virtual address Set1 tag Set0 tag Set2 tag Tag cmp Tag cmp Cache tagPPN tagPPN tagPPN tagPPN Page offsetPPN tag index Block offset

Virtually addressed caches Perform the TLB lookup at the same time as the cache tag compare. –Uses bits from the virtual address to index the cache set –Uses bits from the virtual address for tag match. Problems: –Aliasing: Two processes may refer to the same physical location with different virtual addresses. –When switching processes, TLB must be invalidated, and dirty cache blocks must be written back to memory.

Picture of Virtual Caches tagindex Block offset Virtual address Set1 tag Set0 tag Set2 tag Tag cmp Tag cmp TLB is accessed in parallel with cache lookup Physical address is used to access main memory in case of a cache miss.

OS support for Virtual Memory It must be able to modify the page table register, update page table values, etc. –To enable the OS to do this, AND not the user program, we have different execution modes for a process – one which has executive (or supervisor or kernel level) permissions and one that has user level permissions.