SlideShare a Scribd company logo
Garbage collection in JVM

Alexey Ragozin

Dec 2013
Common terms
Stop-the-world (STW) pause
– total freeze of application thread in JVM

Compacting algorithms
– ability to relocate objects during garbage collection to
defragment available free space

Parallel collection
– using parallel processing to reduce STW pauses

Concurrent collection
– reclaiming memory in background (no STW pause)
Problem diversity
< 1GiB
< 20 ms
< 200 ms
< 2000 ms

< 10GiB

Lowgarbagecoding

> 10GiB

Off-heap

Young GC

Concurrent mark sweep
Young GC

Fragmentation

Concurrent mark sweep / G1
Fragmentation
Dangers
Young GC
Initial mark
Remark
Concurrent mode failure
Promotion failure
G1 Minor
G1 Full GC
0

20

200

2000

20000
Economy of collection
S – size of heap space
L – size of “live” objects

Size of
“garbage”

Copy collection
SL
 Efficiency*:  c 

L

Mark-Sweep
 Efficiency*:

SL
SL
 c1 
 c2 
L
S

* efficiency – CPU cycles / reclaimed bytes
Weak generational thesis
Thesis
 Most of objects die young
 Number of references from old to young is small

Conclusion
If we could collection old and young objects separately, we
could use throughput efficient algorithm for young objects
and memory efficient algorithm in old space.
Generational collection
Young space
 Throughput oriented collector

Old space
Memory efficient collection

Promotion procedure
All objects are created in young space. Once
object have survived long enough, it should be
moved to old space
Concurrent Mark Sweep






[stop-the-world]
[concurrent]
[concurrent]
[stop-the-world]
[concurrent]

Collection of root references
Marking object graph
Remarking starting with “dirty” pages
Final remark
Sweep - all unmarked is free
Structure of STW pause (CMS)
Summary of pauses

Young
collection
Scan
thread
stacks

Scan dirty cards

Read
card
table

Scan
dirty
pages

Copy
live
objects

Initial
mark
Scan
thread
stacks

Scan
young
space

Remark
Scan
thread
stacks

Scan
young
space

Scan dirty cards

Read
card
table

Scan
dirty
pages
Pause asymptotics

http://blog.ragozin.info/2011/07/openjdk-patch-cutting-down-gc-pause.html
GC parallelism

http://blog.ragozin.info/2013/06/java-gc-in-numbers-parallel-young.html
GC parallelism

http://blog.ragozin.info/2013/06/java-gc-in-numbers-parallel-young.html
Other elements of STW pauses
“safe point” initiation time
Waiting JNI memory lock
Thread stacks scanning
Processing special references
• Weak • Soft • JNI • Finalizers
Heap sizing





-Xmx = -Xms
-Xmx = old space + new space
-Xmn = new space
Old space:
 Application data (jmap –histo)
 Reserve 30-50% for GC head room and fragmentation

 New space:
 According to your workloads
 Too large – risk of sporadic huge promotions
CMS fine tuning






Tuning young space geometry (eden / survivor sizes)
-XX:CMSWaitDuration=N
-XX:+CMSScavengeBeforeRemark
Do you need –XX:+ CMSIncrementalMode?
Do you need class unloading?

http://blog.ragozin.info/2011/07/gc-check-list-for-data-grid-nodes.html
Old space fragmentation

http://blog.ragozin.info/2011/10/cms-heap-fragmentation-follow-up-1.html
Old space fragmentation
Fatal fragmentation leads to
 Single threaded STW Mark Sweep Compact
 Very long promotion failure recovery
Increase old space – most efficient remedy
against fragmentation
Other possible issues
 Swapping
disk trashing is lethal for JVM performance

 Reference abuse
 Abnormally slow safepoints
 Abnormally large methods
 JNI locking memory
HotSpot GC tuning options

http://blog.ragozin.info/2013/11/hotspot-jvm-garbage-collection-options.html
SJK – JVM diagnostic tool
SJK - https://github.com/aragozin/jvm-tools
• Garbage class histogram
• Per thread heap allocation rate reporting
> java -jar sjk.jar ttop -p 6344 -n 20 -o CPU

2013-09-09T11:32:45.426+0300 Process summary
process cpu=31.08%
application cpu=28.90% (user=6.40% sys=22.49%)
other: cpu=2.19%
heap allocation rate 5260kb/s
[000001] user= 3.12% sys=11.40% alloc= 762kb/s –
[092016] user= 0.31% sys= 1.56% alloc= 1927kb/s [092007] user= 0.78% sys= 8.75% alloc= 860kb/s [092012] user= 0.31% sys= 0.31% alloc= 429kb/s [091966] user= 0.16% sys= 0.00% alloc=
90kb/s -

