Most Linux installations recommend that you include an exchange partition. This may seem strange to Windows users, who are accustomed to having their entire operating system on a single partition.
What does an exchange, you may even need one, and how big should it be? All of these are important questions that, with the right answers, can greatly improve the performance of your system.
In it’s simplest sense, the swap partition acts as a memory overflow (RAM). If the memory is completely full, any additional application will be performed outside the swap partition instead of memory.
This sounds like an easy way to increase the amount of usable memory without getting more RAM, but that’s not the case. RAM is the ideal hardware for memory because it is extremely fast, unlike hard drives that are, in relative terms, very slow. In addition, they do not want to cause additional wear and tear on their solid-state drive. The advent of solid-state drives have made performance in a minor problem with their much improved speeds – but even they can not match RAM.
The closest analogy of the swap partition can be Windows paging file, although there are many technical differences between the two.
A swap partition can also help some memory elements on the hard drive in order to leave more memory space for the more important elements. This implies that the items being touched would almost never get transferred to the swap partition.
The threshold of what is considered “rare” depends on the “swappiness” (yes, that is the current term used), which can be configured. A higher swappiness means that items are more likely to be moved to the SWAP partition – meaning less swappiness that is less likely to be transferred to the swap partition.
Finally, a swap partition is used as the destination of the contents of your memory every time you tell your system to hibernate. This means that without an exchange partition, hibernation in Linux is impossible.
Of course, in fact it is quite rare for users to use the hibernate feature, so this may not matter to you.
Do you need an exchange partition?
So does this mean that an exchange partition is needed? Absolutely not! A Linux system can perform perfectly well without an exchange partition. However, there are some advantages and disadvantages of having one.
- Provides overflow space when memory is full
- You can move the necessary items seldom away from your high-speed memory
- Allows you to hibernate
- Take up space on the hard disk as swap partitions do not resize dynamically
- May increase hard disk wear
- Performance does not necessarily improve (see below)
When swap partitions do not help
What? Swap partitions do not always help improve performance? I’ll explain a scenario where you have an exchange partition was actually worse than having none.
I had Linux installed on a netbook that only had 1 GB of memory and a hard drive of 5400 rpm. With just 1 GB of memory, you can imagine that it can fill up pretty quickly with a couple of open tabs on your browser. The SWAP partition allowed me to keep all of them open as the memory overflow simply went to it.
But then a bottleneck appeared, due to the 5400 rpm speed of the hard drive. Because the hard drive was so slow, and the system constantly wanted to access the swap partition, the netbook was made very, very slow to the point where it became virtually unusable unless it shut down everything to free up some memory.
The swappiness set does not guarantee that, even though there was now space in memory, everything on the swap partition would be backed up. Instead, a lot of it would stay in the swap partition, causing the netbook to continue to be slow. This was only fixed by a restart, which took a while anyway because the system had to remove everything from the partition before shutting down.
So, this is what I recommend:
- If you would like to be able to hibernate the computer, then you should have a swap partition. The size of this partition should be the size of the installed memory, plus an additional 10-25% leaving space for items that have already moved more towards the swap partition.
- If you want a small increase in performance (and you have at least a 7200 rpm hard drive), then you can add a SWAP partition if you want, but it is not necessary unless you have less than 4 GB of Memory installed. The size of this may be what you want, but it would not do anything bigger than it would if you were creating a SWAP partition to enable hibernation.
- If you have a 5400 rpm hard drive then you should not create a swap partition simply because the bottleneck will make the computer worse. SWAP, then you can still create a partition using the same size guidelines described above – but change the swappiness value to something much lower.
To change the swappiness, you need to run the command
gksu gedit /etc/sysctl.conf that will launch a text editor with the name Gedit, a fantastic all around text editor, for the configuration file we need to change. Then find “vm.swappiness” and change it to a different value (preferably 10). If you do not see this parameter, add this line to the end of the file: vm.swappiness = 10
The value you enter indicates when you want Linux to actively start moving processes from the swap partition’s memory. So, for example, a value of 10 indicates that processes will move when memory usage.
There are a lot of other details involved in this, but it would only make things more confusing.
Swap partitions can make a big difference in the performance of your system – sometimes good and sometimes bad. Now that you are well educated, you should be able to make the right decisions.
Are you looking for other ways to speed up the Linux system? Check out these four other quick and easy tips .
What have you heard about the swap partitions? Do you think it’s worth using? Let us know in the comments!