Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.

不可行的方法
最初我直接修改catalina.sh, 将JAVA_OPTS变量加上了

-server -Xms1G -Xmx1G -XX:+UserG1GC
最初看起来没啥问题,但是当服务器运行几天后,发现执行shutdown.sh无法关闭tomcat, 错误信息如下:

# root@iZ94hjppdqzZ:~/projects/taolijie# cat hs_err_pid5519.log # There is insufficient memory for the Java Runtime Environment to continue.# Native memory allocation (mmap) failed to map 1073741824 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:2673), pid=5519, tid=3061726064## JRE version: (8.0_45-b14) (build )# Java VM: Java HotSpot(TM) Server VM (25.45-b02 mixed mode linux-x86 )# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again#
关闭个tomcat要请求1G的内存, 当时服务器就剩下200M内存,所以Out Of Memory了。查看shutdown.sh,发现它其实还是调用了catalina.sh,只是传入了一个stop参数。而catalina.sh是执行了

org.apache.catalina.startup.Bootstrap stop
来向tomcat发送关闭信息的。由于上面我们设置了JAVA_OPTS使用1G的堆,因此执行该类时JVM会向系统申请1G多的内存,直接导致Out Of Memory。

可行的方法
在catalina.sh的第二行添加:

CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx1G -XX:+UseG1GC"
这些VM参数就会只应用到catalina而不是所有Tomcat进程。

我的方式,参考上面参数设置启发,设置了-Xms1G -Xmn1G就好了,shutdown.sh就能用了

posted @ 2017-01-01 00:01  君子笑而不语  阅读(20478)  评论(0编辑  收藏  举报