SSH Connection Problem: Can't Connect to Server
SSH connection troubleshooting guide: Path.net firewall rules, Default Block, creating a filter rule for SSH port, and step-by-step troubleshooting.
Detect and resolve memory leaks on Linux servers, identify which process is consuming RAM, and apply short and long-term fixes.
A memory leak occurs when an application fails to properly release memory it has used, causing RAM usage to continuously increase over time. Eventually the system runs out of memory, swap space fills up, and the server slows down or crashes. This guide covers how to detect and resolve memory leaks.
Typical signs of a memory leak:
free -h output gradually decreasesoom-kill messages appear in dmesg# General memory status
free -h
# Detailed memory info
cat /proc/meminfo
# Swap usage
swapon --show
# OOM killer logs
dmesg | grep -i 'oom\|killed process\|out of memory'
journalctl -k | grep -i 'oom\|killed'
If the available value in free -h drops below 10% of total RAM, you have memory pressure.
# Sort by memory usage with ps
ps aux --sort=-%mem | head -20
# Real-time monitoring with top
top
# Press 'M' to sort by memory
# More detailed memory analysis with smem
sudo apt install smem -y
smem -r -k | head -20
# Monitor a specific process
watch -n 2 'ps aux | grep app_name | grep -v grep'
# Find the PID of a specific process
pgrep -f app_name
# Log memory usage every 30 seconds
while true; do
echo "$(date): $(cat /proc/PID/status | grep VmRSS)"
sleep 30
done
# Detailed memory map
cat /proc/PID/smaps | grep -E '(Rss|Pss|Shared|Private)' | awk '{sum += $2} END {print sum/1024 " MB"}'
# Set Node.js memory limit
node --max-old-space-size=512 app.js
# PM2 auto-restart on memory limit
pm2 start app.js --max-memory-restart 500M
# /etc/php/8.x/fpm/pool.d/www.conf
# pm.max_requests = 500 # Restart worker after 500 requests
# PHP memory limit
# memory_limit = 256M
# /etc/mysql/mysql.conf.d/mysqld.cnf
# innodb_buffer_pool_size = 256M # 25-50% of RAM
# Clear page cache (safe)
sync && echo 1 > /proc/sys/vm/drop_caches
Use drop_caches carefully in production. Disk I/O may temporarily increase after clearing the cache.
# Restart service
sudo systemctl restart service_name
# Apply memory limit with systemd
# /etc/systemd/system/service.service
# [Service]
# MemoryMax=512M
# Create swap file
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Make permanent
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
To resolve memory leaks, first identify which process is consuming memory with ps aux and smem, then confirm the leak by monitoring growth over time. In the short term, restart the leaking service and apply a memory limit with systemd. For a permanent fix, investigate the application's source code using tools like Valgrind (C/C++), heapdump (Node.js), or jmap (Java). Contact REXE support if the issue persists.
High memory usage can be normal — the application may be processing a lot of data. With a memory leak, RAM usage continuously increases over time and never decreases. If it returns to normal after a server restart, you have a leak.
The OOM (Out of Memory) killer is a Linux kernel mechanism that automatically kills the most memory-hungry process to save the system when memory is exhausted. Use 'dmesg | grep oom' to see which process was killed.
Clearing the page cache (echo 1) is generally safe, but temporarily increases disk I/O. Avoid using it during peak hours in production. This command does not cause permanent data loss.
A permanent fix requires examining the application's source code. Use tools like Valgrind (C/C++), heapdump (Node.js), or jmap (Java) to find the source of the leak. In the short term, apply a MemoryMax limit with systemd and schedule regular restarts.
SSH connection troubleshooting guide: Path.net firewall rules, Default Block, creating a filter rule for SSH port, and step-by-step troubleshooting.
RDP connection troubleshooting guide: Path.net firewall rules, Default Block, creating a filter rule for RDP port, and step-by-step troubleshooting.
Guide to running MTR network tests with WinMTR and Linux MTR, creating ICMP filter rules, and submitting results to support. Diagnose packet loss and latency.