• Ad hoc “pseudo” GC logs
• and more …

main
SVN-WJGGZ
Worker-4863
Worker-4864
Worker-4859
Thank you
http://blog.ragozin.info
- my blog about JVM and other stuff
Alexey Ragozin
alexey.ragozin@gmail.com

More Related Content

What's hot (20)

PPTX
How to be Successful with Scylla
ScyllaDB
 
PDF
Seastar / ScyllaDB, or how we implemented a 10-times faster Cassandra
Tzach Livyatan
 
PDF
JVM Garbage Collection Tuning
ihji
 
PPTX
HotSpot JVM Tuning
Gilad Garon
 
PDF
Ceph scale testing with 10 Billion Objects
Karan Singh
 
PDF
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
PPTX
Latest performance changes by Scylla - Project optimus / Nolimits
ScyllaDB
 
PDF
HTTP Analytics for 6M requests per second using ClickHouse, by Alexander Boc...
Altinity Ltd
 
KEY
Everything I Ever Learned About JVM Performance Tuning @Twitter
Attila Szegedi
 
PDF
PostgreSQL on AWS: Tips & Tricks (and horror stories)
Alexander Kukushkin
 
PDF
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
ScyllaDB
 
PDF
Understanding Garbage Collection
Doug Hawkins
 
PDF
Tuning Linux for Databases.
Alexey Lesovsky
 
PPTX
Developing Scylla Applications: Practical Tips
ScyllaDB
 
PDF
Tuning Java for Big Data
Scott Seighman
 
PDF
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
PDF
Avoiding Data Hotspots at Scale
ScyllaDB
 
PDF
How we got to 1 millisecond latency in 99% under repair, compaction, and flus...
ScyllaDB
 
PDF
Get Your Head in the Cloud - Lessons in GPU Computing with Schlumberger
inside-BigData.com
 
PDF
Chronix Time Series Database - The New Time Series Kid on the Block
QAware GmbH
 
How to be Successful with Scylla
ScyllaDB
 
Seastar / ScyllaDB, or how we implemented a 10-times faster Cassandra
Tzach Livyatan
 
JVM Garbage Collection Tuning
ihji
 
HotSpot JVM Tuning
Gilad Garon
 
Ceph scale testing with 10 Billion Objects
Karan Singh
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
Latest performance changes by Scylla - Project optimus / Nolimits
ScyllaDB
 
HTTP Analytics for 6M requests per second using ClickHouse, by Alexander Boc...
Altinity Ltd
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Attila Szegedi
 
PostgreSQL on AWS: Tips & Tricks (and horror stories)
Alexander Kukushkin
 
Scylla Summit 2016: Analytics Show Time - Spark and Presto Powered by Scylla
ScyllaDB
 
Understanding Garbage Collection
Doug Hawkins
 
Tuning Linux for Databases.
Alexey Lesovsky
 
Developing Scylla Applications: Practical Tips
ScyllaDB
 
Tuning Java for Big Data
Scott Seighman
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
Avoiding Data Hotspots at Scale
ScyllaDB
 
How we got to 1 millisecond latency in 99% under repair, compaction, and flus...
ScyllaDB
 
Get Your Head in the Cloud - Lessons in GPU Computing with Schlumberger
inside-BigData.com
 
Chronix Time Series Database - The New Time Series Kid on the Block
QAware GmbH
 

Viewers also liked (6)

PDF
Java GC tuning and monitoring (by Alexander Ashitkin)
aragozin
 
PDF
Virtualizing Java in Java (jug.ru)
aragozin
 
PDF
Filtering 100M objects in Coherence cache. What can go wrong?
aragozin
 
PDF
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
aragozin
 
PDF
Cборка мусора в Java без пауз (HighLoad++ 2013)
aragozin
 
PDF
Performance Test Driven Development (CEE SERC 2013 Moscow)
aragozin
 
Java GC tuning and monitoring (by Alexander Ashitkin)
aragozin
 
Virtualizing Java in Java (jug.ru)
aragozin
 
Filtering 100M objects in Coherence cache. What can go wrong?
aragozin
 
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
aragozin
 
Cборка мусора в Java без пауз (HighLoad++ 2013)
aragozin
 
Performance Test Driven Development (CEE SERC 2013 Moscow)
aragozin
 
Ad

Similar to Garbage collection in JVM (20)

PPT
Garbage collection in JVM
aragozin
 
PDF
Jvm is-your-friend
ColdFusionConference
 
PDF
The JVM is your friend
Kai Koenig
 
PDF
JVM Performance Tuning
Jeremy Leisy
 
PPT
Performance tuning jvm
Prem Kuppumani
 
