Swap - swapspace and swappiness

  9 years ago

If you aren't RAM-limited, on install, remove the swap partition.  You can remove the swap partition in an installed system as well - I may cover this later.

Then install a program called swapspace.  From their website:

This system daemon for the Linux kernel aims to do away with the need for large, fixed swap partitions or swap files.

When installing a Linux-based system (invariably GNU/Linux) with Swapspace, the usual swap partition can be omitted, or it can be kept quite small. Whenever Swapspace finds during normal system usage that more virtual memory is needed, it will automatically claim space from the hard disk. Conversely, swap space that is no longer needed is freed up again for regular use by the filesystem.

This means that with Swapspace installed, sizing the system's available swap space during installation is no longer a life-or-death choice. It now becomes practical to run GNU/Linux off just a single, big partition--with no disk space lost to regrettable installation choices. The system should also be able to handle the occasional memory-intensive task that takes much more swap space than was originally foreseen, without leaving the same swap space unused and unusable during normal operation as is normally the case.

It creates a dynamically-sized swapfile on demand that grows and shrinks as required, then is deleted when it's no longer needed.

While this program is no longer being maintained, it is bug-free and requires no configuration.  You can install this from the Software Manager, Synaptic or just type:

sudo apt-get install swapspace

in the terminal.

It will also help to decrease "swappiness", the system's tendency to use swap as available memory decreases.  swappiness is on a scale of 0 to 100.  Type:

cat /proc/sys/vm/swappiness

in a terminal to list your system's current swappiness.  By default it's usually 60.  If you turn it down to 0, the system will only use swap when it actually runs out of physical memory - this is probably not desirable.  A value of 10 or 15 would be appropriate - this way swap will be used when memory usage approaches 80-90%.  To test a different swappiness value, use:

sysctl vm.swappiness=10

or whatever value you prefer.  To set the swappiness value, edit /etc/sysctl.conf as root and insert the following line at the end:

vm.swappiness = 10

or whatever value you prefer.  Either reboot or use swapoff -a then swapon -a as root to activate the new swappiness value.

AshBaby 9 years ago

With 2 GB of RAM on an atom netbook and a Mint 15.. No swap. However if you use games or intensive applications,always have 1.5xRAM swap reserved

Hammer459 9 years ago

Bad idea in general unless you know exactly what you are doing.
In particular the suspend to disk (hibernate) will not work as it dumps out the entire memory to the swap partition. Also a runaway program or memory leaking daemon will freeze the system.
Typically, if you have more than enough RAM, Linux will not swap anything out.
That means your total savings is a few GB disc (dirt cheap) at the cost of a risk of total failure.