Virtual Memory Primitives for User Programs

Similar documents
CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

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

Simple Garbage Collection and Fast Allocation Andrew W. Appel

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2015 Lecture 23

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

Outline. 1 Details of paging. 2 The user-level perspective. 3 Case study: 4.4 BSD 1 / 19

CS 134: Operating Systems

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

Processes and Threads

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Garbage Collection Algorithms. Ganesh Bikshandi

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

Lecture Notes on Advanced Garbage Collection

CS399 New Beginnings. Jonathan Walpole

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

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

V. Primary & Secondary Memory!

Lecture 13: Garbage Collection

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Run-Time Environments/Garbage Collection

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

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

Virtual Memory Management

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

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

Virtual Memory I. Jo, Heeseung

OS-caused Long JVM Pauses - Deep Dive and Solutions

Address spaces and memory management

Advanced Memory Management

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory

15 Sharing Main Memory Segmentation and Paging

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

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

16 Sharing Main Memory Segmentation and Paging

Applications of. Virtual Memory in. OS Design

Topic 18: Virtual Memory

Architectural Support for Operating Systems

EECS 482 Introduction to Operating Systems

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Virtual Memory #2 Feb. 21, 2018

Syscalls, exceptions, and interrupts, oh my!

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

Section 10: Device Drivers, FAT, Queuing Theory, Memory Mapped Files

Lecture 4: Memory Management & The Programming Interface

Lecture Notes on Memory Layout

Application Fault Tolerance Using Continuous Checkpoint/Restart

CS5460: Operating Systems

CS61C : Machine Structures

Memory Management. Goals of Memory Management. Mechanism. Policies

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

Total /8 /8 /8 /8 /8 /8 /8 /8 /60. LUMS School of Science and Engineering Department of Computer Science. Final Exam Spring 2013

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

The memory of a program. Paging and Virtual Memory. Swapping. Paging. Physical to logical address mapping. Memory management: Review

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Anne Bracy CS 3410 Computer Science Cornell University

Lecture 15 Garbage Collection

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Solution to the. Gaming Parlor. Programming Project

Past: Making physical memory pretty

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Chapter 8 Memory Management

Caching and Demand-Paged Virtual Memory

Memory Management. Dr. Yingwu Zhu

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

Chapter 9: Virtual Memory

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter 8: Main Memory

Exception Handling. Precise Exception Handling. Exception Types. Exception Handling Terminology

CSE 153 Design of Operating Systems

Virtual Memory Paging

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

CS 153 Design of Operating Systems Winter 2016

Chapter 8: Memory-Management Strategies

An Overview of the BLITZ System

Virtual Memory #3 Oct. 10, 2018

File System CS170 Discussion Week 9. *Some slides taken from TextBook Author s Presentation

CS370 Operating Systems

Lecture 2: Architectural Support for OSes

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

Process Description and Control. Chapter 3

Unit 2 : Computer and Operating System Structure

24-vm.txt Mon Nov 21 22:13: Notes on Virtual Machines , Fall 2011 Carnegie Mellon University Randal E. Bryant.

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

CS370 Operating Systems

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

Processes. Process Management Chapter 3. When does a process gets created? When does a process gets terminated?

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

Basic Memory Management

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Computer System Overview

Transcription:

Virtual Memory Primitives for User Programs Andrew W. Appel & Kai Li Department of Computer Science Princeton University Presented By: Anirban Sinha (aka Ani), anirbans@cs.ubc.ca 1

