Pintos project 3: Virtual Memory Management

Slides:



Advertisements
Similar presentations
Project 5: Virtual Memory
Advertisements

Tutorial 8 March 9, 2012 TA: Europa Shang
CS 140 Project 3 Virtual Memory
CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.
CSCC69: Operating Systems
1 Pintos Project #3 Virtual Memory The following slides were created by Xiaomo Liu and others for CS 3204 Fall And Modified by Nick Ryan for Spring.
Segmentation and Paging Considerations
Jaishankar Sundararaman
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Computer Organization and Architecture
Christo Wilson Project 3: Virtual Memory in Pintos
7/3/20151 Announcement (No deadline extension for the rest of quarter) Project 2 final deadline is Tuesday midnight May 19 Project 0 resubmission for autograding.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
CSE378 Virtual memory.1 Evolution in memory management techniques In early days, single program ran on the whole machine –used all the memory available.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory Chantha Thoeun. Overview  Purpose:  Use the hard disk as an extension of RAM.  Increase the available address space of a process. 
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
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.
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.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.
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.
Virtual Memory 1 1.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
CS 3204 Operating Systems Godmar Back Lecture 17.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation.
1 Pintos Virtual Memory Management Project (CS3204 Spring 2006 VT) Yi Ma.
CS 3204 Operating Systems Godmar Back Lecture 16.
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.
Memory Management Continued Questions answered in this lecture: What is paging? How can segmentation and paging be combined? How can one speed up address.
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Virtual Memory – Paging Techniques
Virtual Memory.
Virtual Memory CSSE 332 Operating Systems
Chapter 9: Virtual Memory
Modeling Page Replacement Algorithms
Memory Management References text: Tanenbaum ch.4.
CSE 153 Design of Operating Systems Winter 2018
Chapter 9: Virtual-Memory Management
Memory Management References text: Tanenbaum ch.4.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Modeling Page Replacement Algorithms
Lecture 3: Main Memory.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 153 Design of Operating Systems Winter 2019
Evolution in memory management techniques
Evolution in memory management techniques
Evolution in memory management techniques
COMP755 Advanced Operating Systems
Virtual Memory.
CSE 542: Operating Systems
Clock Algorithm Example
Virtual Memory 1 1.
Presentation transcript:

Pintos project 3: Virtual Memory Management Presented by Xiaomo Liu Acknowledgement: The slides are based on Yi Ma’s presentation

Outline Virtual Memory Concept Current Pintos memory management Requirement Lazy load Stack growth File – memory mapping Swapping Suggestions How to start Implementation order

Virtual Memory Logical memory layout for every process Mapping to the real physical memory What to do it? Paging! Divide the process into small pieces (pages)– 4KB

Virtual Memory Page 2 Page 0 Page 1

Pintos virtual memory Executable on Disk Physical Memory (frame) Kernel space, space (3-4GB) User executable uses virtual, space (0-3GB). They are organized as segments. PHY_BASE Executable on Disk Physical Memory (frame) paddr = kvaddr – PHY_BASE Virtual Linear Address Space (page)

Find these vaddr.h and pagedir.h/c for its interface. Pintos Virtual Memory Virtual Memory Management RAM Frames Find these vaddr.h and pagedir.h/c for its interface. Virtual Address Space MMU translating linear address into page and offset

Current Status (before the project 3) Support multiprogramming Page directory including its page tables for each process Load the entire data and code segment and stack into the memory before the execution (see load function in process.c). Fixed stack (1 page) to each process

Requirement Overview Lazy load Stack growth File – memory mapping Don’t load any page initially. Load a page from executable when it is needed. Stack growth Allocate additional pages for stack as necessary. File – memory mapping Keep one copy of opened files in the memory. Keep track which memory maps to which file. Swapping Run out of frames, select a used frame and swap it out to the swap disk. Return it as a free frame.

Step 1: Frame table management You need a frame table that keeps track all the frames of physical memory used by the user processes. Two approaches: (1) Modify current allocator “palloc_get_page(PAL_USER)” (2) Implement your own allocator on top of “palloc_get_page(PAL_USER)” without modifying it. (Recommended) Have a look at “init.c, palloc.c” to get some ideas Frame table is necessary for swapping

Step 2: Lazy Load How to load executables? Allocate a frame and load a page of executable into memory Before project 3: pintos will load all pages of executables into the physical memory. After project 3: Load nothing except setup the stack at the beginning When executing the process, a page fault occurs and the page fault handler checks where the expected page is: in executable? in swap disk? If in executable, you need to load the corresponding page from executable If in swap disk, you need to load the corresponding page from swap disk Page fault handler need to resume the execution of the process after lazy load

