Swap is a dedicated partition on the hard drive and used by Linux when the total amount of RAM installed in the system is fully occupied. In other words, the swap partition is the place where the information is stored when it does not take place in RAM. The content of the swap partition is not accessible to the user and the space occupied by the swap partition cannot be used to store the files.
All Linux distributions recommend creating a SWAP partition. The SWAP partition acts as an overflow for computer memory. If the memory is completely filled, any application will be transferred to the SWAP partition. This seems to be an easy way to increase the amount of memory you can use without changing the amount of RAM. RAM is the ideal hardware medium to use as memory because it is extremely fast, unlike hard drives which are slower.
With the introduction of SSDs, accessing applications on the SWAP partition is faster but still can not be compared to the RAM speed. The SWAP partition can also help move some RAM applications to your hard drive to leave more memory space for other more important applications. This involves moving applications that are accessed less frequently in the SWAP partition.
Applications that are used less often depend on a value called swappiness. This value is configurable. A higher value of swappiness means that applications are more likely to be moved to the SWAP partition if the value of a swappiness is lower means that applications are less likely to be moved to the SWAP partition.
The default value for most systems is 60 but can be set between 0 and 100. The SWAP partition is also used by the hibernation function (the RAM is dumped into the SWAP partition whenever the system hibernates). This means that without a SWAP partition, hibernation on Linux is impossible. Creating a SWAP partition is not necessary. A Linux system can work perfectly without a SWAP partition.
There are advantages and disadvantages to having one.
1. Free RAM space when the memory is completely filled.
2. You can move objects faster by using the RAM memory.
3. The ability to use the hibernation function.
1. Occupies space on your hard drive.
2. It may increase the wear of the hard drive.
3. It does not necessarily improve performance.
1. To use the hibernation option, then you should have a SWAP partition. The size of this partition should be 1.5 times the RAM size.
2. If you want a small performance boost and you have a 7200rpm HDD, then you can add a SWAP partition but it is not necessary if you have more than 4GBof installed memory.
3. If you have a 5400rpm HDD you should not create a SWAP partition because it will make your computer slower. If you still want to have a SWAP partition, then change the swappiness value to something much smaller, such as 10.
To change the swappiness value, you must run the following command in the terminal as an administrator:
The editor will open and locate VM.swappiness and change it to a different value (preferably 10). If you do not have this parameter, add this line at the end of the file: VM.swappiness = 10.
As a conclusion, SWAP partitions can make a major difference in your system performance, sometimes for the better or for worse. That’s why you have to be able to make the right decisions.