Ubuntu – maximum size at which a swap file can function


As far as I know, the theoretical limit for a swap file is insanely large depending on whether a 32bit or 64bit system is used.

I have made a 16GB swap file on a 4GB RAM 64bit system with otherwise low-average specs, because I have more than enough space on my 1TB internal HDD…

But does the large swap file actually make a difference in speed/performance?

Best Answer

  • You can have up to 32 swap areas (files or partitions) with up to ~4 billion (2^32) pages each, where a "page" is 4kB on a traditional (eg x86 or x86_64) system but can be larger on other architectures or if you have configured large pages specially.

    This gives a theoretical maximum of 16TB per swap area, and up to 32 swap areas. There may be other limitations that apply before you reach this but this is as big a swap area that mkswap can create for you.

    As to how much you want, any swap area beyond the maximum you actually utilize contributes nothing to system performance or stability. The trick is to estimate the maximum amount of utilization that will ever occur in a normal or even abnormal situation, and use that as your swap file size and no more.

    At time of writing, swap space greater than around 4GB more than your physical memory size is very unlikely to be utilized, unless your system is very abnormal. On a typical system such as a desktop system used by one person at a time, you can probably even stop at a maximum of say 6GB to 8GB even if your physical memory is greater.

  • Related Question