Do I Need Swap in Ubuntu? The Realistic Approach

Realistic Swap In Ubuntu Featured

There used to be a time when a swap space was necessary for every Linux installation, but with modern PCs now having 8GB or more of RAM, is there still a need for a dedicated swap space? if you are using Ubuntu, do you need swap in Ubuntu?

Many will answer positively. Others negatively. They all have their reasons for their opinions. The truth is that your need for swap depends on how you’re using your computer.

Note: while the following content is discussed with Ubuntu in mind, it is applicable for almost any Linux distribution.

The Two Faces of Swap

Like with most modern Linux distributions, on Ubuntu you can use two different forms of swap. The classic version has the form of a dedicated partition. It’s usually set up while installing your OS on your HDD for the first time and exists outside the Ubuntu OS, its files, and your data.

Realistic Swap In Ubuntu Gparted Swap Partition

The more modern take has 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 disable it without having to deal with partitions or remove it and reclaim the space. It’s also easier to set up a new swap file from scratch or extend your swap on different volumes (adding a second swap file, a third one, and so on).

If You Use Hibernation, You Need Swap

Let’s start by getting this out of the way: if you’re using hibernation, you need a swap. And not just any amount, it should be at least as large as the RAM in your PC, plus some GBs on top of that.

When it’s told to hibernate instead of shut down, Ubuntu saves everything in your RAM to the swap before it shuts off. The next time you power on your PC, Ubuntu will load the previous saved state from the swap.

Less Memory than You Need, Add Swap

If Ubuntu itself or the apps you run on it demand more RAM than is installed on your PC, you should add a swap. If you don’t, when your RAM fills up, the system will start terminating the apps it deems as “less important” to free up RAM. In some occasions, it could crash the system, too.

The rule of thumb is, if you have less than 8GB of RAM in your system, you need a swap.

More Memory than You Need, No Swap

On the opposite corner, if you have over 16GBs of RAM and aren’t using apps that are too demanding like Blender, don’t edit 4K videos in Kdenlive or multiple images in parallel in GIMP – you may find that Ubuntu never uses your whole RAM.

In those cases, and if you’re not using hibernation, you can do without swap. For those moments 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 set up permanently as a buffer and increase it when necessary.

Check RAM Use and Act Accordingly

The final verdict is that, for most users, no matter the amount of RAM in their computer, it’s suggested they use at least a small swap as a failsafe. For those who need a swap, we can’t recommend a specific size since it also depends on how you use your computer. Ubuntu does provide a quick guide for the amount of swap to set up for your system.

Ubuntu Swap Table

The short version is this:

  • If you’re using hibernation, use as much as your RAM plus one or two GBs.
  • If you’re not using hibernation, monitor your RAM usage with a tool like htop or system monitor for an extended amount of time. When your RAM is constantly being filled up, you need some swap. Add a swap with half your RAM’s size and check whether the problems are gone. If they’re not, repeat by increasing your swap’s size to 1xRAM, then 1.5xRAM, and so on.
  • If you’re not using hibernation and no matter how much you push your computer, you never see its RAM fully utilized, do you always have more than 25 percent RAM continuously available? Then you probably don’t need a swap and could disable it.

If you have decided you need swap on your system, you should learn how to manage swap usage in Linux, or use zswap instead for older laptops.

Odysseas Kourafalos
Odysseas Kourafalos

OK's real life started at around 10, when he got his first computer - a Commodore 128. Since then, he's been melting keycaps by typing 24/7, trying to spread The Word Of Tech to anyone interested enough to listen. Or, rather, read.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox