1

I increased my swap file size using instructions in this link and now it has stopped being used. I actually tried it a few times and it has happened every time. When I ran swapon -s after each attempt, the swap file's priority always showed -2 so I increased it to 100 but that didn't help either.

swapon -s and free -m output screenshot

How can I fix this? I have 16GB ram and increased the swap file size to 32GB.

mook765
  • 14,911
  • 5
  • 35
  • 67
Mojaddam
  • 11
  • 1
  • You have a lot of unused RAM, so why should swap be used? – mook765 Aug 04 '19 at 15:22
  • @mook765 Even when I run heavy duty apps like android studio along with emulators which eat up all the RAM, it still doesn't get used. – Mojaddam Aug 04 '19 at 15:33
  • The system will avoid swapping because swapping reduces overall performance and responsiveness. You can play around with `swappiness`, take a look at https://askubuntu.com/questions/103915/how-do-i-configure-swappiness . – mook765 Aug 04 '19 at 15:50
  • With 16G RAM, 32G swap is nuts. 4G would be more appropriate. And assuming that you don't mess with priority or vm.swappiness, you really don't want to swap unless your system usage requires/needs it. So REDUCE your swap and quit messing with it. – heynnema Aug 04 '19 at 17:53
  • 3
    Possible duplicate of [How much swap should I take for 1GB to 8TB of RAM on 14.04 or higher?](https://askubuntu.com/questions/594054/how-much-swap-should-i-take-for-1gb-to-8tb-of-ram-on-14-04-or-higher) especially the bit at the end that allows you to see how swap is used. – Fabby Aug 05 '19 at 16:32

1 Answers1

0

Swap size recommended settings from Ubuntu Official documentation
https://help.ubuntu.com/community/SwapFaq

RAM   No hibernation    With Hibernation  Maximum
16GB  4GB               20GB              32GB

You need 4Gb or 20Gb of swap space. Not more.

The priority makes sense when there is more than one swap area. Not used in your (1 swap area) case

You can tune the swapping behavior with swappiness
The same Documentation FAQ tells about swappiness,
see: https://help.ubuntu.com/community/SwapFaq#What_is_swappiness_and_how_do_I_change_it.3F


Rebuild your swap setup:
## Delete old swapfile
sudo swapoff -a
sudo sudo rm /swapfile

## Create new swapfile (choose one according to hibernation use)
# sudo fallocate -l 20g /swapfile  ## If hibernation have to be used
sudo fallocate -l 4g /swapfile     ## If no hibernation use is planed
sudo chmod 600 /swapfile
sudo mkswap /swapfile

## Enable new swapfile
sudo swapon /swapfile

## /etc/fstab check
# since /swapfile was used, a line should be present in /etc/fstab file
# search for and check '/swapfile swap swap defaults 0 0'

## Show swap settings and usage
swapon -s
free -h
cmak.fr
  • 8,411
  • 2
  • 29
  • 45
  • 1
    That bit of the Ubuntu SwapFaq actually originates [here](https://askubuntu.com/questions/594054/how-much-swap-should-i-take-for-1gb-to-8tb-of-ram-on-14-04-or-higher/594402#594402) **>:-)** – Fabby Aug 05 '19 at 16:32