Swap space is the area on a hard disk as a part of the Virtual Memory of your machine.
Swap space temporarily holds inactive memory pages. Swap space is used when system needs physical memory for active processes or insufficient physical memory available.
If the system happens to need more memory resources or space, inactive pages in physical memory are then moved to the swap space therefore freeing up that physical memory for other uses. Note access to swap is slower and to physical memory.
A dedicated partition (recommended), a swap file, or a combination can be defined as swap space. Some recommends twice of physical memory. Nowadays, physical memories in new computers are fairly large, my experience is, half of physical memory is sufficient.
Here to show how to create a file system and assign it as as swap space (virtual swap partition).
First, create a 1000M swap file (eg with 2GB physical memory):
sudo dd if=/dev/zero of=/swap_file bs=1M count=1000
You may adjust the file size as your desire. You can also put the swap_file in a different location if desired.
Next, secure the swapspace access, so ordinary users cannot read the contents:
sudo chown root:root /swap_file
sudo chmod 600 /swap_file
Then, asign it into swap space, and turn it on:
sudo mkswap /swap_file
sudo swapon /swap_file
Finally,make it turn on at every bootup, open up /etc/fstab:
sudo vi /etc/fstab
add this line to the end of the file:
/swap_file none swap sw 0 0