One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap space.
Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.
Please take a note that harddrive speed is slower than RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data.
To check your system whether the swap already configure or not :
sudo swapon -s
If you get only header without any number, surely your system haven’t configured using swap.
Check your system first for free disk :
If everything is good then proceed to create the swap (1G):
dd if=/dev/zero of=/swapfile bs=256M count=4 && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && echo “vm.swappiness = 10” >> /etc/sysctl.conf && sysctl vm.swappiness=10 && echo “/swapfile none swap sw 0 0” >> /etc/fstab && sysctl vm.vfs_cache_pressure=50 && echo “vm.vfs_cache_pressure = 50” >> /etc/sysctl.conf
So what is the swap recommended size ?
According to https://help.ubuntu.com/community/SwapFaq for system less than 1GB memory, it’s highly recommended that the swap space should, as a base minimum, be equal to amount of RAM with maximum twice the amount of RAM depending upon the amount of hard disk space available.
For more detail information about what is swap you may want take a look at https://help.ubuntu.com/community/SwapFaq