IBM Java Garbage Collection Tuning
IBM Java Garbage Collection Tuning
Chris Bailey
Objectives
Overview
Selecting the Correct GC Policy
Sizing the Java heap
Questions/Answers
Object Allocation
Requires a contiguous area of Java heap
Driven by requests from:
The Java application
JNI code
Most allocations take place in Thread Local Heaps (TLHs)
Threads reserve a chunk of free heap to allocate from
Reduces contention on allocation lock
Keeps code running in a straight line (fewer failures)
Meant to be fast
Parallel GC (optthruput)
Parallel Mark Sweep Collector, with compaction avoidance
Created to make use of additional processors on server systems
Designed to increase performance for SMP and not degrade
performance for uni-processor systems
Optimized for Throughput
Best policy for batch type applications
Consists of a single flat Java heap:
0 GB
2 GB
LOA
Heap Base
Heap Size
Heap Limit
GC Helper Threads
Parallelism achieved through the use of GC Helper Threads
Parked set of threads that wake to share GC work
Main GC thread generates the root set of objects
Helper threads share the work for the rest of the phases
Number of helpers is one less than the number of processing
units
So helper threads and main GC thread equals the number of
processing units
Configurable using -Xgcthreads
10
11
Concurrent GC (optavgpause)
Reduces and makes more consistent the time spent inside Stop the
World GC
Reduction usually between 90 and 95%
Achieved by carrying out some of the STW work whilst application is
running
1.4.2:
Concurrent Marking
5.0:
12
Concurrent Kickoff
13
14
Dangling pointer!
15
0 GB
Allocate
Survivor
LOA
Tenured (old) Space
Heap Size
Heap Limit
16
Survivor
Allocate Space
Space
17
Subpooling (subpool)
Goals:
Reduce allocation lock contention by distributing free memory into
multiple lists
Reduce allocation contention through use of atomic operations instead of
a heap lock
Prevent premature garbage collections by using a best fit (or closer to
best fit) policy instead of address ordered
Ideal for very large SMP systems where large amounts data is being
allocated
where there is heap lock contention
18
19
GETS NONREC
5273
5273
6870
6869
1123
1123
1153
1147
46149 45877
33734 23483
5
5
5
5
5
5
1
1
0
0
0
0
0
0
0
0
SLOW
4572
631
51
5
134
19
0
0
0
0
0
0
0
0
GETS NONREC
68
68
42
42
70
70
SLOW
10
1
0
MON-NAME
test.lock.testlock1@A09410/A09418
test.lock.testlock2@D31358/D31360
java.lang.ref.ReferenceQueue$Lock@920628/920630
20
21
-Xgcpolicy:subpools
22
Monitoring GC Activity
Use of Verbose GC logging
only data that is required for GC performance tuning
Graph Verbose GC output using GC and Memory Visualizer (GCMV) from ISA
Activated using command line options
-verbose:gc
-Xverbosegclog:[DIR_PATH][FILE_NAME],X,Y
where:
[DIR_PATH] is the directory where the file should be written
[FILE_NAME]
is the name of the file to write the logging to
X
is the number of files to
Y
is the number of GC cycles a file should contain
Performance Cost:
(very) basic testing shows a 2% overhead for GC duration of 200ms
eg. if application GC overhead is 5%, it would become 5.1%
23
24
gencon
25
26
27
29
30
0x0
0x40000000
0x80000000
3 GB
0xC0000000
4 GB
0xFFFFFFFF
31
1 GB
2 GB
4 GB
3 GB
0x0
0x80000000
0xC0000000
Libraries
0xFFFFFFFF
On AIX:
0 GB
1 GB
2 GB
Kernel
0x0
4 GB
3 GB
Libraries
0x40000000
0x80000000
0xC0000000
0xFFFFFFFF
32
33
34
2 GB
1 GB
Java Heap
Native Heap
0x40000000
0x0
VM Resources
4 GB
3 GB
0xC0000000
Libraries
0xFFFFFFFF
0 GB
Kernel
0x0
2 GB
1 GB
Native Heap
Java Heap
0x40000000
0x80000000
4 GB
3 GB
Libraries
0xC0000000
0xFFFFFFFF
VM Resources
35
0 GB
0x3
Kernel
0x0
1 GB
2 GB
0x7
Native Heap
0x40000000
3 GB
4 GB
0xD
Java Heap
0x80000000
Libraries
0xC0000000
0xFFFFFFFF
VM Resources
36
1 GB
4 GB
3 GB
Native Heap
Java Heap
0x40000000
0x0
2 GB
VM Resources
0x80000000
TASK_SIZE
Kernel
0xC0000000
0xFFFFFFFF
PAGE_OFFSET
z/OS:
0 GB
1 GB
2 GB
Java Heap
0x0
0x40000000
VM Resources
0x7FFFFFFF
37
Additional Options
Maximum Possible
Advised Maximum
AIX
automatic
3.25 GB
2.5GB
2 GB
1.5GB
3 GB
2.5GB
1.8GB
1.5GB
1.8GB
1.8GB
1.7GB
1.3GB
Linux
Hugemem Kernel
Windows
/3GB
z/OS
38
Moving to 64bit
Moving to 64bit remove the Java heap size limit
However, ability to use more memory is not free
64bit applications perform slower
More data has to be manipulated
Cache performance is reduced
64bit applications require more memory
Java Object references are larger
Internal pointers are larger
Major improvements to this in Java 6.0 due to compressed pointers
39
40
Heap Size
Memory
70%
Heap Occupancy
40%
Time
41
42
43
44
45
46
47
Memory
-Xminf
Heap Occupancy
-Xmaxf
Time
WebSphere Support Technical Exchange
48
Fixed or Variable??
Again, dependent on application
For flat memory usage, use fixed
For widely varying memory usage, consider variable
Variable provides more flexibility and ability to avoid
OutOfMemoryErrors
Some of the disadvantages can be avoided:
-Xms set to lowest steady state memory usage prevents
expansion at startup
-Xmaxf1 will remove shrinkage
-Xminf can be used to prevent compaction before
expansion
-Xmine can be used to reduce expansions
49
Tenured
General Advice:
Fix the new space size
Size the tenured space as you would for a flat heap
WebSphere Support Technical Exchange
50
51
Summary
GC Policy should be chosen according to application scenario
Java heap should ideally be sized for between 40 and 70%
occupancy
Min=Max heap size is right for some applications, but not for others
52
53
54
55