背景:公司的一台Linux服务器上部署了很多Java服务(微服务的状态),有时候在测试项目的过程中会发现有些关联的Java服务不可用了?到底是什么原因呢?
类比联想一下,我们的手机在使用的过程中,打开了很多app,对于这些运行中的app,操作系统都要给它们分配内存,如果内存不够用操作系统就会杀掉一些进程,以释放内存空间给新的进程。
# There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 1786867712 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=28610, tid=139813184919296 # # JRE version: Java(TM) SE Runtime Environment (8.0_40-b26) (build 1.8.0_40-b26) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode linux-amd64 compressed oops) #
结论:
JVM尝试去像操作系统申请一块内存超出系统的可使用(RSS)内存时, 此时linux会结束JAVA进程,并抛出如上错误。
如今微服务流行。很多进程同时在一台服务器上跑, 必须注意,分配给JAVA的内存只和一定在服务器的可用内存之内。不然很有可能突然被linux干掉一个进程。
网友评论