Skip to content

Instantly share code, notes, and snippets.

@hotsaucejake
Last active October 29, 2018 20:25
Show Gist options
  • Save hotsaucejake/00ac9f620ea5c121f5633855f3f61932 to your computer and use it in GitHub Desktop.
Save hotsaucejake/00ac9f620ea5c121f5633855f3f61932 to your computer and use it in GitHub Desktop.
Enable Swap Space for Moss Servers

Check System Swap

Before working make sure that system has already swap enabled. If there is no swap, you will get output header only.

sudo swapon -s

Create Swap File

Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.

I have 1GB memory in my system. So I am creating swap of 2GB in size.

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile

Make It Swap

Now make is swap usable file using mkswap command.

sudo mkswap /swapfile

Enable Swap

Now setup the swap for system using swapon command.

sudo swapon /swapfile

Now again check that swap is enabled or not.

sudo swapon -s

Setup Permanent Swap

Append the following entry in /etc/fstab file to enable swap on system reboot.

sudo nano /etc/fstab

/swapfile none swap sw 0 0

Setup Kernel Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

sudo nano /etc/sysctl.conf

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment