Today i am going to talk about Swap Space, not going to explain (for now) how to make the Swap Space but i will talk about what it is.
Many people don't know what is Swap Space, but in fact it is an important thing in Linux, so let's go ahead with it.
If you don't know, Linux uses pagination to change memory blocks(pages) between the main memory (RAM) and hard drive, this way the programs that are not running at the moment can place parts of their memory on the hard drive, giving the new process's more memory to run. So it's in this step that Swap Space comes in action, Swap is the name of the space on the disk given to the Linux kernel to do the pagination. Normally the Swap size it's 2x your Physical Memory size, if you have 1GB RAM your Swap will be of 2GB, since disk space it's cheap this is no problem, the problem is as you may know RAM access is made in nanoseconds while disk access is done in milliseconds, if you have a big Swap size it will slow down your programs, because the overhead of pagination will be bigger.
Exists two ways of making a Swap Space the
Swap Partition and the
Swap File. Swap Partition it's the best way and the more used since it creates a partition on the disk dedicated to the Swap, while Swap File creates a file of the size you want your Swap size to have and it will consume disk space.
Swap size plus the
Physical size it's called the Virtual Memory, this way you can run programs that use more memory than you have physically, without receive the message "Error allocating memory: out of memory".
In the new kernels there's a new configuration related to the Swap it's called Swappiness.
Swappiness can have a value of 0 to 100 and the default is 60, this consists in the times that kernel do the pagination, higher the number, more times kernel will do pagination, smaller the number, less times kernel will change memory pages to disk.
Conclusion
Swap Space is important on Linux and you always should use it as a partition.
You can use a Linux without Swap, but if your machine runs out of memory your system will crash.
The rule to choose the size of the Swap size it's 2x your physical memory size.
This was my first article and i am sorry about my english.
Hope you enjoy, if you have any comments or doubt leave a comment