Ubuntu – Maximum swap file size

nfsswapUbuntu

I'm doing some file processing that seems to require an enormous swap file: even 20Gb isn't enough. What's the theoretical maximum? Running swapon on a 1Tb file resulted in:

swapon: /mnt/big/swap.swap: swapon failed: Invalid argument

The system in question is an Ubuntu VM running on OpenStack, and the drive is NFS mounted. Answers that are broader than this are fine, too though.

Best Answer

The error message here probably comes not from the size of the swap file per se, but from its location on an NFS mount. There is nothing wrong, I believe in a 1 TB swap file. Imagine what sort of swap will be there on a multiprocessor SMP with 4TB RAM!

In order to swap on a remote file you can do as follows:

  # losetup /dev/loop0 /mnt/big/swap.swap
  # mkswap /dev/loop0
  # swapon /dev/loop0