Making a Swapfile

Making and enabling a swapfile for a little more memory and better performance is simple and takes about 3 minutes.

Note: Putting a swap file on USB or SD flash media is a bad idea, as it may be written to many times, wearing out the drive's limited write cycles.

Prepare the Swapfile
This will create a 512MB swap file, named "swapfile.img" in /.
dd if=/dev/zero of=/swapfile.img bs=1M count=512 #for a 1GB swapfile, use count=1024 mkswap /swapfile.img

You can now turn the swap file on using:
swapon /swapfile.img

You can also turn it off by using:
swapoff /swapfile.img

Always-on Swapfile
To have your swapfile always enabled, even after a reboot, without having to manually turn it on or off, add the following line to the end of your /etc/fstab file using nano or similar:
/swapfile.img none swap sw 0 0

If you're worried about editing /etc/fstab, you can add "swapon /swapfile.img" to a new line in your /etc/rc.local file. The effect is the same.