Increasing Swap Memory on CentOS , RHEL & Fedora
Are you experiencing memory constraints on your CentOS 8 server? One solution to alleviate memory pressure is by increasing the swap space. In this guide, we'll walk you through the process of increasing the swap memory to 2GB on CentOS / RHEL / FEDORA.
Checking Current Swap Space
Before we begin, let's check if there's any existing swap space on your system. You can do this by running the following command:
free -m
If there's currently no swap space available, you'll see output similar to the following:
Swap: 0 0 0
Creating a Swap File
To create a 2GB swap file, follow these steps:
1. Allocate space for the swap file:
sudo fallocate -l 2G /swapfile
2. Set appropriate permissions on the swap file:
sudo chmod 600 /swapfile
3. Configure the swap file:
sudo mkswap /swapfile
4. Activate the swap file:
sudo swapon /swapfile
Verifying Swap
To ensure the swap space has been added successfully, run `free -m` again:
free -m
You should now see the newly added swap space in the output.
Making Swap Permanent
To make the swap space permanent across reboots, add an entry for the swap file in the `/etc/fstab` file:
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
Reboot and Verification
Finally, reboot your system to apply the changes. After rebooting, verify that the swap space is still active:
free -m
You should see the swap space listed, indicating that it's now available for use.
Conclusion
Increasing swap memory can be an effective way to manage memory constraints on your CentOS 8 server. By following the steps outlined in this guide, you've successfully increased the swap memory to 2GB, providing additional memory resources for your system.
Remember, while swap space can help alleviate memory pressure, it's not a substitute for physical RAM. If you find yourself regularly relying on swap space, consider upgrading your system's RAM for better performance.
Now that you've successfully increased your CentOS / RHEL / FEDORA Server's swap memory, you can enjoy improved system stability and performance.