1 Garbage Collection Danny Angus. Introduction Student loans, amongst other things, run B2B applications implementing government policy in the UK. We.

Slides:



Advertisements
Similar presentations
An Implementation of Mostly- Copying GC on Ruby VM Tomoharu Ugawa The University of Electro-Communications, Japan.
Advertisements

Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Paging: Design Issues. Readings r Silbershatz et al: ,
Lecture 5 Memory Management Part I. Lecture Highlights  Introduction to Memory Management  What is memory management  Related Problems of Redundancy,
Dynamic Memory Management
1 Overview Assignment 5: hints  Garbage collection Assignment 4: solution.
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
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?
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
Memory Leak WEBLOGIC SERVER.  Overview of Java Heap  What is a Memory Leak  Symptoms of Memory Leaks  How to troubleshoot  Tools  Best Practices.
C O N F I D E N T I A L 17-May-15 1 Java Memory Management Overview Justin Chen Mar 16 rd, 2009.
NUMA Tuning for Java Server Applications Mustafa M. Tikir.
CPSC 388 – Compiler Design and Construction
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
This presentation: Sasha GoldshteinCTO, Sela Group Garbage Collection Performance Tips.
UPortal Performance Optimization Faizan Ahmed Architect and Engineering Group Enterprise Systems & Services RUTGERS
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
Memory Management 2010.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Age-Oriented Concurrent Garbage Collection Harel Paz, Erez Petrank – Technion, Israel Steve Blackburn – ANU, Australia April 05 Compiler Construction Scotland.
Linked lists and memory allocation Prof. Noah Snavely CS1114
Memory Management April 28, 2000 Instructor: Gary Kimura.
G1 TUNING Shubham Modi( ) Ujjwal Kumar Singh(10772) Vaibhav(10780)
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Memory Leak Overview and Tools. AGENDA  Overview of Java Heap  What is a Memory Leak  Symptoms of Memory Leaks  How to troubleshoot  Tools  Best.
Exploiting Prolific Types for Memory Management and Optimizations By Yefim Shuf et al.
Chapter 3 Memory Management: Virtual Memory
The Java Virtual Machine Mike Brunt.  What is the JVM?  Main JVM Suppliers  ColdFusion and the JVM  Java J2EE – Java EE Servlet Containers  Where.
File I/O Applied Component-Based Software Engineering File I/O CSE 668 / ECE 668 Prof. Roger Crawfis.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Installing, Configuring And Troubleshooting Coldfusion Mark A Kruger CFG Ryan Stille CF Webtools.
Power your JVM with Effective Garbage Collection Tuning SiliconIndia Java Conference 29 th October, 2010 Vivekanand Jha.
1 Tuning Garbage Collection in an Embedded Java Environment G. Chen, R. Shetty, M. Kandemir, N. Vijaykrishnan, M. J. Irwin Microsystems Design Lab The.
Copyright (c) 2004 Borys Bradel Myths and Realities: The Performance Impact of Garbage Collection Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn.
The Design and Implementation of Log-Structure File System M. Rosenblum and J. Ousterhout.
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Virtual Memory Virtual Memory is created to solve difficult memory management problems Data fragmentation in physical memory: Reuses blocks of memory.
Computer Systems Week 14: Memory Management Amanda Oddie.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
J2SE 1.5 : Memory Heap and Garbage Collector. Objectives You will be able to understand the JVM Memory Heap You will be able to know what the Garbage.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java Author: Fridtjof Siebert, CASES 2000 Michael Sallas Object-Oriented Languages.
Topic: Java Garbage Collection
CSC 331 Object Oriented Programming Using Java
CS161 – Design and Architecture of Computer
Java 9: The Quest for Very Large Heaps
Chapter 9 – Real Memory Organization and Management
CS 153: Concepts of Compiler Design November 28 Class Meeting
Swapping Segmented paging allows us to have non-contiguous allocations
O.S Lecture 13 Virtual Memory.
Am I Reading GC Logs Correctly?
Strategies for automatic memory management
ColdFusion Performance Troubleshooting and Tuning
OS – Memory Deallocation
Interpreting Java Program Runtimes
COMP755 Advanced Operating Systems
Continuously and Compacting By Lyndon Meadow
New GC collectors in Java 11
CMPE 152: Compiler Design May 2 Class Meeting
Presentation transcript:

1 Garbage Collection Danny Angus

Introduction Student loans, amongst other things, run B2B applications implementing government policy in the UK. We process 900,000+ complex loan applications in the six months from March to September every year. 2

Introduction We have to tune performance, our funding stakeholders demand we provide value for money. (As a tax payer so do I). You should tune for performance too. 3

Myth Memory management is one of the things Java is supposed to do for us. We do have to be good citizens And sometimes it still fails to live up to our expectations. 4

Just take a look at these comments from APR, and imagine the code. Glad you don’t have to write it? I know I am. /* Round up the block size to the next boundary, but always * allocate at least a certain size (MIN_ALLOC). */ /* Find the index for this node size by * dividing its size by the boundary size */ /* First see if there are any nodes in the area we know * our node will fit into. */ /* Walk the free list to see if there are * any nodes on it of the requested size * * NOTE: an optimization would be to check * allocator->free[index] first and if no * node is present, directly use * allocator->free[max_index]. This seems * like overkill though and could cause * memory waste. */ /* If we found nothing, seek the sink (at index 0), if * it is not empty. */ /* Walk the free list to see if there are * any nodes on it of the requested size */ /* If we haven't got a suitable node, malloc a new one * and initialize it. */ 5

