I went to work this morning and reported that a virtual machine could not connect to ssh. I thought it was probably shut down, or the storage was full. capacity).
Open the background to check the alarm event, no!
I have a hunch that this is not so simple. . . .
into the console, enter
w
dude, output
fork:Cannot allocate memory
Translate: Insufficient memory or the number of processes exceeds the limit
try typing again
free
I want to check the current memory usage, but the same command is not executed and cannot be checked
After communicating with the user, turn off the power and restart the virtual machine to solve the problem.
ps: executable command solution
1. Check whether the system memory usage is too high. After confirming that the memory is insufficient, disable irrelevant services that take up a lot of memory or add memory.
View memory usage through free and top commands
# top
top - 10:43:05 up 6 days, 1:05, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 133 total, 1 running, 132 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8009256 total, 5404700 free, 273716 used, 2330840 buff/cache
KiB Swap: 8257532 total, 8257532 free, 0 used. 7412252 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9 root 20 0 0 0 0 S 0.3 0.0 4:46.06 rcu_sched
1878 root 20 0 21692 1324 1000 S 0.3 0.0 1:59.66 irqbalance
9540 root 20 0 0 0 0 S 0.3 0.0 0:57.49 kworker/0:1
15937 root 20 0 162096 2268 1592 R 0.3 0.0 0:00.05 top
22101 root 20 0 0 0 0 S 0.3 0.0 0:23.94 kworker/1:4
26850 root 20 0 275292 5028 3756 S 0.3 0.1 13:30.88 vmtoolsd
# free -m -m 参数就是用 M显示内容使用情况
total used free shared buff/cache available
Mem: 7821 266 5278 16 2276 7238
Swap: 8063 0 8063
total=used+free
total:表示物理,内存总量–机器总的物理内存 单位为:M
used:用掉的内存{ 总计分配给缓存(包含Buffer和cache)使用的数量,但其中可能部分缓存并未实际使用 }
free: 空闲的物理内存–未被分配的内存
shared:共享内存,一般系统不会用到,这里也不讨论
buffers:系统分配但未被使用的buffers数量
cached:系统分配但未被使用的cache数量
2. Check /var/log/message for oom records.
# grep "Out of memory" /var/log/messages
#
> The Linux kernel has a mechanism called OOM killer (Out Of Memory killer). This mechanism will monitor those processes that occupy too much memory, especially those processes that occupy memory very quickly, and then automatically kill the process to prevent memory exhaustion.
3. Check whether the total number of processes exceeds the limit, and modify the pid_max configuration of the total number of processes.
Check the system pid_max value. The default value of pid_max is 32768.
root@:~# sysctl kernel.pid_max
kernel.pid_max = 32768
View the total number of processes in the system. If the total number of processes reaches pid_max, the system will report a fork Cannot allocate memory error when creating a new process.
# yum install psmisc
pstree -p | wc -l 如没有此命令先安装
744
ps -eLf | wc -l
Temporarily increase the total number of processes pid_max
# sysctl -w kernel.pid_max=65535
kernel.pid_max = 65535
Permanently modify the total number of processes pid_max to make the configuration take effect immediately.
# echo "kernel.pid_max = 65555" >> /etc/sysctl.conf
# sysctl -p
kernel.pid_max = 65555