大网数据广告活动
服务器运维问答

how do i find a memory leak in Linux?

· 52CE 我爱测

I have a digital ocean droplet. recently i combined it with another, and now the system will randomly (every couple days) completely max out on CPU usage (for a single user, not for the system) and it throws a bunch of "out of me…

问题原文

原帖链接 · Katushai · CC BY-SA 4.0

I have a digital ocean droplet. recently i combined it with another, and now the system will randomly (every couple days) completely max out on CPU usage (for a single user, not for the system) and it throws a bunch of "out of memory" errors. i cant use top to figure out what process is causing the problem because it happens randomly.

to try to solve the problem, i recently quadrupled the available memory and CPU power. the problem went away for about a month and now it's happening again, more often than before.

i dont know when its going to strike. and when it does, it locks up the entire system and i have to hard reboot. i checked /var/log/messages and i see a bunch of "out of memory" errors from php, mysqld, spamd, and some other stuff. how do i figure out which user is causing the problem, and more specifically, how do i figure out how to solve it?

for context, it's a regular web hosting system that has cpanel installed.

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

Read the OOM messages. It will print out memory usage details at the time and the PID that was killed. That task is not necessarily the root cause, it just looked big to the kernel at the time.

Look at /proc/meminfo and watch processes with top. You should know approximately how much memory the system is sized for. Say a 4 GB instance intends 2 GB for DB shared memory, 1 GB for web server processes, and 1 GB for OS and admin tools. Any one of these categories exceeding their estimate would cause memory pressure.

Measure memory use per service precisely with cgroup accounting. Containers do this, although you have not said you are using containers.

systemd slices also use cgroups, if that is your service manager. Set DefaultMemoryAccounting=yes and review the output of systemd-cgtop. Try cgroup aware monitoring over time with tools like netdata's cgroups plugin. Set resource limits on the unit once you know what they should be.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。