U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Quantifying the Performance of Garbage Collection vs. Explicit Memory Management.

Slides:



Advertisements
Similar presentations
Paging: Design Issues. Readings r Silbershatz et al: ,
Advertisements

U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Matthew Hertz, Yi Feng, & Emery Berger Department of Computer Science University.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 1 MC 2 –Copying GC for Memory Constrained Environments Narendran Sachindran J. Eliot.
Steve Blackburn Department of Computer Science Australian National University Perry Cheng TJ Watson Research Center IBM Research Kathryn McKinley Department.
Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
Canisius College Department of Computer Science Canisius College University of Rochester Poor Richard's Memory Manager Tongxin Bai, Jonathan Bard, Stephen.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
Hastings Purify: Fast Detection of Memory Leaks and Access Errors.
Heap Shape Scalability Scalable Garbage Collection on Highly Parallel Platforms Kathy Barabash, Erez Petrank Computer Science Department Technion, Israel.
CPSC 388 – Compiler Design and Construction
Increasing Memory Usage in Real-Time GC Tobias Ritzau and Peter Fritzson Department of Computer and Information Science Linköpings universitet
Mark and Sweep Algorithm Reference Counting Memory Related PitFalls
CS 536 Spring Automatic Memory Management Lecture 24.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Using Prefetching to Improve Reference-Counting Garbage Collectors Harel Paz IBM Haifa Research Lab Erez Petrank Microsoft Research and Technion.
Free-Me: A Static Analysis for Individual Object Reclamation Samuel Z. Guyer Tufts University Kathryn S. McKinley University of Texas at Austin Daniel.
1 The Compressor: Concurrent, Incremental and Parallel Compaction. Haim Kermany and Erez Petrank Technion – Israel Institute of Technology.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science CRAMM: Virtual Memory Support for Garbage-Collected Applications Ting Yang, Emery.
Operating Systems CMPSCI 377 Lecture 11: Memory Management
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
U NIVERSITY OF M ASSACHUSETTS Department of Computer Science Automatic Heap Sizing Ting Yang, Matthew Hertz Emery Berger, Eliot Moss University of Massachusetts.
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
An Adaptive, Region-based Allocator for Java Feng Qian & Laurie Hendren 2002.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Garbage Collection Without Paging Matthew Hertz, Yi Feng, Emery Berger University.
1 An Efficient On-the-Fly Cycle Collection Harel Paz, Erez Petrank - Technion, Israel David F. Bacon, V. T. Rajan - IBM T.J. Watson Research Center Elliot.
Garbage collection (& Midterm Topics) David Walker COS 320.
1 Reducing Generational Copy Reserve Overhead with Fallback Compaction Phil McGachey and Antony L. Hosking June 2006.
Uniprocessor Garbage Collection Techniques Paul R. Wilson.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Garbage Collection Memory Management Garbage Collection –Language requirement –VM service –Performance issue in time and space.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science 2006 Exterminator: Automatically Correcting Memory Errors Gene Novark, Emery Berger.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
CSC 107 – Programming For Science. Today’s Goal  Learn how arrays normally used in real programs  Why a function returning an array causes bugs  How.
380C Lecture 17 Where are we & where we are going –Managed languages Dynamic compilation Inlining Garbage collection –Why you need to care about workloads.
Lecture 10 : Introduction to Java Virtual Machine
Fast Conservative Garbage Collection Rifat Shahriyar Stephen M. Blackburn Australian National University Kathryn S. M cKinley Microsoft Research.
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Advanced Compilers CMPSCI 710 Spring 2004 Lecture 1 Emery Berger University of Massachusetts,
Free-Me: A Static Analysis for Automatic Individual Object Reclamation Samuel Z. Guyer, Kathryn McKinley, Daniel Frampton Presented by: Dimitris Prountzos.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science 1 Automatic Heap Sizing: Taking Real Memory into Account Ting Yang, Emery Berger,
Compilation (Semester A, 2013/14) Lecture 13b: Memory Management Noam Rinetzky Slides credit: Eran Yahav 1.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Yi Feng & Emery Berger University of Massachusetts Amherst A Locality-Improving.
Garbage Collection and Memory Management CS 480/680 – Comparative Languages.
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
CSC 213 – Large Scale Programming. Explicit Memory Management  Traditional form of memory management  Used a lot, but fallen out of favor  malloc /
PHY 107 – Programming For Science. Today’s Goal  Learn how arrays normally used in real programs  Why a function returning an array causes bugs  How.
® July 21, 2004GC Summer School1 Cycles to Recycle: Copy GC Without Stopping the World The Sapphire Collector Richard L. Hudson J. Eliot B. Moss Originally.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
GC Assertions: Using the Garbage Collector To Check Heap Properties Samuel Z. Guyer Tufts University Edward Aftandilian Tufts University.
1 The Garbage Collection Advantage: Improving Program Locality Xianglong Huang (UT), Stephen M Blackburn (ANU), Kathryn S McKinley (UT) J Eliot B Moss.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Dynamic Compilation Vijay Janapa Reddi
Interpreted languages Jakub Yaghob
Concepts of programming languages
CMSC 341 Prof. Michael Neary
David F. Bacon, Perry Cheng, and V.T. Rajan
Memory Management Kathryn McKinley.
Created By: Asst. Prof. Ashish Shah, J.M.Patel College, Goregoan West
Program-level Adaptive Memory Management
Presentation transcript:

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Quantifying the Performance of Garbage Collection vs. Explicit Memory Management Matthew Hertz * & Emery Berger University of Massachusetts Amherst * now at Canisius College

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Explicit Memory Management malloc / new allocates space for an object free / delete returns memory to system Simple, but tricky to get right Forget to free  memory leak free too soon  “dangling pointer”

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Dangling Pointers Node x = new Node (“happy”); Node ptr = x; delete x; // But I’m not dead yet! Node y = new Node (“sad”); cout data << endl; // sad  Node x = new Node (“happy”); Node ptr = x; delete x; // But I’m not dead yet! Node y = new Node (“sad”); cout data << endl; // sad  Insidious, hard-to-track down bugs

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Solution: Garbage Collection No need to free Garbage collector periodically scans objects on heap Reclaims non-reachable objects Won’t reclaim objects until they’re dead (actually somewhat later)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science No More Dangling Pointers Node x = new Node (“happy”); Node ptr = x; // x still live (reachable through ptr) Node y = new Node (“sad”); cout data << endl; // happy! Node x = new Node (“happy”); Node ptr = x; // x still live (reachable through ptr) Node y = new Node (“sad”); cout data << endl; // happy! So why not use GC all the time?

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science It’s The Performance… There just aren’t all that many worse ways to f*** up your cache behavior than by using lots of allocations and lazy GC to manage your memory. GC sucks donkey brains through a straw from a performance standpoint. Linus Torvalds

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Slightly More Technically… “GC impairs performance” Extra processing (collection, copying) Degrades cache performance (ibid) Degrades page locality (ibid) Increases memory needs (delayed reclamation)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science On the other hand… No, “GC enhances performance!” Faster allocation (pointer-bumping vs. freelist) Improves cache performance (no need for headers) Better locality (can reduce fragmentation, compact data structures according to use)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Outline Quantifying GC performance A hard problem Oracular memory management Experimental methodology Results

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Comparing Memory Managers Node v = malloc(sizeof(Node)); v->data=malloc(sizeof(NodeData)); memcpy(v->data, old->data, sizeof(NodeData)); free(old->data); v->next = old->next; v->next->prev = v; v->prev = old->prev; v->prev->next = v; free(old); Using GC in C/C++ is easy: BDW Collector

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Comparing Memory Managers Node v = malloc(sizeof(Node)); v->data=malloc(sizeof(NodeData)); memcpy(v->data, old->data, sizeof(NodeData)); free(old->data); v->next = old->next; v->next->prev = v; v->prev = old->prev; v->prev->next = v; free(old); …slide in BDW and ignore calls to free. BDW Collector

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science What About Other Garbage Collectors? Compares malloc to GC, but only conservative, non-copying collectors (really = BDW) Can’t reduce fragmentation, reorder objects, etc. But: faster precise, copying collectors Incompatible with C/C++ Standard for Java…

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Comparing Memory Managers Node node = new Node(); node.data = new NodeData(); useNode(node); node = null;... node = new Node();... node.data = new NodeData();... Adding malloc/free to Java: not so easy… Lea Allocator

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Comparing Memory Managers Node node = new Node(); node.data = new NodeData(); useNode(node); node = null;... node = new Node();... node.data = new NodeData(); need to insert frees, but where? free(node.data)?free(node)? Lea Allocator

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Oracular Memory Manager Java Simulator C malloc/free perform actions at no cost below here execute program here allocation Oracle Consult oracle at each allocation Oracle does not disrupt hardware state Simulator invokes free()…

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Object Lifetime & Oracle Placement Oracles bracket placement of frees Lifetime-based: most aggressive Reachability-based: most conservative unreachable live dead reachable freed by lifetime-based oracle freed by reachability- based oracle can be collected free(obj) free(??) obj = new Object; can be freed free(obj)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Liveness Oracle Generation Java PowerPC Simulator C malloc/free perform actions at no cost below here execute program here trace file allocation, mem access, prog. roots Post- process Liveness: record allocs, mem. accesses Preserve code, type objects, etc. May use objects without accessing them Oracle

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Reachability Oracle Generation Java PowerPC Simulator C malloc/free perform actions at no cost below here execute program here trace file allocations, ptr updates, prog. roots Merlin analysis Reachability: Illegal instructions mark heap events Simulated identically to legal instructions Oracle

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Oracular Memory Manager Java PowerPC Simulator C malloc/free perform actions at no cost below here execute program here oracle allocation Consult oracle before each allocation When needed, modify instruction to call free Extra costs (oracle access) hidden by simulator

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Experimental Methodology Java platform: MMTk/Jikes RVM(2.3.2) Simulator: Dynamic SimpleScalar (DSS) Simulates 2GHz PowerPC processor G5 cache configuration Garbage collectors: GenMS, GenCopy, GenRC, SemiSpace, CopyMS, MarkSweep Explicit memory managers: Lea, MSExplicit (MS + explicit deallocation)

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Experimental Methodology Perfectly repeatable runs Pseudoadaptive compiler Same sequence of optimizations Compiler advice from average of 5 runs Deterministic thread switching Deterministic system clock

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Execution Time for pseudoJBB GC performance can be competitive

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Geo. Mean of Execution Time Garbage collection trades space for time

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Footprint at Quickest Run GC uses much more memory

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Footprint at Quickest Run GC uses much more memory

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Avg. Relative Cycles and Footprint GC always requires more space

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Javac Paging Performance GC: poor paging performance

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science pseudoJBB Paging Performance Lifetime vs. reachability… a wash

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Summary of Results Best collector equals Lea's performance… Up to 10% faster on some benchmarks... but uses more memory Quickest runs require 5x or more memory GenMS at least doubles mean footprint

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Take-home: Practitioners Practitioners: GC - ok if system has more than 3x needed RAM and no competition with other processes Not so good: Limited RAM Competition for physical memory Depends on RAM for performance In-memory database Search engines, etc.

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Take-home: Researchers GC performance already good enough with enough RAM Problems: Paging is a killer Performance suffers for limited RAM

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Future Work Obvious dimensions Other collectors: Bookmarking collector [PLDI 05] Parallel collectors Other allocators: New version of DLmalloc (2.8.2) Our locality-improving allocator [ISMM 05] Other architectures: Examine impact of different cache sizes Other memory management methods Regions, reaps

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Thank you

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Execution Time for ipsixql Object lifetimes can be very important

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science What's the Catch? There just aren’t all that many worse ways to f*ck up your cache behavior than by using lots of allocations and lazy GC to manage your memory. GC sucks donkey brains through a straw from a performance standpoint. Linus Torvalds “ famous computer scientist”

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Who Cares About Memory? RAM is not cheap Already up to 25% of the cost of computer Percentage continues to rise Sun E1000: 4GB costs $75,000 Get additional CPU for free! Upgrading laptops may require new machine

U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Quantifying GC Performance Perform apples-to-apples comparison Examine unaltered applications Measurements differ only in memory manager Consider range of metrics Both time and space measurements