用非root用户启动某监控程序,报了如下错误:
There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 549232 bytes for Chunk::new# An error report file with more information is saved as:
# /opt/smc/hs_err_pid6659.log
#
# There is insufficient memory for the Java Runtime Environment to continue.
# pthread_getattr_np
# An error report file with more information is saved as:
# /opt/smc/hs_err_pid7631.log
OpenJDK 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
#
# There is insufficient memory for the Java Runtime Environment to continue.
# pthread_getattr_np
# An error report file with more information is saved as:
# /opt/smc/eventmonitor/sbin/hs_err_pid8109.log
#
# There is insufficient memory for the Java Runtime Environment to continue.
# pthread_getattr_np
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 40 bytes for symbol
# An error report file with more information is saved as:
# /opt/smc/hs_err_pid10567.log
运行java -version也报错:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
修改配置
/etc/security/limits.d目录下90-nproc.config,centos6.0的max user processes只有1024,而centos5.0的是278528,具体为什么这么做,不得而知。
90-nproc.config:
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.
* soft nproc 278528
root soft nproc unlimited
注释掉* soft nproc 1024或者修改1024为老版本的278528。
如果还不行,查看:/proc/sys/vm/overcommit_memory文件:
缺省设置:0(只读)
该文件指定了内核针对内存分配的策略,其值可以是0、1、2。
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存(参照overcommit_ratio)。
如果此文件的值不为0,则修改为0。
结束,success!