There was a time when swap space was required for each Linux installation, but with modern PCs now having 8 GB or more of RAM, is there still a need for dedicated swap space? if you use Ubuntu, do you need an exchange in Ubuntu?
Many will respond positively. Others negatively. They all have their reasons for their opinions. The truth is that your need for swaps depends on how you use your computer.
Note: While the following content is discussed with Ubuntu in mind, it is applicable to almost all Linux distributions.
The two faces of the swap
As with most modern Linux distributions, on Ubuntu, you can use two different forms of swap. The classic version has the form of a dedicated score. It is generally configured when you first install your operating system on your hard drive and exists outside of the Ubuntu operating system, its files and your data.
The most modern take is in the form of a swap file. This file exists among the files of your OS next to your data.
By having your swap as a file, you can deactivate it without having to process the partitions or delete it and reclaim space. It is also easier to configure a new swap file from scratch or to extend your swap to different volumes (by adding a second swap file, a third, etc.).
If you use hibernation, you must swap
Let’s start by eliminating this: if you use hibernation, you need an exchange. And not just any quantity, it should be at least as large as your PC’s RAM, plus a few more GB.
When told to hibernate instead of stopping, Ubuntu saves everything in your RAM to replace it before shutting down. The next time you turn on your PC, Ubuntu will load the previous saved state from the swap.
Less memory than necessary, add a swap
If Ubuntu itself or the applications on which you run it require more RAM than that installed on your PC, you must add an exchange. If you don’t, when your RAM fills up, the system will start terminating applications it deems “less important” to free up RAM. In some cases, it could also crash the system.
Generally, if you have less than 8 GB of RAM in your system, you need an exchange.
More memory than necessary, no swap
In the opposite corner, if you have more than 16 GB of RAM and don’t use overly demanding apps like Blender, don’t edit 4K videos in Kdenlive or multiple images in parallel in GIMP – you may find that Ubuntu never uses all of your RAM.
In these cases, and if you are not using hibernation, you can do so without exchange. For those times when you need more memory than you have, you can easily create and activate a swap file. You may even want to have a small swap file permanently configured as a buffer and increase it if necessary.
Check RAM usage and act accordingly
The final verdict is that, for most users, regardless of the amount of RAM in their computer, it is suggested that they use at least one small swap as built-in security. For those who need an exchange, we cannot recommend a specific size, as it also depends on how you use your computer. Ubuntu does provide a quick guide for the amount of swap to configure for your system.
The short version is as follows:
- If you are using hibernation, use as much as your RAM plus one or two GB.
- If you are not using hibernation, monitor your RAM usage with a tool like
htopor system monitor for an extended period. When your RAM is constantly full, you need an exchange. Add a swap with half the size of your RAM and check if the problems are gone. If not, repeat by increasing the size of your swap to 1xRAM, then to 1.5xRAM, etc.
- If you are not using hibernation and no matter how much pressure is placed on your computer, you never see its fully used RAM, do you always have more than 25% of RAM permanently available? Then you probably don’t need an exchange and could deactivate it.
If you’ve decided that you need swap on your system, you need to learn how to manage swap usage on Linux, or use zswap instead for older laptops.
Is this article useful?