EECE476: Computer Architecture Lecture 27: Virtual Memory, TLBs, and Caches Chapter 7 The University of British ColumbiaEECE 476© 2005 Guy Lemieux.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

CSIE30300 Computer Architecture Unit 10: Virtual Memory Hsin-Chou Chi [Adapted from material by and
Virtual Memory Hardware Support
COMP 3221: Microprocessors and Embedded Systems Lectures 27: Virtual Memory - III Lecturer: Hui Wu Session 2, 2005 Modified.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
S.1 Review: The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of.
Recap. The Memory Hierarchy Increasing distance from the processor in access time L1$ L2$ Main Memory Secondary Memory Processor (Relative) size of the.
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Memory Management.
Memory Management 2010.
ECE 232 L27.Virtual.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 27 Virtual.
Chapter 3.2 : Virtual Memory
Translation Buffers (TLB’s)
CS 333 Introduction to Operating Systems Class 9 - Memory Management
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Lecture 21 Last lecture Today’s lecture Cache Memory Virtual memory
CS333 Intro to Operating Systems Jonathan Walpole.
Some VM Complications Extra memory accesses Page tables are huge
CSE431 L22 TLBs.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 22. Virtual Memory Hardware Support Mary Jane Irwin (
Cosc 2150: Computer Organization Chapter 6, Part 2 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.
IT253: Computer Organization
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-8 Memory Management (2) Department of Computer Science and Software.
Fall 2000M.B. Ibáñez Lecture 17 Paging Hardware Support.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Paging Paging is a memory-management scheme that permits the physical-address space of a process to be noncontiguous. Paging avoids the considerable problem.
1  2004 Morgan Kaufmann Publishers Chapter Seven Memory Hierarchy-3 by Patterson.
CS.305 Computer Architecture Memory: Virtual Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.
Lab4: Virtual Memory CS 3410 : Computer System Organization & Programming Spring 2015.
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
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)
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
CS203 – Advanced Computer Architecture Virtual Memory.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 33 Paging Read Ch. 9.4.
CS161 – Design and Architecture of Computer
Non Contiguous Memory Allocation
ECE232: Hardware Organization and Design
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
Virtual Memory - Part II
CS703 - Advanced Operating Systems
CS510 Operating System Foundations
Chapter 8: Main Memory.
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
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
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
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
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
Presentation transcript:

EECE476: Computer Architecture Lecture 27: Virtual Memory, TLBs, and Caches Chapter 7 The University of British ColumbiaEECE 476© 2005 Guy Lemieux

2 Multitasking Most OS’s multitask –Run Program A and B at the same time Most CPUs must support multitasking –Not run at exactly the same time: Run Program A for 20ms Run Program B for 20ms Run Program A for 20ms, etc

3 Programs Sharing Memory Computer has 128MB –Netscape uses 60MB –Word uses 35MB –Windows uses 45MB –Total: 140MB How to run all 3? It gets worse…. –Netscape assumes memory starts at address 0 –Word assumes memory starts at address 0 How can they both run if they both assume memory starts at 0 ?? –Windows ? It’s the OS…. who knows!

4 Programs Sharing Memory It gets even worse –Windows starts using 45MB –Netscape starts using 16MB –Word starts using 20MB –User opens web page, Netscape wants +32MB –User opens document, Word wants +10MB –User opens 2 nd web page, Netscape wants +12MB –User edits document, Word wants +5MB –TOTAL Windows 45MB, Netscape 60MB, Word 35MB Main Mem Win Net Word Net Word

5 Programs Sharing Memory It gets even worse –Exit Word –Start Engineering program Wants 30MB for a matrix Must be contiguous! How? Move Netscape? Not realistic Solution? –Divide Main Memory into pages, say 4KB each –Divide Programs into pages (same size) –Map Program Pages into Main Memory Pages –Store extra Program Pages on disk Main Mem Win Net

6 Solution: Virtual Memory Physical addresses Disk addresses Virtual addresses Address translation Net Netscape sees thisMain Memory sees this Can store some on disk! Pages Fragmented: Non-contiguous (holes), out-of-order, some on disk

7 Address Translation Page offsetVirtual page number Virtual address Page offsetPhysical page number Physical address Translation Table Lookup Page Size: 2^12 = 4096 bytes

8 Virtual Memory Program Viewpoint –Addresses start at 0 –Malloc() gives program contiguous memory (consective addresses) –Malloc(), Free(), Malloc(), Free() Can malloc() re-use parts that are freed? Causes internal fragmentation within one program –There is lots of free memory available CPU/OS Viewpoint –Keep all programs separate Don’t all start at 0 Security implications…. programs should not read each other’s data! –Dynamic program behaviour cause memory fragmentation Starting & ending programs, swapping to disk Causes external fragmentation between programs –Limited memory available Use Disk to hold extra data Use Main Memory like a cache for the program data stored on disk New structure: Page Table

9 Page Table: Big Lookup Table Disk addresses Net Netscape sees thisMain Memory sees this Fragmented: Non-contiguous (holes), out-of-order, some on disk Page Table Virtual Addresses Physical Addresses Address Translation

10 Page Table Holds virtual-to-physical address translations Access like a memory –Input: Virtual Address Only need Virtual PageNumber portion (upper bits) Lower bits are PageOffset, ie which byte inside the page –Output: Physical Address Lookup gives a Physical PageNumber Combine with PageOffset to form entire Physical Address Where to hold the PageTable for a program? –Dedicated memory inside CPU? Too big! not done! –Instead, store it in main memory

11 Page Table Translation Structure Size of Page Table? 2^20 or ~1 million entries 1 Page Table Per Program! Page Table Register Virtual Address Page OffsetVirtual Page Number Physical Page Number Physical Address Physical Page NumberPage Offset Page Table Valid If 0 then page is on disk

12 Page Table Implications CPU executes “Load” instruction –Recall: address is now a Virtual Address –First step: Lookup address translation Where is page table? In main memory Special CPU register called Page Table Register (PTR) –Holds starting address of page table Read DataMem from PTR+PageNumber to get Physical Address –Second step: Access the data Read DataMem from Physical Address Every load/store requires TWO memory accesses –Slow! –Can we speed up the translation step? Yes, use a cache!

13 TLB: Translation Looksaside Buffer (A special cache for the Page Table) Virtual page number TLB Page Table Tag Physical Page Number V V Physical Page Number or Disk Address Physical Memory Disk

14 Memory Access: TLB Usage Algorithm NOTICE: exception (interrupt) on miss, software (OS) handles TLB misses, not hardware NOTICE: software designates some memory pages as READ-ONLY Example: pages holding instructions. It will may share some read-only pages with multiple programs, eg you run Netscape twice.

15 TLB Notes TLB Miss –Not handled by hardware –CPU raises exception (interrupt) –OS must fix, because it may have to get data from the disk –OS handles security issues as well Read-only pages –Can share non-sensitive data, eg instructions and pre-compiled data tables in a program such as Netscape –Writes to read-only pages cause exception –OS handles, possible outcomes: Illegal to write to this page Change page to writable If page is shared, make a new writable copy of this page for this program only. Remaining program share the original read-only copy.

16 Combined TLB & Cache Structure 1. TLB lookup 3. Access data cache 2. Convert VA to PA NOTE: TLB is now slowing our cache!!

17 TLB first, Cache second ? TLB first, Cache second strategy is slow –Called Physically Indexed, Physically Tagged To improve performance: –Lookup TLB, Lookup Cache at same time –Must use Virtual Address to lookup in cache –Compare Physical Address (output of TLB) to TAG (output of cache) when checking cache hit –If OK, we can use the data –Called Virtually Indexed, Physically Tagged