HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajorpending

Debug: Linux process consuming too much memory

Submitted by: @anonymous··
0
Viewed 0 times
memory usageoom killerrsspmapmemory leaklinux memory

Error Messages

Out of memory: Killed process
oom-kill
Cannot allocate memory

Problem

A process on Linux is using too much memory and the system is running low or triggering OOM killer.

Solution

Diagnose memory issues on Linux:

# 1. Quick overview - who's using memory?
ps aux --sort=-%mem | head -20
# Or with formatting:
ps -eo pid,ppid,user,%mem,%cpu,rss,vsz,comm --sort=-%mem | head -20

# RSS = Resident Set Size (actual RAM used)
# VSZ = Virtual Size (includes mapped but unused memory)

# 2. System-wide memory status
free -h
# Pay attention to 'available', not 'free'
# Linux uses free RAM for caches (good!)

# 3. Detailed per-process memory
cat /proc/<pid>/status | grep -i vm
# VmRSS: actual RAM
# VmSize: virtual memory
# VmSwap: swapped out memory

# 4. Memory map of a process
pmap -x <pid> | tail -5
# Shows per-mapping breakdown

# 5. Monitor memory over time
watch -n1 'ps -o pid,rss,vsz,comm -p <pid>'

# Or use top with memory sort
top -o %MEM

# 6. Check OOM killer logs
dmesg | grep -i 'oom\|out of memory\|killed process'
journalctl -k | grep -i oom

# 7. Memory leak detection
valgrind --leak-check=full ./myprogram  # C/C++

# 8. Limit process memory
# Using cgroups (systemd):
systemd-run --scope -p MemoryMax=512M ./myprogram

# Using ulimit (per-process):
ulimit -v 524288  # 512MB virtual memory limit

# 9. Check what's in swap
for pid in $(cd /proc && ls -d [0-9]*); do
  swap=$(awk '/VmSwap/{print $2}' /proc/$pid/status 2>/dev/null)
  if [ "${swap:-0}" -gt 0 ]; then
    echo "$pid ($swap KB): $(cat /proc/$pid/comm)"
  fi
done | sort -t: -k2 -n -r | head -10

Why

Linux memory management uses available RAM for caches, making 'free' misleading. RSS is the true measure of process memory use. OOM killer activates when both RAM and swap are exhausted.

Context

Linux server memory troubleshooting

Revisions (0)

No revisions yet.