IT Blog

home

The solutions about OOM Exception.

12 Feb 2016

OOM이 발생한 경우 해결책 중 하나에 대한 기록.

hs_err_pid[NUM].log 파일에 기록된 내용

# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 12288 bytes for committing reserved memory.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2677), pid=31805, tid=140339567539968
#
# JRE version: OpenJDK Runtime Environment (8.0_45-b13) (build 1.8.0_45-b13)
# Java VM: OpenJDK 64-Bit Server VM (25.45-b02 mixed mode linux-amd64 compressed oops)
# Core dump written. Default location: /home/ec2-user/core or core.31805
#

Java Thread는 Native Heap 공간에 Stack Trace를 저장할 공간을 필요로 한다. ThreadStack Space의 크기는 -Xss 옵션을 통해 지정된다. -Xss 옵션을 통해지정되는 공간은 개별 Thread가 사용하는 공간이다. 만일 N개의 Thread가 활성화되면 N* 만큼의메모리 공간이 필요하다.

대부분의 OS에서 Thread Stack Size는 512K ~ 1M 사이다. 따라서 많은 수의 Thread가 활성화되면 Thread Stack Space만으로도 큰 크기의 Native Heap 메모리 공간을 소모한다.

Thread Stack Space 문제에 의한 OOME를 해소하는 방법은 다음과 같다.

http://ukja.tistory.com/61

참고 : 현재 default stack trace size #[ec2-user@ip ~]$ java -XX:+PrintFlagsFinal -version | grep ThreadStackSize # intx CompilerThreadStackSize = 0 {pd product} # intx ThreadStackSize = 1024 {pd product} # intx VMThreadStackSize = 1024 {pd product} #openjdk version "1.8.0_45" #OpenJDK Runtime Environment (build 1.8.0_45-b13) #OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)