How to Fix Oracle Cloud Free Tier Out of Memory (OOM) Crashes

Key Takeaways
- ✓Learn why Oracle Cloud Free Tier Always Free instances crash under memory load
- ✓Step-by-step commands to allocate and mount a 2GB Linux Swap file
- ✓
Get started now or speak directly with our engineering team for specialized assistance.

There is nothing more disorienting for a developer than launching a fresh Oracle Cloud Free Tier instance, configuring Nginx and MySQL, deploying a website, and then suddenly finding that the database service has vanished into thin air. You run sudo systemctl status mysql or check your web application logs, only to find cryptic termination messages like Out of memory: Kill process 1421 (mysqld) or a abrupt single word: Killed.
This phantom crash behavior is caused by the Linux kernel's internal emergency safeguard: the Out of Memory (OOM) Killer. When a virtual machine exhausts all physically available Random Access Memory (RAM), the operating system kernel cannot allocate memory requested by active applications. To prevent the entire operating system from deadlocking or suffering file system corruption, Linux kernel algorithms automatically calculate process penalty scores and forcefully terminate memory-heavy background processes. Because Oracle Cloud Infrastructure (OCI) Free Tier Always Free x86 instances come provisioned with 1GB of physical RAM and zero Swap space configured by default, even modest web traffic spikes, search crawler indexing, or database background maintenance tasks will trigger immediate process termination.
If you have already resolved your initial network connectivity by following our tutorial on Opening Ports 80 & 443 on Oracle Cloud VPS, configuring a virtual Swap file is the mandatory next step to guarantee server uptime and data safety.
Looking for zero-maintenance server stability? Avoid manual Linux kernel parameter tuning and swap file allocation by utilizing RackUp IT's high-speed Managed Cloud & Web Hosting Services, engineered with high-RAM guarantees and automated failover monitoring.
Why do Oracle Cloud Free Tier instances experience sudden process terminations far more frequently than traditional virtual private server (VPS) hosting providers?
Physical RAM is high-speed, volatile hardware memory utilized by your CPU to execute active application threads. When Linux web applications require more memory than physically installed, modern operating systems rely on Swap Space. Swap is a reserved portion of your storage drive (such as an NVMe SSD) formatted specifically to emulate additional virtual RAM. When physical RAM fills up, the Linux kernel gracefully moves idle memory pages out of RAM and writes them to the Swap drive, freeing up physical memory for active processes.
When Swap space is absent (0 Bytes allocated), Linux lacks any memory safety buffer. The kernel executes its internal oom_killer() routine, selects the process consuming the largest memory footprint (which is almost universally mysqld, mariadbd, php-fpm, or node), and sends a non-catchable SIGKILL signal. The application stops instantly without writing data buffers to disk, leading to database table corruption and broken web pages.
Connect to your Oracle Cloud instance via SSH using your terminal or PuTTY, and inspect your server's current hardware memory status by running:
# Display memory and swap usage in human-readable megabytes and gigabytes
free -h
# Inspect active swap devices and file paths
sudo swapon --showInspect the output under the Swap: row. If the total capacity reads 0B, your virtual server has no virtual memory overflow buffer and will terminate database applications the moment memory usage hits 100%.
We will create a dedicated 2GB Swap file on your NVMe storage drive. For 1GB physical RAM instances, allocating 2GB of Swap space provides the optimal ratio between memory protection and drive read/write performance.
Execute the following commands in sequence inside your server terminal:
# Allocate a contiguous 2 Gigabyte file named /swapfile using fallocate
sudo fallocate -l 2G /swapfile
# Fallback method: If your filesystem does not support fallocate, use dd:
# sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
# Restrict file permissions so only the root user can read or write to swap
sudo chmod 600 /swapfile
# Format the allocated binary file as Linux Swap filesystem
sudo mkswap /swapfile
# Activate the swap file immediately in the running kernel
sudo swapon /swapfileVerify that your new virtual memory is active by executing free -h. You should now observe 2.0Gi listed under the Swap column!
By default, Swap space initialized via the swapon command exists only in volatile memory and will be unmounted whenever your Oracle Cloud instance reboots. To make the Swap file permanent across system restarts, append its mount path to the Linux system file system table (/etc/fstab):
# Create a safety backup of your fstab configuration file
sudo cp /etc/fstab /etc/fstab.bak
# Append the swapfile mounting entry to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabThe Linux kernel governs Swap behavior using two key kernel runtime variables configured via sysctl:
Swappiness (vm.swappiness): A percentage value between 0 and 100 defining how aggressively Linux shifts memory pages from physical RAM to Swap. Default Linux desktop settings use 60. For VPS environments, a swappiness setting between 10 and 20 prevents unnecessary disk I/O latency while maintaining emergency protection against OOM crashes.
VFS Cache Pressure (vm.vfs_cache_pressure): Governs how aggressively the kernel reclaims file system directory and inode structures from RAM. Lowering this value from 100 to 50 keeps file metadata cached in RAM, improving web server file access speeds.
Apply these permanent kernel performance parameters by appending them to /etc/sysctl.conf:
# Configure swappiness to 20
echo 'vm.swappiness=20' | sudo tee -a /etc/sysctl.conf
# Configure VFS cache pressure to 50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
# Reload sysctl settings into the active kernel without rebooting
sudo sysctl -p
Click the button below to learn more and get started.
In addition to system-level Swap configuration, tuning your database engine config file (located at /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf) prevents MySQL from attempting to reserve more memory than your physical hardware can supply:
[mysqld]
# Restrict InnoDB Buffer Pool to 256MB on 1GB RAM instances
innodb_buffer_pool_size = 256M
max_connections = 40
performance_schema = OFF
key_buffer_size = 32M
table_open_cache = 400Save the file and restart your database daemon by running sudo systemctl restart mysql.
For more detailed walkthroughs on setting up application stacks on Oracle Cloud, explore our guide on Setting up WordPress on Oracle Cloud Free Tier.
To confirm that your OOM errors have been resolved, monitor kernel system logs using journalctl or dmesg:
# Search system logs for OOM killer activity
sudo dmesg -T | grep -i oom
# Inspect system log history for process kills
sudo journalctl -u mysql --since "24 hours ago"If the output returns empty, your Linux Swap file is performing properly, buffering transient traffic surges and protecting your database from sudden termination.
Will adding a Swap file degrade NVMe SSD performance?
Modern cloud storage drives handle swap operations efficiently. By configuring vm.swappiness=20, Linux utilizes Swap exclusively during high-memory spikes rather than continuous operations, preserving drive lifespan while protecting uptime.
How much Swap space should I allocate on 24GB ARM Ampere instances?
For Oracle Cloud ARM Ampere instances provisioned with 6GB to 24GB RAM, a 4GB Swap file provides ample safety overhead for high-concurrency Node.js, Docker, or WordPress environments.
Why does MySQL still crash even after enabling Swap?
If crashes persist, verify your innodb_buffer_pool_size parameter. Setting buffer pools larger than total physical RAM forces constant disk thrashing that can overwhelm the operating system.
What is the difference between Swap files and Swap partitions?
Swap partitions require dedicated drive partitioning during OS installation. Swap files offer identical performance benefits on modern Linux kernels while allowing flexible sizing and creation on existing file systems without repartitioning.
Cloud Infrastructure Engineer.
DevOps & TutorialsLearn how to point a custom domain to Oracle Cloud VPS and install free Let's Encrypt SSL with Certbot and Nginx in this complete step-by-step tutorial.
Managed VPSLeeds independent retailers need fast, stable websites to capture local shoppers. Discover the best local web hosting options and why managed VPS containers prevent slow checkouts.
VPS HostingStuck with ERR_CONNECTION_TIMED_OUT on Oracle Cloud Free Tier? Learn the step-by-step fix for opening port 80 & 443 across OCI VCN Security Lists and Ubuntu iptables/ufw firewalls.