1 Pintos Project #3 Virtual Memory The following slides were created by Xiaomo Liu and others for CS 3204 Fall 2007. And Modified by Nick Ryan for Spring.

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
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
CS 153 Design of Operating Systems Spring 2015
Jaishankar Sundararaman
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
03/26/2010CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying an earlier.
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Christo Wilson Project 3: Virtual Memory in Pintos
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
CS 241 Section Week #12 (04/22/10).
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
CS 3204 Operating Systems Godmar Back Lecture 11.
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.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
CS 4284 Systems Capstone Godmar Back Virtual Memory – Paging Techniques.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
CS 3204 Operating Systems Godmar Back Lecture 17.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Implementation.
1 Virtual Memory. Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost,
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.
Pintos project 3: Virtual Memory Management
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.
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.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
Virtual Memory – Paging Techniques
Virtual Memory.
Virtual Memory CSSE 332 Operating Systems
CSE 120 Principles of Operating
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Modeling Page Replacement Algorithms
Memory Management References text: Tanenbaum ch.4.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Memory Management References text: Tanenbaum ch.4.
Operating Systems Lecture November 2018.
5: Virtual Memory Background Demand Paging
Modeling Page Replacement Algorithms
Virtual Memory.
CSCE 313 – Introduction to UNIx process
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE451 Virtual Memory Paging Autumn 2002
CS703 - Advanced Operating Systems
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.
Module 9: Virtual Memory
Virtual Memory.
Presentation transcript:

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 2009 CS3204: Operating Systems Spring 2009 Project 3 Help Session

2 Outline  Virtual memory concept  Current pintos memory management  Task Lazy load Stack growth File memory mapping Swapping  Suggestion How to start Implementation order

3 Virtual Memory Concept  VM is the logical memory layout for every process It is divided into kernel space and user space Kernel space is global (shared) User space is local (individual)  Different from physical memory  Map to the physical memory  How to do it? Paging! Divide the VM of a process into small pieces (pages) – 4KB “ Randomly ” permute their orders in PM Code Data BSS Stack start program here Heap 0 MAX_VIRTUAL user space kernel space

4 Virtual Memory Mapping  Page 4KB in VM  Frame 4KB in PM  One to one mapping v

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

6 Pintos Virtual Memory Mapping  Virtual address (31 – 12: page number, 11 – 0: offset)  Physical address (31-12: frame number, 11-0: offset)  Two-level mapping Page number finds to the corresponding frame Page offset finds to the corresponding byte in the frame

7 Pintos Virtual Memory Mapping … Three-level mapping Find these vaddr.h and pagedir.h/c for its interface. Virtual Memory Mapping RAM Frames

8 Current Status (Before project 3)  Support multiprogramming  Load the entire data, code and stack segments into memory before executing a program (see load() in process.c)  Fixed size of stack (1 page) to each process  A restricted design!

9 Project 3 Requirement  Lazy load Do not load any page initially Load one page from executable when necessary  Stack growth Allocate additional page for stack when necessary  File memory mapping Keep one copy of opened file in memory Keep track of which memory maps to which file  Swapping If run out of frames, select one using frame Swap it out to the swap disk Return it as a free frame

10 Step 1: Frame “ Table ”  Functionalities Keep track all the frames of physical memory used by the user processes Record the statuses of each frame, such as  Thread it belongs to (if any!)  Page table entry it corresponds to (if any!)  … (can be more)  Implementations (two possible approaches) 1. Modify current frame allocator “ palloc_get_page(PAL_USER) ” 2. Implement your own frame allocator on top of “ palloc_get_page(PAL_USER) ” without modifying it. (Recommended) Have a look at “ init.c ” and “ palloc.c ” to understand how they work Not necessary to use hash table (need figure out by yourself)  Usage Frame table is necessary for physical memory allocation and is used to select victim when swapping.

11 Step 2: Lazy Loading  How does pintos load executables? Allocate a frame and load a page of executable from file disk into memory  Before project 3 Pintos will initially load all pages of executable into 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 file (i.e. hasn ’ t loaded yet)? in swap disk (i.e. swapped out already)? 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 needs to resume the execution of the process after loading the page

