COS 318: Operating Systems Virtual Memory and Its Address Translations.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Tore Larsen Material developed by: Kai Li, Princeton University
Memory Management: Overlays and Virtual Memory
Virtual Memory Chapter 18 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer,  S. Dandamudi.
CS 153 Design of Operating Systems Spring 2015
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Virtual Memory & Address Translation Vivek Pai Princeton University.
Virtual Memory & Address Translation Vivek Pai Princeton University.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Chapter 3.2 : Virtual Memory
Translation Buffers (TLB’s)
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
Computer Organization and Architecture
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Review of Memory Management, Virtual Memory CS448.
Operating Systems Chapter 8
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
Topics covered: Memory subsystem CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Computer Architecture Lecture 28 Fasih ur Rehman.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Lecture 19: Virtual Memory
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Operating Systems COMP 4850/CISG 5550 Page Tables TLBs Inverted Page Tables Dr. James Money.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory 1 1.
1 Memory Management. 2 Fixed Partitions Legend Free Space 0k 4k 16k 64k 128k Internal fragmentation (cannot be reallocated) Divide memory into n (possible.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Address Translation Tore Larsen Material developed by: Kai Li, Princeton University.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Memory management Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
CS203 – Advanced Computer Architecture Virtual Memory.
CDA 5155 Virtual Memory Lecture 27. Memory Hierarchy Cache (SRAM) Main Memory (DRAM) Disk Storage (Magnetic media) CostLatencyAccess.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
W4118 Operating Systems Instructor: Junfeng Yang.
Memory: Page Table Structure CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
CS161 – Design and Architecture of Computer
Memory: Page Table Structure
Translation Lookaside Buffer
Memory.
Non Contiguous Memory Allocation
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
From Address Translation to Demand Paging
From Address Translation to Demand Paging
Virtual Memory, Address-Translation and Paging
Chapter 8: Main Memory.
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Evolution in Memory Management Techniques
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 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
CS703 - Advanced Operating Systems
Translation Buffers (TLBs)
Review What are the advantages/disadvantages of pages versus segments?
Virtual Memory 1 1.
Presentation transcript:

COS 318: Operating Systems Virtual Memory and Its Address Translations

2 Today’s Topics  Virtual Memory Virtualization Protection  Address Translation Base and bound Segmentation Paging Translation look-ahead buffer

3 The Big Picture  DRAM is fast, but relatively expensive $25/GB 20-30ns latency 10-80GB’s/sec  Disk is inexpensive, but slow $0.2-1/GB (100 less expensive) 5-10ms latency (200K-400K times slower) 40-80MB/sec per disk (1,000 times less)  Our goals Run programs as efficiently as possible Make the system as safe as possible CPU Memory Disk

4 Issues  Many processes The more processes a system can handle, the better  Address space size Many small processes whose total size may exceed memory Even one process may exceed the physical memory size  Protection A user process should not crash the system A user process should not do bad things to other processes

5 Consider A Simple System  Only physical memory Applications use physical memory directly  Run three processes emacs, pine, gcc  What if gcc has an address error? emacs writes at x7050? pine needs to expand? emacs needs more memory than is on the machine? OS pine emacs gcc Free x0000 x2500 x5000 x7000 x9000

6 Protection Issue  Errors in one process should not affect others  For each process, check each load and store instruction to allow only legal memory references CPU Check Physical memory address error data gcc

7 Expansion or Transparency Issue  A process should be able to run regardless of its physical location or the physical memory size  Give each process a large, static “fake” address space  As a process runs, relocate each load and store to its actual memory CPU Check & relocate Physical memory address data pine

8 Virtual Memory  Flexible Processes can move in memory as they execute, partially in memory and partially on disk  Simple Make applications very simple in terms of memory accesses  Efficient 20/80 rule: 20% of memory gets 80% of references Keep the 20% in physical memory  Design issues How is protection enforced? How are processes relocated? How is memory partitioned?

9 Address Mapping and Granularity  Must have some “mapping” mechanism Virtual addresses map to DRAM physical addresses or disk addresses  Mapping must have some granularity Granularity determines flexibility Finer granularity requires more mapping information  Extremes Any byte to any byte: mapping equals program size Map whole segments: larger segments problematic

10 Generic Address Translation  Memory Management Unit (MMU) translates virtual address into physical address for each load and store  Software (privileged) controls the translation  CPU view Virtual addresses  Each process has its own memory space [0, high] Address space  Memory or I/O device view Physical addresses CPU MMU Physical memory I/O device Virtual address Physical address

11 Goals of Translation  Implicit translation for each memory reference  A hit should be very fast  Trigger an exception on a miss  Protected from user’s faults Registers L1 Memory Disk 2-3x x 20M-30Mx Paging L2-L x

12 Base and Bound  Built in Cray-1  Each process has a pair (base, bound)  Protection A process can only access physical memory in [base, base+bound]  On a context switch Save/restore base, bound registers  Pros Simple Flat and no paging  Cons Arithmetic expensive Hard to share Fragmentation virtual address base bound error + > physical address

13 Segmentation  Each process has a table of (seg, size)  Treats (seg, size) as a fine- grained (base, bound)  Protection Each entry has (nil, read, write, exec)  On a context switch Save/restore the table and a pointer to the table in kernel memory  Pros Efficient Easy to share  Cons Complex management Fragmentation within a segment physical address + segmentoffset Virtual address segsize > error

14 Paging  Use a fixed size unit called page instead of segment  Use a page table to translate  Various bits in each entry  Context switch Similar to the segmentation  What should be the page size?  Pros Simple allocation Easy to share  Cons Big table How to deal with holes? VPage #offset Virtual address > error PPage#... PPage#... PPage #offset Physical address Page table page table size

15 How Many PTEs Do We Need?  Assume 4KB page Offset is low order 12 bits of VE for byte offset (0,4095) Page IDis high-order 20 bits  Worst case for 32-bit address machine 2 20 maximum PTE’s At least 4 bytes per PTE 2 20 PTEs per page table per process (> 4MB), but there might be 10K processes. They won’t fit in memory together  What about 64-bit address machine? 2 52 possible pages 2 52 * 8 bytes = 36 PBytes A page table cannot fit in a disk Let alone when each process has own page table

16 Multiple-Level Page Tables Directory pte dirtableoffset Virtual address What does this buy us?

17 Inverted Page Tables  Main idea One PTE for each physical page frame Optimization: Hash (Vpage, pid) to Ppage #  Pros Small page table for large address space  Cons Lookup is difficult Overhead of managing hash chains, etc pidvpageoffset pidvpage 0 k n-1 koffset Virtual address Physical address Inverted page table

Comparison 18 ConsiderationPagingSegmentation Programmer aware of technique? NoYes How many linear address spaces? 1Many Total address space exceed physical memory? Yes Procedures and data distinguished and protected separately? NoYes Easily accommodate tables whose size fluctuates? NoYes Facilitates sharing of procedures between users? NoYes Why was technique invented? Large linear address space without more physical memory To break programs and data into logical independent address spaces and to aid sharing and protection

19 Segmentation with Paging (MULTICS, Intel Pentium) VPage #offset Virtual address > PPage#... PPage#... PPage #offset Physical address Page table segsize Vseg # error

20 Virtual-To-Physical Lookups  Programs only know virtual addresses Each program or process starts from 0 to high address  Each virtual address must be translated May involve walking through the hierarchical page table Since the page table stored in memory, a program memory access may requires several actual memory accesses  Solution Cache “active” part of page table in a very fast memory

21 Translation Look-aside Buffer (TLB) offset Virtual address PPage#... PPage#... PPage#... PPage #offset Physical address VPage # TLB Hit Miss Real page table VPage#

22 Bits in a TLB Entry  Common (necessary) bits Virtual page number: match with the virtual address Physical page number: translated address Valid Access bits: kernel and user (nil, read, write)  Optional (useful) bits Process tag Reference Modify Cacheable

23 Hardware-Controlled TLB  On a TLB miss Hardware loads the PTE into the TLB Write back and replace an entry if there is no free entry Always? Generate a fault if the page containing the PTE is invalid VM software performs fault handling Restart the CPU  On a TLB hit, hardware checks the valid bit If valid, pointer to page frame in memory If invalid, the hardware generates a page fault Perform page fault handling Restart the faulting instruction

24 Software-Controlled TLB  On a miss in TLB Write back if there is no free entry Check if the page containing the PTE is in memory If not, perform page fault handling Load the PTE into the TLB Restart the faulting instruction  On a hit in TLB, the hardware checks valid bit If valid, pointer to page frame in memory If invalid, the hardware generates a page fault Perform page fault handling Restart the faulting instruction

25 Hardware vs. Software Controlled  Hardware approach Efficient Inflexible Need more space for page table  Software approach More expensive Flexible Software can do mappings by hashing PP#  (Pid, VP#) (Pid, VP#)  PP# Can deal with large virtual address space

26 Cache vs. TLB  Similarities Cache a portion of memory Write back on a miss  Differences Associativity Consistency Vpage #offset TLB ppage #offset Memory Hit Miss Cache Address Data Hit Memory Miss

27 TLB Related Issues  What TLB entry to be replaced? Random Pseudo LRU Why not “exact” LRU?  What happens on a context switch? Process tag: change TLB registers and process register No process tag: Invalidate the entire TLB contents  What happens when changing a page table entry? Change the entry in memory Invalidate the TLB entry

28 Consistency Issues  “Snoopy” cache protocols (hardware) Maintain consistency with DRAM, even when DMA happens  Consistency between DRAM and TLBs (software) You need to flush related TLBs whenever changing a page table entry in memory  TLB “shoot-down” On multiprocessors, when you modify a page table entry, you need to flush all related TLB entries on all processors, why?

29 Summary  Virtual Memory Virtualization makes software development easier and enables memory resource utilization better Separate address spaces provide protection and isolate faults  Address translation Base and bound: very simple but limited Segmentation: useful but complex  Paging TLB: fast translation for paging VM needs to take care of TLB consistency issues