Tomcat service startup error: cannot allocate memory [How to Solve]

Today, an environment hung up. First, restart it. It was found that it didn’t get up. The following error was reported:

....
Cannot allocate memory

1. Check whether the thread is full first:
# check the maximum allowed processes

[[email protected] ~] sysctl kernel.pid_max
kernel.pid_max = 32768

#View the number of processes in progress on this server

[[email protected] ~] ps -eLf | wc -l
1597

2. Compare the above two values. If the two values are similar, increase the number of allowed processes:
Modify PID_ Max value (custom)

[[email protected] ~] echo 999999 > /proc/sys/kernel/pid_max

Settings take effect permanently

[[email protected] ~] echo "kernel.pid_max=999999" >> /etc/sysctl.conf
[[email protected] ~] sysctl -p

3. If it is not, check the Tomcat log:


then modify the memory allocation:

1. [[email protected] ~] vim/etc/sysctl.conf 
vm.overcommit_memory=1
   [[email protected] ~] sysctl -p  

2.[[email protected] ~] echo 1 > /proc/sys/vm/overcommit_memory
  [[email protected] ~] sysctl –p  

3. [[email protected] ~] sysctl  vm.overcommit_memory=1 

Explanation:
memory allocation strategy in the kernel: overcommit_Memory
optional values: 0, 1, 2

0,: indicates that the kernel will check whether there is enough available memory for the process to use; If there is enough available memory, the memory application is allowed; Otherwise, the memory request fails and the error is returned to the application process
1: indicates that the kernel is allowed to allocate all physical memory regardless of the current memory state
2: indicates that the kernel allows to allocate more memory than the sum of all physical memory and swap space.


Read More: