Skip to content

Odoo Swap File Configuration: Prevent OOM Kills

DeployMonkey Team · March 23, 2026 7 min read

Why Swap Matters for Odoo

Odoo workers consume significant memory, especially during report generation, large imports, and asset compilation. Without swap, the Linux OOM killer terminates Odoo processes when RAM is exhausted. Proper swap configuration prevents crashes on memory-constrained VPS instances.

Swap Sizing Guidelines

# Recommended swap for Odoo servers:
# 1GB RAM  → 2GB swap
# 2GB RAM  → 2GB swap
# 4GB RAM  → 2-4GB swap
# 8GB RAM  → 2-4GB swap
# 16GB RAM → 2-4GB swap
# 32GB+ RAM → 2GB swap (safety net only)

# Odoo-specific considerations:
# Each worker: 150-300MB RAM
# Cron worker: similar to HTTP worker
# Report generation: can spike to 500MB+
# Asset compilation: 300-500MB spike
# Large CSV imports: can exceed 1GB

Create Swap File

# Check existing swap
free -h
swapon --show

# Create 4GB swap file
sudo fallocate -l 4G /swapfile
# Or on some filesystems:
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

# Set permissions (security critical)
sudo chmod 600 /swapfile

# Format as swap
sudo mkswap /swapfile

# Enable swap
sudo swapon /swapfile

# Verify
free -h

Make Permanent

# Add to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

# Verify fstab (important before reboot!)
sudo findmnt --verify

# Or use UUID:
swap_uuid=$(sudo blkid -s UUID -o value /swapfile 2>/dev/null)
# Note: swap files may not have UUID, path is fine

Swappiness Tuning

# Swappiness: 0-100 (how aggressively to use swap)
# Default: 60
# For Odoo production: 10-20

# Low swappiness = prefer keeping data in RAM
# Only swap when truly necessary

# Set temporarily
sudo sysctl vm.swappiness=10

# Set permanently
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf

# Also tune vfs_cache_pressure:
# Default: 100, for Odoo: 50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf

sudo sysctl -p

SSD Considerations

# Modern SSDs handle swap well
# NVMe: swap barely impacts performance
# SATA SSD: acceptable for safety swap
# HDD: avoid heavy swap usage

# SSD wear from swap is minimal:
# Even 10GB/day swap writes = decades of SSD life
# Do not avoid swap on SSDs

# For cloud VPS:
# Network-attached storage is slower
# Prefer instance-local NVMe if available
# Still better than OOM kills

Monitoring Swap Usage

# Real-time monitoring
free -h
vmstat 1 5

# Which processes use swap
for f in /proc/*/status; do
  awk '/^(Name|VmSwap)/{printf $2" "} END{print""}' $f 2>/dev/null
done | sort -k2 -n -r | head -10

# Alert when swap exceeds threshold
# Add to crontab:
*/5 * * * * SWAP_USED=$(free | awk '/Swap/{print $3}'); \
  [ $SWAP_USED -gt 2000000 ] && \
  echo "High swap: ${SWAP_USED}KB" | logger -t odoo-swap

DeployMonkey

DeployMonkey automatically configures appropriate swap space on every server based on available RAM, with optimized swappiness for Odoo workloads.