PPT
«Большие объёмы данных и сборка мусора в Java
Olga Lavrentieva
 
PPT
Taming Java Garbage Collector
Daya Atapattu
 
PDF
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
PDF
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
 
PPTX
JVM memory management & Diagnostics
Dhaval Shah
 
PDF
[Jbcn 2016] Garbage Collectors WTF!?
Alonso Torres
 
PPTX
An efficient memory system for java Garbage Collection
Rohit Deshpande
 
PPTX
Jvm problem diagnostics
Danijel Mitar
 
PDF
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
PDF
Garbage First & You
ColdFusionConference
 
PDF
Garbage First and you
Kai Koenig
 
PDF
Garbage First and You!
devObjective
 
ODP
Garbage collection
Mudit Gupta
 
PPT
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
 
Garbage collection in JVM
aragozin
 
Jvm is-your-friend
ColdFusionConference
 
The JVM is your friend
Kai Koenig
 
JVM Performance Tuning
Jeremy Leisy
 
Performance tuning jvm
Prem Kuppumani
 
«Большие объёмы данных и сборка мусора в Java
Olga Lavrentieva
 
Taming Java Garbage Collector
Daya Atapattu
 
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
 
JVM memory management & Diagnostics
Dhaval Shah
 
[Jbcn 2016] Garbage Collectors WTF!?
Alonso Torres
 
An efficient memory system for java Garbage Collection
Rohit Deshpande
 
Jvm problem diagnostics
Danijel Mitar
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
Garbage First & You
ColdFusionConference
 
Garbage First and you
Kai Koenig
 
Garbage First and You!
devObjective
 
Garbage collection
Mudit Gupta
 
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
 
Ad

More from aragozin (20)

PDF
Java on Linux for devs and ops
aragozin
 
PDF
I know why your Java is slow
aragozin
 
PPTX
Java profiling Do It Yourself (jug.msk.ru 2016)
aragozin
 
PDF
Java black box profiling JUG.EKB 2016
aragozin
 
PDF
Распределённое нагрузочное тестирование на Java
aragozin
 
PDF
What every Java developer should know about network?
aragozin
 
PPTX
Java profiling Do It Yourself
aragozin
 
PPTX
DIY Java Profiler
aragozin
 
PPTX
Java black box profiling
aragozin
 
PDF
Блеск и нищета распределённых кэшей
aragozin
 
PDF
JIT compilation in modern platforms – challenges and solutions
aragozin
 
PDF
Casual mass parallel computing
aragozin
 
PPTX
Nanocloud cloud scale jvm
aragozin
 
PDF
Performance Test Driven Development with Oracle Coherence
aragozin
 
PPTX
Борьба с GС паузами в JVM
aragozin
 
PPTX
Распределённый кэш или хранилище данных. Что выбрать?
aragozin
 
PPTX
Devirtualization of method calls
aragozin
 
PPTX
Tech talk network - friend or foe
aragozin
 
PDF
Database backed coherence cache
aragozin
 
PDF
ORM and distributed caching
aragozin
 
Java on Linux for devs and ops
aragozin
 
I know why your Java is slow
aragozin
 
Java profiling Do It Yourself (jug.msk.ru 2016)
aragozin
 
Java black box profiling JUG.EKB 2016
aragozin
 
Распределённое нагрузочное тестирование на Java
aragozin
 
What every Java developer should know about network?
aragozin
 
Java profiling Do It Yourself
aragozin
 
DIY Java Profiler
aragozin
 
Java black box profiling
aragozin
 
Блеск и нищета распределённых кэшей
aragozin
 
JIT compilation in modern platforms – challenges and solutions
aragozin
 
Casual mass parallel computing
aragozin
 
Nanocloud cloud scale jvm
aragozin
 
Performance Test Driven Development with Oracle Coherence
aragozin
 
Борьба с GС паузами в JVM
aragozin
 
Распределённый кэш или хранилище данных. Что выбрать?
aragozin
 
Devirtualization of method calls
aragozin
 
Tech talk network - friend or foe
aragozin
 
Database backed coherence cache
aragozin
 
ORM and distributed caching
aragozin
 

Recently uploaded (20)

PDF
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Survival Models: Proper Scoring Rule and Stochastic Optimization with Competi...
Paris Women in Machine Learning and Data Science
 
PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
Essential Content-centric Plugins for your Website
Laura Byrne
 
[GDGoC FPTU] Spring 2025 Summary Slidess
minhtrietgect
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Digital Circuits, important subject in CS
contactparinay1
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Survival Models: Proper Scoring Rule and Stochastic Optimization with Competi...
Paris Women in Machine Learning and Data Science
 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Essential Content-centric Plugins for your Website
Laura Byrne
 

Garbage collection in JVM