About the Authors Andrew W. Appel (http:// http://www.cs.princeton.edu/~appel/) Research Interests. I do research in computer security, compilers, programming languages, type theory, and functional programming. Kai Li (http://www.cs.princeton.edu/~li/ http://www.cs.princeton.edu/~li/) Supervisor of Dr. Mark Greenstreet (UBC) Mainly into Parallel & Distributed Systems & Computer Architectures. 2

Outline The Main Objectives of the Paper. The User Level Algorithms. Performance Analysis of VM Primitives. Conclusion drawn from the analysis. Lessons Learnt - Design Issues. Analysis of the paper. 3

Objectives This is I guess the first survey paper we have got so far. In the words of the authors: What virtual memory primitives should the operating system provide to user processes & how well do today s operating systems provide them 4

Virtual Machine Terminologies TRAP: Trap to kernel to handle page faults. PROT1: Write Protect 1 page. PROTN: Write protect N Pages. UNPROT: Unprotect a single page. DIRTY: Return list of dirty pages. MAP: Map save physical page at two different virtual pages with different levels of protection at same address space. 5

VM Applications Concurrent Garbage Collection. Shared virtual memory between processors. Concurrent Checkpointing. Generational Garbage collection. Persistent stores. Extending addressability. Data Compression Paging. Heap Overflow Detection. 6

Application 1: Concurrent Garbage Collection Garbage collector threads can not run concurrently with mutator threads on which garbage collection is to be performed. Garbage collection is normally run after the end of the execution of the threads. It poses a problem to run garbage collector on kernel threads of OSes because Operating System threads keep running, they never really STOP. We need to perform garbage collection concurrently. This algorithm tries to address this issue. 7

Baker s s sequential real time copying collector algorithm Two classes of objects, from & to.. Those reachable by current thread from different paths, starting from registers & pointers for example, are moved from from space to to space incrementally. Mutator sees objects in to space only. When mutator allocates space for new objects using new,, it causes the collector to copy a few more objects from from space to to space. New objects contain to space pointers only. All objects in scanned area contain to space objects only. Unscanned area contain objects that have not been classified as garbage or not garbage.. They contain both to space & from space pointers. 8

Use Of Protected VM Set unscanned area pages as no access. When mutator thread tries to access an object in the unscanned area, it causes a page fault. Collector handles the TRAP, scans the objects on that page, removes them to to space, updated pointers & unlocks the page. Mutator does not notice that the page was originally in from space. The collector runs concurrently in the unscanned area of the code, unprotects the pages as they are being scanned & removes them to to space. If collector threads runs faster than mutator, page faults will be less. Uses TRAP, PROTN, UNPROT & MAP2. 9

Application 2: Shared VM Multiple Processors, some common shared VM area. SVM address space partitioned into pages. read only pages are shared. Writable pages reside in physical memory of a SINGLE processor. If a processor wants to write to a page other than its own, it must obtain a copy of it & invalidate other copies. A page fault occurs when a processor tries to write to a page other than its own. Uses Trap, PROT1 & UNPROT. 10

Application 3: Concurrent Checkpointing Originally, in order to have checkpoints, one had to stop the running thread. It is possible to have concurrent real time checkpoints. Set accessibility of entire address space pages to read only. Start copying the pages to a separate virtual address space. When copying of a page is done set it to read-write mode. When the check pointing thread access a page in read mode, no fault occurs. When it tries to write, write memory access fault occurs, the page is quickly copied to separate address space & status of the current page set to read-write. Restart faulting thread. Incremental checkpoints can also be applied at ease with this algorithm. Uses PROT, UNPROT, PROT1, PROTN, DIRTY. 11

Application 4: Generational Garbage collection Dynamically allocated records in programming languages has two important properties: Younger records are more likely to terminate soon than older records. More pointers go from younger records to older records than the reverse. If i<j, very few pointers from G i to G j. Garbage collection efforts thus should be concentrated on younger records. Inspect DIRTY pages from Gi s.. Else:- Write protect pages of all G i s. When G j calls G i, trap is generated. Save the trapping address in a list. Unprotect page. Find the possible pages from the list that are candidates for garbage in G j. Uses PROTN, UNPROT, TRAP or simply DIRTY. G i G j 12

Application 5: Persistent Stores A data structure, namely a heap that is saved into the disk. Kept on a stable storage device. Implemented in UNIX using:- void *mmap(void* *addr, size_t len, int prot, int flags, int fildes, off_t off); Check http://www.opengroup.org/onlinepubs/009695399/functions/mmap.html Pointer traversal in persistent store is same as in incore traversal. Page fault can occur if the currently accessed page is not actually in memory. Permanent image of the file in the disk should not be modified until commit.. During commit,, all dirty pages moved to disk. Use garbage collection at commit time. 13

Application 6: Heap Overflow Detection Ordinarily, heap overflow is detected by compare & conditional branch during each memory allocation. Can be done more efficiently if we have a guard page which is protected at the end of the memory allocated for heap. Page fault occurs when program tries to access a page beyond the Heap area. Garbage collector is invoked which may free some unused heap pages or a rearrangement may be required. Restart faulting threads. PROT1 & TRAP used. 14

Outline The Main Objectives of the Paper. The User Level Algorithms. Performance Analysis of VM Primitives. Conclusion drawn from the analysis. Lessons Learnt - Design Issues. Analysis of the paper. 15

Performance Analysis Four stages: 1. Sum of PROT1, TRAP & UNPROT by 100 repetitions of the following steps Access a random protected page. In TRAP, unprotect this page & protect some other page. 2. Sum of PROTN, TRAP & UNPROT. Protect 100 pages. Access each page in random sequence. In TRAP handler, unprotect faulting page. 3. Measure the time for a TRAP operation which does not change protection of a page Useful for heap- overflow detections. 4. Time for a single ADD instructions my measuring time taken in a loop that iterates 20 times with each loop having 18 ADD instructions. 16

Results An interesting statistic will be to normalize these results with CPU speed to get the actual picture. 17

Normalized statistic The figure shows the number of ADD instructions that can be executed by the CPU during the time it executes PROT+TRAP + UNPROT. Shows clearly that memory protection mechanisms & TRAP are not optimized in most operating systems. 18

Conclusions Wide variations between the performance of the operating systems on the same hardware. Indicative of the fact that there may be scopes of improvement. Since all the applications discussed involve CPU only & not disk (which has very high seek latency times), it is important that these operations are optimized otherwise this becomes a bottleneck. The situation becomes more acute in real time systems where time constraints are very rigid. 19

Outline The Main Objectives of the Paper. The User Level Algorithms. Performance Analysis of VM Primitives. Conclusion drawn from the analysis. Lessons Learnt - Design Issues. Analysis of the paper. 20

Lessons Learnt from Analysis The Design Issues Make pages less accessible in batches & more accessible in singles as & when required by the process. When a page is made less accessible, outdated information in TLB can cause illegal access violation. Can be prevented by flushing the TLB pages in batches because batch operation reduces the cost per page. 21

Lessons Learnt from Analysis The Design Issues If page faults are handled by CPU, handling time directly depends on the page size. It is important to make page sized optimal. Traditionally though page sizes has been larger because when page faults occurs between physical memory & disk, large disk access time called for having large page size to reduce disk IO time. Good idea is to small pages for PROT & UNPROT operations & for disk page faults, contiguous multi- page blocks can be used (Used in VAX). 22

Lessons Learnt from Analysis The Design Issues When User mode service routines need to access a protected page, allow them by:- Either have multiple mapping of the same page at different addresses with different protection levels in the same address page. Use a separate system call. other alternates exists (did not really understand fully) 23

Is it too tough to implement the applications in OSes? Hmm, synchronous behavior in user programs create a lot of trouble in pipelined architectures. But all except heap overflow detection use asynchronous behavior. Heap overflow detection using VM page faults in VAX or Motorola is thus ugly & is not reliable. Thus its not really a big ask! 24

Analysis of the Paper Strengths:- Discusses a whole lot of applications of protected VM. Brings out the weaknesses of OS s in implementations of this algos. Proposes some design optimization issues that must be looked into. 25

Analysis of the Paper Weaknesses:- I did not find the addressability extension & data compression applications too compelling. Analysis of VM primitive performance in modern OS s not very exhaustive. It s s an old paper, ACM 1991; it would be interesting to discuss how far these ideas are still relevant I the context of modern systems having large physical memory. Any other comments? 26

Questions, Comments & Discussions 27