This kernel traffic archive from January 2001 says It's always been the suggested "twice the amount of RAM" in terms of Linux swap size. The idea that swap should be twice as large as RAM has been around for ages, since the days of servers with 16M of RAM.

The problem with this advice is that the amount of swap which can be used beneficially depends on the application use and on the speed of the disk not on the size of the RAM. The size of RAM has been increasing at a greater rate than the speed of disks and therefore the utility of having 2*RAM as the swap size has been decreasing. There's no point in having 2G of swap for a machine with 1G of RAM if using that much swap will make the machine be unusably slow such that a reboot is the only way of regaining control of the machine! Having less swap such that the kernel out of memory (OOM) killer will kill some processes often gives a better result.

If you want to use suspend to disk or a kernel crash dump facility then swap needs to be larger than RAM. There are some situations where a tmpfs file system can be significantly larger than RAM while still delivering good performance (I once ran a machine with 512M of RAM and 6G of swap for this reason). But for most cases of machines with 512M of RAM or more there will be no benefit in having swap larger than RAM and there are some potential disadvantages.

With the speed of modern hard drives it seems unlikely that more than 512M of swap can be used for paging typical applications to a single disk. Having multiple disks with swap spaces will allow increases in the amount of swap which can be usefully used.

Finally if you have a machine that may do some significant paging then make sure that the swap partition is on the fastest part of the disk. My benchmark program ZCAV can be used to find the fastest part of the disk (usually the lowest block numbers).


Back to the main computer performance tuning page.
Copyright © Russell Coker.