Is there a 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?


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.


It makes no difference in terms of speed or performance. It just allows you to use up to 20 GB of virtual memory before the OOM killer starts killing processes to reclaim memory.

If you want better performance:

  • decrease swappiness if you don't use more than 4 GB that often
  • add RAM
  • switch to an SSD and put the swap file on it

According to the answer by Gilles

...There used to be a 2GB swap size limit (on most 32-bit platforms), but this has not been the case for years. The limitation was removed at some point in the 2.2 kernel series.

Additionally, he cites man page for mkswap:

The maximum useful size of a swap area depends on the architecture and the kernel version.

In linux/swap.h library there is MAX_SWAPFILES entry, so there is limit on the number of swap files on the kernel level, however that apparently isn't definitive area either. According to the linked document:

It should be noted that the six bits for “type” should allow up to 64 swap areas to exist in a 32 bit architecture instead of the MAX_SWAPFILES restriction of 32

Which I understand has having maximum of up to 64 swap files on the 32-bit architectures. However, I haven't noticed in the document mention what would happen on 64-bit architecture. Also worth noting that in this case, OP's efforts to create swap files failed on 30th entry.

As for swap partitions, there appears to be no limit for that in the kernel, besides previously mentioned constats, but number of any partitions still would be limited by the underlying BIOS and disk layout.


This answer might not be appropriate for Ubuntu 18.04 (thanks to @Chai T. Rex for pointing this out in the comments).

Anyway for previous versions, here it goes (there is still no proposed update LTS>LTS, so this might still be relevant):

It's not a file, it's a partition, and yes it does because of swappiness

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

So basically if your swap partition is much bigger than the RAM that you have, the system will tend to swap more, causing a general slowness.


There is not much difference in speed or performance when increasing the swap partition to be arbitrarily large.

There are several factors related to swap that can affect performance such as swappiness and hard drive type (SDD or HDD).

Swap is fairly slow and increasing swappiness reduces the performance. However it only has an affect if there is not enough RAM. But it is better than not having any swap. My recommendation is to make the swap partition size twice as big as your RAM.