Lazy load: supplemental page table Functionalities Your “s - page table” must be able to decide where to load executable and which corresponding page of executable Your “s - page table ” must be able to decide how to get swap disk and which sectors of swap disk stores the corresponding page Used by page fault handler Populated in load_segment() and mmap() system call

Step 3: Stack Growth Functionality Implementation Before project 3: user stack is fixed size of 1 page, i.e. 4 KB After project 3: user stack is allow to grow Allocate additional pages for user stack as necessary Implementation If the user program exceeds the stack size, a page fault will happen In page fault handler, you need to distinguish stack accesses from other accesses (It is a stack access if the fault address is greater or equal to esp – 32) Catch the stack pointer—esp of interrupt frame You can impose a absolute limit on stack size, STACK_SIZE

Step 4: Memory mapped files Functionality Keep a copy of an open file in memory Keep it in user space Memory mapped

Step 4: Memory mapped files If file size is not multiple of PGSIZE—stick-out, cause partial page Don’t map when: zero address or length, overlap, or console Implementation Use the “fd” to keep track of the open files of a process Design two system calls: mapid_t mmap(fd, addr) and void munmap(mapid_t) Design a data structure to keep track of these mappings We don’t require that two processes that map the same file see the same data

Step 5: Swapping Functionality Implementation When no more free frame, evict a page from its frame and put a copy of into swap disk, if necessary, to get a free frame — swap out When page fault handler finds a page is not memory but in swap disk, allocate a new frame and move it to memory —swap in Implementation Need a method to keep track of which pages have been swapped and in which part of swap disk a page has been stored

Swapping: evict a frame Choose a suitable page replacement algorithms, such as second chance algorithm, additional reference bit algorithm. (See 9.4 of textbook) Select a frame to swap out from frame table Use accessed/dirty bit in PTE Send it to swap Prevent change to page during swapping Update PD & PT

Swapping: frame table The main purpose of maintaining frame table is to efficiently evict a frame for swapping Evict a frame usually need to access the “Accessed” & “Dirty” bits of the page table entry of this frame Remember this fact! It is very important to design your data structure of the frame table and its entry. Because you need to somehow refer frame table entry back to the page table entry (PTE) so as to get the “Accessed” & “Dirty” bits.

Swapping: swap space management You must be able to keep track of which swap slots have been used and which are not. A page is 4KB The Swap disk has sectors of 512B. (see disk.c/h)

Step 6: On process termination Destroy your supplemental page table Free your frames Free your swap slots Close all files. It means write back the dirty mmap pages

Important issues Access user data In project 2, need only verify user address. In project 3, need handle actual access to the content of user memory: (must prevent) process B from evicting a page belonging to process A if A accesses this page during a system call. Need protections: check address+ lock frame read/write unlock.

Important issues Synchronization Allow parallelism of multiple processes. Page fault handling from multiple processes must be possible in parallel. E.g., A’s page fault need I/O (swap, lazy load); B’s page fault need not (stack growth, all ‘0’ page), then B should go ahead.

Important issues Data structure Proper data structure will affect your design Bit map, hash, list, and array How many copies Make it simple

Design milestone Decide the data structures Data structure for supplemental page table entry, frame table entry, swap table entry Data structure for the tables, Hash table? Array? List? Bitmap? Should your tables be global or per-process? Decide the operations for your data structures How to populate the entries of your data structures How to access the entries of your data structures How many entries your data structure should have When & how to free or destroy your data structure Deadline Oct 26th 11:59pm No extra days

Suggested Order Pre-study Understand memory & virtual memory (Lecture slides and Ch 8 & 9 of your textbook) Understand the project documentation (including Appendix A: virtual address & hash table) Understand the important source codes ( load() in process.c and pagedir.h) Submit your design milestone Fix the bugs of project 2 and make it pass all the test cases Frame table management: Implement your frame table allocator.

Suggested Order Supplemental page table management Modifying load() function in process.c or designing a new one to populate your supplemental page table Modify the page fault handler to implement the lazy load, i.e. load a page when page fault occurs Run the regression test cases from project2 Your kernel with lazy load should pass all the test cases at this point Implement stack growth, memory mapping in parallel Swapping Construct your data structure for swap slots management Implement the page replacement algorithm Implement “swap out” functionality Implement “swap in” functionality

Other suggestions Working in the VM directory Create your page.h, frame.h, swap.h, as well as page.c, frame.c, swap.c in the /VM directory Add your additional files to the makefile: Makefile.build Keep an eye on project forum

End Question? Good luck!