12 Step 3: Supplemental Page Table  Functionalities Your “ s-page table ” must be able to decide where to load executable and which corresponding page of executable to load Your “ s-page table ” must be able to decide how to get swap disk and which part (in sector) of swap disk stores the corresponding page  Implementation Use hash table (recommend)  Usage Rewrite load_segment() (in process.c) to populate s-page table without loading pages into memory Page fault handler then loads pages after consulting s-page table

13 Step 4: Stack Growth  Functionalities Before project 3: user stack is fixed with size of 1 page, i.e. 4KB After project 3: user stack is allows to allocate additional pages as necessary  Implementation If the user program exceeds the stack size, a page fault will occur Catch the stack pointer, esp, from the interrupt frame In page fault handler, you need to determine whether the faulted address is “ right below ” the current end of the stack  Whether page fault is for lazy load or stack growth  Don ’ t consider fault addresses less than esp - 32 Calculate how many additional pages need to be allocated for stack; or just allocated faulting page. You must impose an absolute limit on stack size, STACK_SIZE  Consider potential for stack/heap collisions

14 Step 5: File Memory Mapping  Functionalities Make open files accessible via direct memory access – “ map ” them  Storing data will write to file  Read data must come from file If file size is not multiple of PGSIZE — sticks-out, may cause partial page – handle this correctly Reject mmap when: zero address or length, overlap, or console file (tell by fd) Memory mapped

15 Step 5: File Memory Mapping …  Implementations Use “ struct file* ” to keep track of the open files of a process (get via file_reopen()) Design two new system calls: mapid_t mmap(fd, addr) and void munmap(mapid_t) Mmap() system call also populates the s-page table Design a data structure to keep track of these mappings (need figure out by yourself) We don ’ t require that two processes that map the same file see the same data We do require that mmap() ’ ed pages are  Loaded lazily  Written back only if dirty  Subject to eviction if physical memory gets scarce

16 Step 6: Swap “ table ”  Functionalities When out of free frames, 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 whether a page has been swapped and in which part of swap disk a page has been stored if so Not necessary to use hash table (need figure out by yourself) Key insights: (1) only owning process will ever page-in a page from swap; (2) owning process must free used swap slots on exit

17 Step 7: Frame Eviction  Implementations The main purpose of maintaining frame table is to efficiently find a victim frame for swapping Choose a suitable page replacement algorithm, i.e. eviction algorithm, such as second chance algorithm, additional reference bit algorithm etc. (See 9.4 of textbook) Select a frame to swap out from frame table  Unfortunately, frame table entry doesn ’ t store access bits  Refer frame table entry back to the page table entry (PTE)  Use accessed/dirty bit in PTE (must use pagedir_* function here to get hardware bit.) Send the frame to swap disk  Prevent changes to the frame during swapping first Update page tables (both s-page table and hardware page table via pagedir_* functions) as needed

18 Step 8: On Process Termination  Resource Management Destroy your supplemental page table Free your frames, freeing the corresponding entries in the frame table Free your swap slots (if any) and delete the corresponding entries in the swap table Close all files: if a file is mmapped + dirty, write the dirty mmapped pages from memory back to the file disk

19 Important Issues  Synchronization Allow parallelism of multiple processes Page fault handling from multiple processes must be possible in parallel For example, if process A ’ s page fault needs I/O (swapping or lazy load); and if process B ’ s page fault does not need I/O (stack growth or all ‘ 0 ’ page), then B should go ahead without having to wait for A.

20 Implementation Order Suggestions  Pre-study Understand memory & virtual memory (Lecture slides and Ch 8 & 9 of the textbook) Understand project specification (including Appendix A.6, A.7 and A.8) Understand the important pieces of source code (process.c: load_segment(), exception.c: page_fault())  Try to pass all the test cases of project 2 At least, argument passing and system call framework should work  Frame table management

21 Implementation Order Suggestions …  Supplemental page table management  Run regression test cases from project 2 They are already integrated in the P3 test cases You kernel with lazy load should pass all the regression test cases at this point  Implement stack growth and file memory mapping in parallel  Swapping Implement the page replacement algorithm Implement “ swap out ” & “ swap in ” functionality

22 Other Suggestions  Working the VM directory Create your page.h, frame.h, swap.h as well as page.c, frame.c, swap.c in VM directory Add your additional files to the makefile: Makefile.build  Keep an eye on the project forum  Start the design document early It counts 50% of your project scores! Its questions can enlighten your design! Is shared this time (1 per group)

23 End  Questions?  Project 3 is due April 14 th at 11:59PM  Good luck!