centos7:无法分配内存 (errno=12)

启动项目报错:OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000f5a9b000, 66166784, 0) failed; error='无法分配内存' (errno=12)

部分日志内容:

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 262144 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:2627), pid=25179, tid=0x00007fc9dea02700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b15) (build 1.8.0_112-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b15 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

通过命令查看,发现可用的物理内存还剩很多

linux参数之max_map_count

“This file contains the maximum number of memory map areas a process may have. Memory map areas are used as a side-effect of calling malloc, directly by mmap and mprotect, and also when loading shared libraries.

While most applications need less than a thousand maps, certain programs, particularly malloc debuggers, may consume lots of them, e.g., up to one or two maps per allocation.

The default value is 65536.”

 max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量。

虚拟内存区域是一个连续的虚拟地址空间区域。

在进程的生命周期中,每当程序尝试在内存中映射文件,链接到共享内存段,或者分配堆空间的时候,这些区域将被创建。

调优这个值将限制进程可拥有VMA的数量。限制一个进程拥有VMA的总数可能导致应用程序出错,因为当进程达到了VMA上线但又只能释放少量的内存给其他的内核进程使用时,操作系统会抛出内存不足的错误。

如果你的操作系统在NORMAL区域仅占用少量的内存,那么调低这个值可以帮助释放内存给内核用。

 

调整示例

如下调整为默认的4倍

此操作需要root权限

临时修改:

[root@localhost ~]# sysctl -w vm.max_map_count=262144

永久修改:
直接写到/etc/sysctl.conf中,然后执行sysctl -p

    [root@localhost ~]# vim /etc/sysctl.conf
     
    vm.max_map_count=262144
     
    [root@localhost ~]# sysctl -p
     

查看修改结果

    [root@localhost ~]# sysctl -a|grep vm.max_map_count
     
    vm.max_map_count = 262144

 
 

上一篇:Centos 系统部署前性能优化


下一篇:TM4C123G学习笔记2——GPIO