Administering Filesystems  «Prev 

Setting up a Swap File

Swap devices (partitions) are usually used for swap because they are faster, but it is also possible to create a file that can be used for swap.
Use the following to create the file, where count defines the number of 1KB blocks that swapfile will have:

dd if=/dev/zero of=swapfile bs=1024 count=65536 
mkswap swapfile

List the file in /etc/fstab and follow the rest of the steps listed above to activate the swapfile. The swapfile can also be activated manually with swapon swapfile.

Setting up a swap file

One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap space.
Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.
Basically, this gives you the ability to increase the amount of information that your server can keep in its working "memory", with some caveats. The space on the hard drive will be used mainly when space in RAM is no longer sufficient for data.
The information written to disk will be slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. Overall, having swap space as a fall back for when your system's RAM is depleted is a good safety net.