How to increase swap size?

I tried to increase the swap size after turning off the swap (sudo swapoff -a) on the server, but it always says “fallocate: fallocate failed: Text file busy,” even though I turned it off. It always uses ~300MB by an unknown process.

My question is, why do you guys automatically add 1GB swap file to the server if there isn’t an easy way to increase it? We use Cleavr to simplify server management, not to deal with such issues.

Please provide a solution and add option to manage swap on your panel.

Hello @musharof,

First of all welcome to Cleavr Forum and sorry for getting back lately.

It sounds like there might be some process still holding onto the swap file even after you’ve turned off swapping with sudo swapoff -a.

Turning off swap moves the resources back to the main memory and might take several minutes to complete. Don’t exit the process in the middle.

To turn off swapping run:

sudo swapoff -a

You can confirm swapping is disabled by running the following command:

sudo swapon --show

If the above command shows no output proceed with executing the following commands to configure the swap:

fallocate --length {{ size }} /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
swapon /swapfile
echo "vm.swappiness=20" >> /etc/sysctl.conf
echo "vm.vfs_cache_pressure=50" >> /etc/sysctl.conf

Configuring the swap size is in our backlog and we’ll surely prioritize this over the next few sprints.

Worked like charm, thanks!

Don’t rely on the swap memory. If the server is actively using swap you have a problem with the available resources. Try to optimize your web apps instead! :slight_smile:

1 Like