Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.

Slides:



Advertisements
Similar presentations
Tutorial 8 March 9, 2012 TA: Europa Shang
Advertisements

CSCC69: Operating Systems
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
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.
Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
CS 153 Design of Operating Systems Spring 2015
Jaishankar Sundararaman
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
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.
CSE378 Virtual memory.1 Evolution in memory management techniques In early days, single program ran on the whole machine –used all the memory available.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Thread Scheduling.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
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.
Chapter 4 Memory Management Virtual Memory.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
Pintos project 3: Virtual Memory Management
Lecture 14 PA2. Lab 2: Demand Paging Implement the following syscalls xmmap, xmunmap, vcreate, vgetmem/vfreemem, srpolicy Deadline: November , 10:00.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
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.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
Jonathan Walpole Computer Science Portland State University
Virtual Memory CSSE 332 Operating Systems
CE 454 Computer Architecture
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
Outline Paging Swapping and demand paging Virtual memory.
Memory Management and Virtual Memory
CSE 153 Design of Operating Systems Winter 2018
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2018
Lecture 28: Virtual Memory-Address Translation
Virtual Memory: Concepts /18-213/14-513/15-513: Introduction to Computer Systems 17th Lecture, October 23, 2018.
O.S Lecture 13 Virtual Memory.
Evolution in Memory Management Techniques
Operating Systems Lecture November 2018.
Memory Management Overview
Virtual Memory Hardware
Translation Lookaside Buffer
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
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 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
Evolution in memory management techniques
CSE 153 Design of Operating Systems Winter 2019
Evolution in memory management techniques
Evolution in memory management techniques
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.
Review What are the advantages/disadvantages of pages versus segments?
Instructor: Phil Gibbons
Presentation transcript:

Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation

Outline  Managing virtual address space  Managing physical memory  Managing swap area 2

Introduction  The OS virtual memory system interacts with paging hardware, physical memory and the disk  It implements three main abstractions for managing these hardware resources o Per-process virtual address space management o Physical memory management o Swap management  These abstractions are used to implement the virtual memory hierarchy 3

Address Space  Recall that the address space is the set of memory addresses that are accessible to a process  OS provides each process its own independent virtual address space o i.e., each process sees contiguous (virtual) memory addresses starting from 0  An address space is broken into regions or segments  Regions hold different kinds of information, e.g., stack, heap, data, text (or code) 4 Virtual address space Page 1 Page 0 Unallocated pages Page 2^ Stack Text Data Heap

Address Space API  The OS must track the address space of each process o All regions within an address space o A page table that holds translations for the address space  The address space API includes: o id = as_create()  Create empty address space, allocate new page table associated with id, with no pages mapped to frames o as_destroy(id)  Destroy address space id  Free page table associated with id o as_define_region(id, …)  Add a new region to an address space 5

Address Space API o as_modify_region(id, …)  Change the size of a region  This will be needed to implement heap and stack regions o as_find_region(id, vaddr)  Find a region, given a virtual address o as_load_page(id, …)  Load a page in memory from file (demand paging) o new_id = as_copy(id)  Create a full copy of the address space and the page table with same mappings o as_switch(id)  Switch the address space to id. Mappings in the TLB from the previous address space must be removed. 6

Managing Physical Memory  The OS needs to manage physical memory frames  A coremap allows tracking usage of frames  Coremap implementation uses an array of structures, one per frame  Each struct tracks o Whether a frame is allocated or free (similar to bitmap) o For allocated frame, it tracks one (or more) address spaces and pages that map to the frame  Helps implement swapping of pages to disk and shared pages 7

Coremap API  frame = allocate_frame(n) o Allocate n free contiguous memory frames, returns physical address of first frame  free_frame(frame) o Free the block of frames, starting at frame  map(id, page_nr, frame) o Maps frame to virtual address (page_nr) in address space id o May need to allocate page table entry o Note that a frame may be mapped to multiple pages in the same or in different address spaces (these are called shared pages)  unmap(id, page_nr) o Removes frame corresponding to page_nr from address space  evict(frame) o Used by swap handler to unmap all pages associated with frame 8

Managing Swap Area  Dirty pages need to be placed in swap  Use technique similar to managing memory o Use a bitmap or linked list of “swap frames”  When evicting a page to swap o Find a free swap frame o Write the page to this location on the disk o Can use invalid PTE to note the location of the swap frame  On page fault, handler uses PTE to locate frame in swap area o Next time page is swapped out, it may be written elsewhere o What happens when a shared frame is loaded from swap? 9

Managing Swap Area frame number (PFN)unusedDCW1R 0131 Index in swap area (non-zero) All zeroes0 Page Table Entry (PTE) when virtual page is in memory Invalid PTE (never allocated) PTE when virtual page is on swap

Summary  The virtual memory system of an OS is complicated because it interacts with paging hardware, physical memory and the disk  It implements three main abstractions for managing these hardware resources o Per-process virtual address space  e.g., create address space, create VM region, load page o Physical memory management  e.g., allocate/deallocate frames, map frame to page, evict frame o Swap management  e.g., allocate/deallocate swap page  OS implements the virtual memory hierarchy with these abstractions 11

Think Time  How is managing swap similar to managing memory? 12