Linux Swap File

You should have atleast half the amount of space for your swap file as you do for physical memory.

root@drvault:/data# sudo dd if=/dev/zero of=/1gb.swap bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 9.46563 s, 113 MB/s

root@drvault:/data# mkswap /1gb.swap
mkswap: /1gb.swap: warning: don’t erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=387ac3e8-64c7-4010-9f20-4e38b443762d

sudo swapon /1gb.swap

/1gb.swap  none  swap  sw  0 0

reboot
root@drvault:~# cat /proc/meminfo | grep Swap*
SwapCached:            0 kB
SwapTotal:       1048568 kB
SwapFree:        1048568 kB

 Add to top of /etc/rc.local script.

#swap file
mkswap /1gb.swap
swapon /1gb.swap

Now verify your memory. Reboot and test.

root@drvault:~# free
             total       used       free     shared    buffers     cached
Mem:       6194152     146112    6048040          0      15596      46528
-/+ buffers/cache:      83988    6110164
Swap:      5242872          0    5242872

You can also add to /etc/fstab

/1gb.swap       none    swap sw 0 0