One of the quickest way to avoid out of memory errors is by adding some swap space. Swap is an area on hard drive where operating system can temporally store data that it can no longer hold in RAM.
Use following way to add additional swap space in Ubuntu:
First check about swap space with free command:
free -m
Lets say if we need 10GB of swap, for this first create a 10GB file with following command:
sudo fallocate -l 10G /swapfile
View details about created swapfile:
ls -hl /swapfile
Output:
-rw-r–r– 1 root root 10G May 19 06:54 /swapfile
Change permissions of swapfile:
sudo chmod 600 /swapfile
Set swap space with following command:
sudo mkswap /swapfile
Check for new swap space:
sudo swapon -s
Output:
Filename Type Size Used Priority
/swapfile file 10485756 2700 -2
Make swap file permanent by adding it in /etc/fstab
/swapfile none swap sw 0 0
Like this:
Like Loading...