DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • All You Need To Know About Garbage Collection in Java
  • Using Heap Dumps to Find Memory Leaks
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Java Z Garbage Collector (ZGC): Revolutionizing Memory Management

Trending

  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  • Building Custom Tools With Model Context Protocol
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Build Your First AI Model in Python: A Beginner's Guide (1 of 3)
  1. DZone
  2. Coding
  3. Languages
  4. OutOfMemoryError: Kill Process or Sacrifice Child – Causes and Solutions

OutOfMemoryError: Kill Process or Sacrifice Child – Causes and Solutions

This post discusses what triggers this ‘kill Process or sacrifice child’ OutOfMemoryError and potential solutions to diagnose this problem.

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Aug. 03, 21 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
9.6K Views

Join the DZone community and get the full member experience.

Join For Free

There are different flavors of OutOfMemoryError. One of the flavors of OutOfMemoryError is ‘Kill Process or sacrifice child’. This post discusses what triggers this ‘kill Process or sacrifice child’ OutOfMemoryError and potential solutions to diagnose this problem.

What Triggers OutOfMemory: Kill Process or Sacrifice Child?

When processes in the host tend to consume more memory than the available memory in the RAM, Operating System based on it’s internal heuristics computations will kill certain processes. In this circumstance, the processes which get killed by the Operating system will experience ‘OutOfMemoryError: Kill Process or sacrifice child.' This problem is more pervasive in the container’s world as well.

Simulating OutOfMemory: Kill Process or Sacrifice Child

In this section, let’s see how to simulate ‘Out Of memory: Kill Process or sacrifice child.’

We launched an AWS EC2 instance r5a.2xlarge Amazon Linux instance. This type of EC2 instance has 64GB RAM.

Fig 1: No Processes running in a r5a.2xlarge host that has 64GB RAM

In this EC2 instance, we launched one Java program. We configured this Java program to consume 20GB of RAM. So this means there is only an additional ~43.5GB of RAM is left. i.e.,

= 64 GB total RAM – 20GB Java Process – 0.5GB Kernel Processes

= 43.5GB

Fig 2: Launched a Java process that will occupy 20GB RAM

Now we went ahead and launched the BuggyApp. BuggyApp is a simple open-source chaos engineering program that is capable of generating various performance problems. We configured BuggyApp to keep creating objects. We set the initial heap size (i.e., Xms) of this program to be 1GB and maximum heap size (i.e., Xmx) to be 50GB and launched the BuggyApp. It means when BuggyApp starts, it’s initial memory consumption will be 1GB, and it has the potential to consume up to 50GB. But if you note, there is only room for 43.5GB in the RAM.

Fig 3: Launching BuggyApp with initial heap size to be 1GB and Max Heap size to be 50GB

BuggyApp got launched successfully, but when its memory consumption reached 43GB, the Operating system killed the BuggyApp program with the ‘Out Of memory: Kill Process or sacrifice child’ error. Operating system took this serious action so that other processes on the system can be safeguarded.

[ 1584.087068] Out of memory: Kill process 3070 (java) score 547 or sacrifice child 
[ 1584.094170] Killed process 3070 (java) total-vm:56994588kB, anon-rss:35690996kB, file-rss:0kB, shmem-
rss:0kB


Above is the kernel log message printed on this device. You can note that the Operating System is killing our BuggyApp java process (whose Process Id is 3070). Note Operating System has internal algorithms and heuristics and keeps track of score for each process. Score this BuggyApp got was 547, thus it killed this process.

Fig 4: BuggyApp experiencing Out Of memory: Kill Process or sacrifice child

Solutions for OutOfMemory: Kill Process or Sacrifice Child

Here are the potential solutions to fix ‘Out Of memory: Kill Process or sacrifice child’:

  1. Increase the RAM capacity of the device in which your applications are running
  1. Reduce the unnecessary processes that are running on the device.
  1. Reduce the memory consumption of the processes which are consuming a lot of memory. 
operating system garbage collection Memory (storage engine)

Opinions expressed by DZone contributors are their own.

Related

  • All You Need To Know About Garbage Collection in Java
  • Using Heap Dumps to Find Memory Leaks
  • Understanding Root Causes of Out of Memory (OOM) Issues in Java Containers
  • Java Z Garbage Collector (ZGC): Revolutionizing Memory Management

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!