What Is a Linux Swap Partition? Every thing You Must Know

Most Linux installations recommend including a swap partition. This may seem strange to Windows users who are used to having their entire operating system on a single partition.


What does a swap partition do, do you need one and how big should it be? These are all important questions that, with the right answers, can significantly improve your system's performance.

What the Linux swap partition does

The swap partition serves as overflow memory for your RAM. When your RAM is completely full, all additional applications are run from the swap partition instead of RAM.

This may sound like an easy way to increase your computer's usable memory without actually getting more RAM. However, this is not the case. RAM is the ideal hardware for storage because it is extremely fast, unlike hard drives, which are relatively slower in relative terms.

Solid-state drives may have had less impact on performance due to their greatly improved speeds

How do solid-state drives work?
In this article, you will learn exactly what SSDs are, how SSDs actually work and work, why SSDs are so useful and the biggest disadvantage of SSDs.
Continue reading

, but even they cannot match the RAM. This also applies to newer NVMe SSDs

What is an M.2 SSD? The advantages and disadvantages as well as the installation
Would you like your operating system to run even faster? The answer is to use an M.2 SSD. Here's what you need to know.
Continue reading

. In both cases, you don't want to cause additional wear on your solid-state drive.

The Windows swap file is a close analogy to the swap partition

How to fix low RAM or memory leaks in Windows
Do you have 4 or more GB of RAM and does your computer still feel sluggish? You may have a memory leak or deficiency. We'll show you how to fix all of your Windows (10) …
Continue reading

, although there are many technical differences between the two.

The Linux swap partition is not limited to overflow space. It can support your PC in other ways.


A swap partition can also help move some items from your storage to your hard drive to leave more space for more important items in memory. This means that items that are rarely touched are moved to the swap partition.

The threshold for what is considered "rare" depends on the "swappiness" (yes, that is the term actually used) that is configurable. A higher swappiness means that data is more likely to be moved to the swap partition. Less swap means that data is less likely to move to the swap partition.


A swap partition is used as the target for the contents of your memory when you instruct your system to wake up. This means that hibernation under Linux is not possible without a swap partition.

Still, it has become rare for users to use the hibernation feature, so it may not matter to you.

Do you need a swap partition?

Create a swap partition in Ubuntu Linux

Does this mean that a swap partition is required? Not at all! A Linux system can function properly without a swap partition. We have already discussed the benefits of a swap partition. Why don't you want to have one?

If swap partitions don't help

Swap partitions have their drawbacks. They take up space on your hard disk, the size of which is not dynamically changed when not in use. Heavy replacement can also increase the wear on your main drive. In some cases, swap partitions do not even improve performance. Here's an example where a swap partition can actually be worse than one.

Suppose you installed Linux on an old netbook with only 2 GB RAM and a 5400 rpm hard drive. With just 2GB of memory, you can imagine that filling up with a few open browser tabs will pretty quickly. With the swap partition, you can keep them all open when memory overflows

How much RAM do you really need?
How much computer memory do you need? Here you can find out how to check the installed RAM and how much RAM your computer needs.
Continue reading


However, a bottleneck occurs due to the hard drive's speed of 5400 rpm. Since the hard drive is so slow and the system constantly wants to access the swap partition, the netbook becomes extremely sluggish. The machine is slow enough to become unusable unless you close everything to free up space.

The set swapiness does not guarantee that everything in the swap partition will be moved back as soon as space is available in RAM. Instead, a lot can remain in the swap partition, causing the netbook to remain sluggish. So you have to restart your computer to start from a clean slate. This takes a while because the system has to remove everything from the swap partition before shutting down.

What happens if you don't have an exchange?

If you want to do without a swap partition, you know the risks. If your computer needs more RAM than is available, the interface may crash. You must forcibly shut down your computer and lose all the data that you have been working on.

In such cases, you may want a swap partition, even if it was used only once. It depends on whether you run out of space frequently. Would you notice if you had 4 GB less space available because you spent that amount on the exchange?

Linux swap recommendations

Here are some recommendations on when you want to have a swap partition and how big it should be.

  • If you want Put your computer to sleep, then you should have a swap partition. The size of this partition should match the size of your installed memory, plus an additional 10-25% to leave room for items that have already been moved to the swap partition.
  • I just want one small performance boost (and you have at least one 7200 rpm hard drive)? You can then add a swap partition if necessary. The size can be any size, but I wouldn't make it bigger than you if you created a swap partition to wake it up.
  • If you Use heavy applications occasionally If you need additional memory, a swap partition can be reassured. In this case, your swap partition does not have to be as big as your RAM.
  • If you have a 5400 RPM hard drive, then You may not want to create a swap partition simply because the bottleneck can make your computer worse. However, if you absolutely want an exchange, you can still create a partition with the same size guidelines described above. Just make sure you change the swappiness value to a much lower value.

Change swappiness

Ubuntu Linux Swappiness file

As with many aspects of the Linux desktop, the exchange of your computer is saved in a text file. You can find this file by navigating / proc / sys / vm.

When you open the file, a single number is displayed, indicating your current swappiness. You can edit this file with any text editor of your choice, provided you have root privileges.

To do this with the standard GNOME text editor in Ubuntu and Fedora, you can try the following:

sudo gedit / proc / sys / vm / swappiness

There is also a command line option that works regardless of which text editor you have installed. Just enter:

sudo sysctl vm.swappiness = 20

You can enter any number between 0 and 100. The value indicates when Linux should actively move processes from memory to the swap partition. For example, a value of 20 indicates that processes will be postponed when memory usage reaches 80%. The default swappiness value in Ubuntu of 60 indicates that processes are postponed when memory usage reaches 40%.

You can check whether the change was successful by opening this text file again. Not surprisingly, the terminal offers a faster way to check your swappiness. Just enter this command:

cat / proc / sys / vm / swappiness

Does your PC feel faster?

Swap partitions can significantly improve the performance of your system – sometimes for good and sometimes for bad. Now that you know what the swap partition is for, hopefully you will be better equipped to make the right decision for your situation.

Before repartitioning your drive, you should be aware that memory management involves more than the amount of RAM and the size of your Linux swap partition. Take a moment to learn how Linux manages RAM

Does Linux Eat Your RAM? How to manage your memory
Why does Linux suddenly run slowly? How to check RAM usage and speed up work on your Linux PC or laptop again.
Continue reading


Leave a Reply

Your email address will not be published. Required fields are marked *