A Swap Space is a space on a hard disk used as the virtual memory extension of a computer’s real memory. Having a swap space enabled allows your computer’s operating system to pretend that you have more RAM than you actually installed, only being used mainly when there is no sufficient space in RAM left to run applications efficiently.
If you VPS is running low on memory or the MySQL server is constantly shutting down, it’s time to look the memory usage and consider to add Swap Space on your VPS if you haven’t.
sudo swapon --show
If you don’t see anything output back after you run the command, it means that the system doesn’t have any Swap Space available at the moment.
You can also confirm it by
free -h
Before you go ahead, you should also make sure you have enough space left to make the Swap file.
df -h
The general rule when it comes to how big the Swap Space should be is to double the amount of RAM you have on your system or at least the same. So, since I have a server that has 512MB or RAM, I will be creating a 1GB file here.
sudo fallocate -1 1G /swapfile
Once succeeded, you can verify the correct amount of space was reserved by
ls -lh /swapfile
You also need to lock the file down so only the users with the root privilege can get access to the contents of the file.
sudo chmod 600 /swapfile
Check again if needed.
sudo mkswap /swapfile sudo swapon /swapfile
To verify what the configuration for the Swap Space you just created and enabled, use:
sudo swapon --show free -h
The last thing to do is to make the newly created Swap Space permanently available even after the reboot. To do so, you need to add the swap space file to the /etc/fstab file. Nano the file and add the following line at the end of the file.
/swapfile none swap sw 0 0
That’s all you need to.
If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…
In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…
Wake-On-LAN is a networking standard that lets you wake up a computer from either a…
First of all, this is not to bypass a PDF file that requires a password…
Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…
One colleague came up to me the other day asking me to take look at…