Pintos Virtual Memory

Similar documents
CS140 Project 3: Virtual Memory. TA: Diveesh Singh

LAB3: VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Project 2! CSE 421/521 - Operating Systems! Virtual Memory in Pintos

Project 3: Virtual Memory

Pintos Project 3 Virtual Memory. October 26, 2016

Project 4: Virtual Memory

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

PROCESS VIRTUAL MEMORY PART 2. CS124 Operating Systems Winter , Lecture 19

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

CS 153 Design of Operating Systems Winter 2016

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

Address spaces and memory management

CSE 120 Principles of Operating Systems

Chapter 3 - Memory Management

Lecture 19: File System Implementation. Mythili Vutukuru IIT Bombay

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

EECS 482 Introduction to Operating Systems

CSE 120 Principles of Operating Systems Spring 2017

Chapter 6: Demand Paging

Virtual Memory Management

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Caching and Demand-Paged Virtual Memory

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

CIS Operating Systems Memory Management Page Replacement. Professor Qiang Zeng Spring 2018

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory Management: Virtual Memory and Paging CS 111. Operating Systems Peter Reiher

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Chapter 9: Virtual Memory

CS 318 Principles of Operating Systems

OPERATING SYSTEM. Chapter 9: Virtual Memory

Managing Storage: Above the Hardware

CS399 New Beginnings. Jonathan Walpole

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

UC Berkeley CS61C : Machine Structures

MODERN OPERATING SYSTEMS. Chapter 3 Memory Management

Lecture 14 Page Replacement Policies

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

CIS Operating Systems Memory Management Cache Replacement & Review. Professor Qiang Zeng Fall 2017

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I)

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Virtual Memory 1. Virtual Memory

Virtual Memory 1. Virtual Memory

Basic Memory Management

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory

CSE 153 Design of Operating Systems

Lecture 14: Cache & Virtual Memory

Virtual Memory, Address Translation

Recap: Memory Management

EECS 482 Introduction to Operating Systems

Lecture 17. Edited from slides for Operating System Concepts by Silberschatz, Galvin, Gagne

This is a closed-book exam. You may use two double-sided 8.5x11 sheets of notes.

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

CS370 Operating Systems

Virtual Memory. Computer Systems Principles

Protection. - Programmers typically assume machine has enough memory - Sum of sizes of all processes often greater than physical memory 1 / 36

Faculty of Computer Science Institute for System Architecture, Operating Systems Group. Memory. Björn Döbel. Dresden,

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Lecture#16: VM, thrashing, Replacement, Cache state

Intel P The course that gives CMU its Zip! P6/Linux Memory System November 1, P6 memory system. Review of abbreviations

Section 7: Wait/Exit, Address Translation

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 25

CS420: Operating Systems

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

CS510 Operating System Foundations. Jonathan Walpole

Page Which had internal designation P5

Memory management, part 2: outline

CS370 Operating Systems

Administrivia. Lab 1 due Friday 12pm. We give will give short extensions to groups that run into trouble. But us:

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Chapter 8: Virtual Memory. Operating System Concepts

Roadmap. Handling large amount of data efficiently. Stable storage. Parallel dataflow. External memory algorithms and data structures

Opera&ng Systems ECE344

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Pentium/Linux Memory System March 17, 2005

Intel P6 (Bob Colwell s Chip, CMU Alumni) The course that gives CMU its Zip! Memory System Case Studies November 7, 2007.

Virtual Memory, Address Translation

Paging and Page Replacement Algorithms

CIS Operating Systems Memory Management Cache and Demand Paging. Professor Qiang Zeng Spring 2018

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

How to create a process? What does process look like?

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

CIS Operating Systems Memory Management Cache. Professor Qiang Zeng Fall 2017

Changelog. Virtual Memory (2) exercise: 64-bit system. exercise: 64-bit system

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

CS370 Operating Systems

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

Transcription:

Pintos Virtual Memory Daniel Chiu Slides adapted from previous quarters

Overview: Project Components High Level Goal: Implement Virtual Memory Page Table Management Page Fault Handler Interacts with most of the rest of the system Eviction Policy Approximation of LRU (e.g. clock algorithm ) Swap Disk Management Page{in,out} evicted pages Stack Growth Memory Mapped Files (including lazy loading executables)

First: Memory Layout All user virtual addresses have corresponding kernel virtual addresses The hardware page table (discussed in lecture) allows the MMU to map addresses automatically You will need to keep around additional information e.g. keep track of where to fetch pages that aren t in memory Explained in a few more slides

Pintos Page Tables Base implementation already creates basic page directory & page table structure mappings. (Look at paging_init() in init.c) e.g. user wants a new upage at vaddr: palloc_get_page(pal_user) returns a page Register with pagedir_set_page() Layout is very similar to the one discussed in lecture, except: Only two levels of page tables 4 byte page table entries Note that hardware bits (present, writable, user, accessed, dirty) are PER PAGE TABLE ENTRY, not per physical frame!

Handling Virtual Memory Page Fault Handler Verify that the access is legal (read/write) If page has been evicted, load from disk/swap Else, trigger stack growth if necessary Paging something in might require paging something else out Beware of race conditions while accessing data structures You may need to pin pages to prevent them from being evicted Don t pin for too long, but Don t worry about running out of pages to pin (you can panic the kernel) Global Data Structure: Frame Table Keeps track of the physical frames that are allocated/free Per-Process Data Structure: Supplemental Page Table Keeps track of supplemental data about each page i.e. location of data (frame/disk/swap); pointer to corresponding kernel virtual address; list of aliases, etc.

Stack Growth As part of the page fault handler, devise a heuristic to identify valid stack accesses that require stack growth Valid stack accesses may cause the following page faults: PUSH: 4 bytes below %esp PUSHA: 32 bytes below %esp Other accesses: anywhere between %esp and PHYS_BASE Accesses to stack pages that have been paged out Accesses above the stack pointer after %esp has been decremented (i.e. with SUB $n %esp) All pages on the stack (except the first one) must be allocated lazily You should limit stack size to a constant as most OSes do Why is this a good idea?

Memory Mapped Files Implement the mmap() and munmap() system calls Per-Process Data Structure: mmap Page Table Keeps track of file -> page mappings for the process mmap()ed pages must be loaded from disk lazily mmap() should fail (return -1) if: The size of the file is zero bytes The range of pages mapped overlaps with existing mapped pages All mappings are implicitly unmapped when a process exits

Page Replacement Mechanism Eviction Policy Approximation of LRU replacement (e.g. clock algorithm) Pages that can be deallocated without writing to swap/disk Read only (code) pages Clean data pages Clean mmap()ed pages Pages that must be written out to swap Stack pages Dirty data pages Write dirty mmap()ed pages to their corresponding file on disk Global Data Structure: Swap Table Keeps track of the swap slots that are allocated/free

Implementation Order But these are all interdependent! It WON T work to design them separately and try to piece everything together later!

Useful Code Page Allocator (threads/palloc.{h,c}) Allows you to obtain a virtual address for a physical frame Pages can be allocated from either the user pool or the kernel pool Page Directory (userprog/pagedir.{h,c}, threads/pte.h) Interface to the x86 hardware page directory Allows you to perform operations on the hardware page tables for each process pte.h gives access to hardware bits (p/w/u/a/d) General data structures Hash Table (lib/kernel/hash.{h,c}) Bitmap (lib/kernel/bitmap.{h,c}) List (lib/kernel/list.{h,c}) [you should already know this one!] Refer to Appendix A of the Pintos Reference Guide for a more elaborate description of the available APIs

No Extra Credit In previous years there was extra credit available for this assignment There is NO extra credit being offered for this assignment (or for assignment 4) despite what it says in the assignment handout!

Good Luck! Any Questions?