dmesg 里出现 OOM(Out Of Memory) 信息,说明 Linux 内核在某一时刻发现可用内存耗尽,被迫触发 OOM Killer 杀掉某些进程,以保住系统不彻底崩溃。
下面分几块说明:为什么会出现、常见原因、怎么看、怎么处理。
OOM = Out Of Memory
当系统:
内核就会:
dmesg / /var/log/messages)示例:
Out of memory: Kill process 12345 (java) score 800 or sacrifice child
Killed process 12345 (java), UID 0, total-vm: 8192000kB, anon-rss: 6000000kB
关键信息:
Out of memoryKill processscore(OOM 评分,越高越容易被杀)total-vm / anon-rss(进程占用内存)-Xmx 设太大)memory.limitdmesg 也能看到dmesg | grep -i "out of memory"
dmesg -T | grep -i oom
dmesg -T | grep -i "killed process"
free -hsar -rtop / htop# 创建 swap
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
--memory# 让某个进程不容易被 OOM
echo -500 > /proc/PID/oom_score_adj
dmesg 出现 OOM,说明系统内存真的不够了,内核被迫杀进程保命。
如果你愿意,可以把 dmesg 的 OOM 片段贴出来,我可以帮你具体分析是哪个进程、为什么、怎么改最合适。