Onidel
Tutorials

Troubleshooting Out-of-Memory Issues on Ubuntu 24.04 VPS: Complete OOM Kill Prevention Guide (2025)

8 January 2026
4 min read
Troubleshooting Out-of-Memory Issues on Ubuntu 24.04 VPS: Complete OOM Kill Prevention Guide (2025)

Out-of-memory (OOM) kills can bring your Ubuntu 24.04 VPS to its knees, terminating critical processes without warning. With Ubuntu 24.04’s transition to systemd-oomd and cgroup v2, understanding memory management has become more crucial than ever. This comprehensive guide will help you diagnose OOM events, tune systemd-oomd, configure memory limits, and implement optimal swap strategies.

Introduction

Modern Ubuntu 24.04 systems use a sophisticated memory management approach that differs significantly from previous versions. The introduction of systemd-oomd as the default OOM killer, combined with cgroup v2 memory controls, provides better user experience but requires new troubleshooting approaches.

When your VPS experiences memory pressure, you’ll notice:

  • Applications being terminated unexpectedly
  • System responsiveness degrading significantly
  • Critical services becoming unavailable
  • Database connections dropping during peak loads

This guide covers everything from basic diagnosis to advanced tuning, ensuring your Amsterdam VPS or New York VPS maintains optimal performance under memory pressure.

Prerequisites

Before diving into OOM troubleshooting, ensure you have:

  • Ubuntu 24.04 LTS VPS with root or sudo access
  • Minimum 2GB RAM (4GB+ recommended for production)
  • Basic command-line knowledge
  • SSH access configured with proper security
  • systemd version 252+ (default in Ubuntu 24.04)

Verify your system configuration:

auto
# Check Ubuntu version
lsb_release -a

# Verify systemd version
systemctl --version

# Check cgroup v2 support
stat -fc %T /sys/fs/cgroup/

Diagnosing OOM Events

Checking System Logs

Start by examining recent OOM events in your system logs:

auto
# Check for OOM kills in journal
journalctl --since="24 hours ago" | grep -i "killed\|oom"

# Monitor systemd-oomd activity
journalctl -u systemd-oomd --since="24 hours ago"

# Check kernel OOM killer messages
dmesg | grep -i "killed process"

Monitoring Memory Usage

Use these commands to get real-time memory statistics:

auto
# Detailed memory information
free -h

# Process memory usage
ps aux --sort=-%mem | head -10

# systemd slice memory usage
systemctl status --no-pager -l
systemd-cgtop

Understanding cgroup Memory Limits

Check current memory limits and usage for different cgroups:

auto
# Check user slice memory limits
cat /sys/fs/cgroup/user.slice/memory.max
cat /sys/fs/cgroup/user.slice/memory.current

# Monitor system slice
cat /sys/fs/cgroup/system.slice/memory.max
cat /sys/fs/cgroup/system.slice/memory.current

Tuning systemd-oomd

Configuration Basics

systemd-oomd configuration is located in /etc/systemd/oomd.conf. Create or modify this file:

auto
sudo nano /etc/systemd/oomd.conf

Add these optimized settings:

auto
[OOM]
# Swap usage threshold (default: 90%)
DefaultMemoryPressureDurationSec=30

# Memory pressure threshold
DefaultMemoryPressureLimit=80%

Service-Specific Tuning

Configure memory limits for critical services. Create a drop-in directory:

auto
# Example: Configure database service
sudo mkdir -p /etc/systemd/system/mysql.service.d/
sudo nano /etc/systemd/system/mysql.service.d/memory.conf

Add memory controls:

auto
[Service]
MemoryMax=2G
MemoryHigh=1.5G
OOMPolicy=continue

Reload and restart services:

auto
sudo systemctl daemon-reload
sudo systemctl restart systemd-oomd
sudo systemctl restart mysql

Implementing Swap Strategies

Traditional Swap File

For VPS environments with sufficient storage, a traditional swap file provides reliable memory overflow:

auto
# Create 2GB 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

ZRAM Configuration

ZRAM provides compressed in-memory swap, ideal for VPS with limited storage:

auto
# Install zram-tools
sudo apt update && sudo apt install zram-tools

# Configure ZRAM
sudo nano /etc/default/zramswap

Set optimal ZRAM parameters:

auto
# Set to 50% of available RAM
PERCENT=50
CORP=lz4
PRIORITY=100

Enable and start ZRAM:

auto
sudo systemctl enable zramswap
sudo systemctl start zramswap

Best Practices

Monitoring and Alerting

Set up proactive monitoring to prevent OOM situations:

auto
# Create memory monitoring script
sudo nano /usr/local/bin/memory-monitor.sh
auto
#!/bin/bash
MEM_THRESHOLD=85
USED_MEM=$(free | grep Mem | awk '{printf "%.0f", $3/$2 * 100}')

if [ $USED_MEM -gt $MEM_THRESHOLD ]; then
    logger "Warning: Memory usage at ${USED_MEM}%"
    # Add notification logic here
fi

Application Optimization

Optimize applications to reduce memory footprint:

  • Database tuning: Adjust buffer pools and cache sizes
  • Web server configuration: Limit worker processes and connections
  • Container limits: Set appropriate memory limits for Docker containers
  • JVM tuning: Configure heap sizes for Java applications

Security Considerations

Warning: Be cautious when modifying OOM settings. Incorrect configurations can lead to system instability or security vulnerabilities.

  • Always test changes in a non-production environment first
  • Monitor system behavior after configuration changes
  • Keep backups of original configuration files
  • Consider implementing CIS hardening alongside memory tuning

Conclusion

Properly managing memory on Ubuntu 24.04 VPS requires understanding the interplay between systemd-oomd, cgroup v2, and traditional memory management techniques. By implementing the diagnostic procedures, tuning strategies, and monitoring practices outlined in this guide, you can significantly reduce OOM kills and maintain stable system performance.

The combination of proactive monitoring, appropriate swap configuration, and systemd-oomd tuning creates a robust memory management strategy. Whether you’re running applications on high-performance infrastructure in Amsterdam or New York, these techniques will help ensure your services remain available during memory pressure events.

For production workloads requiring guaranteed memory availability, consider upgrading to higher-specification VPS instances with dedicated resources and advanced features like NVMe storage and high-availability configurations.

Share

Related Articles

Onidel Cloud