So what do we have A load of theory but no silver bullet (but I think Sun would like the “AgressiveHeap” option to work for most of us) No “API” which we (the hardworking geeks in the field) can use to even hint about what our applications are going to be doing. A few general heap options A lot of “secret” knowledge 6

How to keep up with the work Suns JVM uses “generational” heap management Partions for old & young Java can create a lot of new objects, For long running processes under steady heavy load that means a real lot. 7

The Generations Young generation New space, when you create an object memory here is allocated. Tenured generation If it last longer than a wee while it is moved here Permanent generation Stuff (classes loaded mainly) that won’t be thrown away 8

And there’s more to the young Creation space Two survivor spaces Objects are promoted from survivor space when they survive a certain number of collections. You can set this number. 9

A Generalisation about types Mark and sweep Start in the VM and follow all of the object references you can reach, mark each object Remove the ones you cant reach Stop and copy Stop execution Copy all the objects you can reach into a new space 10

Mark and sweep Lots of work to do all that marking Leads to fragmentation You can sweep concurrent with execution This is good if you have plenty of CPU and want to avoid pauses. Still need to defrag now and then though. More garbage == more work 11

Stop and copy You need twice as much memory Pauses everything for the whole time it takes De-fragments the space every time More survivors == more work 12

JRE 1.4 Copying collector – default for the young space – aka “minor collection” Parallel copying –XX:+UseParNewGC Parallel scavenge –XX:+UseParallelGC Mark – compact – default for tenured space – major collection Concurrent collector – XX:+UseConcMarkSweepGC 13

What is your goal? “They” expect you to choose between Throughput & Response time, or speed v no pauses. But if you’re like me you’ll want everything. 14

The compromise Balance the time spent in collections against the number of collections. Get the maximum benefit from each collection. 15

Some more clues Space fills to its threshold, and is cleaned right out. In a steady state process there will be an apparent base load in a newly cleaned space, you can measure this and size the spaces. Then you can pick the collector that least intrusively keeps up with the rate at which you use the space. 16

So how do you measure? -loggc: -XX:PrintGCDetails -verbose:gc [GC 0.000: [DefNew: 512K->64K(576K), secs] 512K->155K(1984K), secs] Draw the graph You’re looking for a sawtooth shape The peaks and troughs should reach the same point every time. 17

Pink is before, blue after See the small amount cleaned at each small collection And the big amount cleaned in the major collection What does this suggest? Young space is too small Time line – there is no time on this graph If the whole think took a day do we have too few major collections If this whole thing is a minute do we have too many Context is important Illustration 18

If the heap in use grows Reduce the frequency of collections by increasing the young space 19

This time the young generation is more cleaned Fewer promotions Tenured space in use after the major collection If this continues the size of the heap will increase And pauses will be bigger Another example 20

Logarythmic early growth Steady young size and promotion Would we want the lines to be more horizontal? Only you can tell, balance memory use vs CPU Is this under load or is your normal peak load worse? Optimise for normal peak = = efficient Optimise for occasional peak = = robust Tie it back to real events 21

If major collections are too frequent Increase the size of the heap a bit.. 22

Don’t overdo it If the tenured space is too big you’ll have longer pauses for the tenured collection Reduce the number of promtions by sizing the young generation. -XX:NewSize -XX:MaxNewSize -XX:SurvivorRatio 23

Size the young gen 24

Use Subtraction… [GC : [DefNew: 98814K->7027K(104832K), secs] K->612653K( K), secs] [GC : [DefNew: K->3604K(104832K), secs] K->613349K( K), secs] 696k promoted. 25

Time, don’t forget it 26

A real default profile 27

Here’s one I prepared earlier 28

Myth exploded “Make –Xmx and –Xms the same size” If you have plenty of RAM make –Xmx big to cope with the unexpected But keep –Xms small to manage collection frequency and size 29

Tip Never let the OS swap out the Java heap This is because marking involves traversing the whole heap in unpredictable patterns 30

Size the Young generation Make those collections work for you New size, new ratio balance the eden space and the survivor spaces You want as many of your short lived objects to live and die in one collection, without letting the collection get too onerous of course 31

Size the permanent space Size it just a bit bigger than you need 32

Myth exploded “allocations which can’t be made in permanent space will be made from tenured space” In practice a compacting collection occurs, and if it doesn’t release enough concurrent memory in the perm space the jvm spins up to 100% re-trying the compaction. 33

Parallel and concurrent Might make sense if you have plenty of cpu Uses more cpu, but no pauses Except that you still get de-fragmentation pauses, threads have to be parked before objects can be moved and references re- written. Marking takes a while, and then you have to collect. This may be too slow to clear down during peaks. 34

Aggressive heap The silver bullet? 35

Some more stuff - Xincgc / -Xnoincgc -XX:ParallelGCThreads= -XX:+UseCMSCompactAtFullCollection -XX:MaxTenuringThreshold=0 -XX:SurvivorRatio=1024 -XX:SoftRefLRUPolicyMSPerMB= XX:PretenureSizeThreshold= -XX:+DisableExplicitGC -XX:CMSInitiatingOccupancyFraction= -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSFullGCsBeforeCompaction=1 36

Sizes Xmsvalue -Xmxvalue -Xmnvalue -XX:MinHeapFreeRatio=minimum -XX:MaxHeapFreeRatio=maximum -XX:NewRatio=ratio -XX:NewSize=size -XX:MaxNewSize=size -XX:MaxPermSize= -XX:+AggressiveHeap -XX:+UseAdaptiveSizePolicy 37

Conclusion If you spend too much time doing this you probably need to buy hardware. But it is worth doing now and again. Thanks to Student Loans for letting me talk frankly about our problems. 38

Questions? 39