dmesg 里出现“内存不足(Out of memory / OOM)”相关提示,通常说明 Linux 内核在某一时刻无法为进程分配所需内存,于是触发了 OOM 机制。下面从原因、常见表现和排查思路三个方面说明。
Linux 内存包括:
当两者都耗尽,内核无法分配新内存,就会:
Out of memory典型日志:
Out of memory: Kill process 1234 (java) score 800 or sacrifice child
即使 free 显示还有内存,也可能不够,因为:
某个程序持续申请内存不释放,例如:
最终拖垮整个系统。
在:
中如果设置了内存上限,超出后:
dmesg 显示 OOM例如:
vm.overcommit_memory=2 且内存紧张nr_hugepages 占用过多| 信息 | 含义 |
|---|---|
Out of memory |
内存彻底不够 |
oom-kill |
OOM Killer 已杀进程 |
page allocation failure |
内存分配失败(可能是碎片) |
GFP flags |
申请内存的类型 |
free -h
top
htop
dmesg | grep -i oom
dmesg | grep -i "killed process"
swapon --show
如果没有或太小,可考虑增加。
ps aux --sort=-%mem
docker statskubectl describe podsystemctl show <service> | grep Memory
dmesg显示内存不足,说明 系统或某个限制域内内存已被耗尽,内核被迫杀进程以保护系统。
如果你愿意,可以把 dmesg 相关日志贴出来,我可以帮你具体分析是哪类问题。