Software & AppsOperating SystemLinux

How To Empty Swap and Revert to Using RAM in Ubuntu

Ubuntu 6

In this article, we will guide you through the process of emptying swap and reverting to using RAM in Ubuntu. This can be a useful process when you want to optimize your system’s performance. However, it’s important to proceed with caution because mismanagement of swap and RAM can lead to system instability.

Quick Answer

To empty swap and revert to using RAM in Ubuntu, you can reduce the swappiness value to make the kernel less likely to use swap space. Additionally, you can temporarily empty the swap by disabling and then re-enabling it. However, it’s important to proceed with caution and ensure you have enough free RAM available before disabling the swap.

Understanding Swap and RAM

Before we dive into the process, it’s crucial to understand what swap and RAM are. RAM (Random Access Memory) is a type of computer memory that can be read and changed in any order, often used to store working data and machine code.

Swap space, on the other hand, is a portion of a hard disk drive (HDD) that is used for virtual memory. Swap space temporarily holds memory pages that are inactive. Swap space is used when your system decides that it needs physical memory for active processes and there is insufficient unused physical memory available.

Checking the Current Swappiness Value

The first step in this process is to check the current swappiness value. The swappiness value represents how aggressively the kernel moves processes out of physical memory and onto the swap disk. You can check this value by running the command:

cat /proc/sys/vm/swappiness

This command reads the value of the file /proc/sys/vm/swappiness, which represents the current swappiness value.

Reducing the Swappiness Value

If you want to reduce the swappiness value, you can use the sysctl command. For example, to set the swappiness value to 10, you can run:

sudo sysctl vm.swappiness=10

In this command, sudo runs the following command with root privileges, sysctl is a utility that allows you to read and modify kernel parameters at runtime, vm.swappiness=10 sets the swappiness value to 10. A lower value will make the kernel less likely to use swap space.

Temporarily Emptying the Swap

To temporarily empty the swap, you can disable and then re-enable it. This can be done with the following commands:

sudo swapoff -a
sudo swapon -a

The swapoff command disables the swap, and the swapon command enables it. The -a option specifies that the command should be applied to all swap spaces.

Permanently Setting the Swappiness Value

If you want to permanently set the swappiness value to a lower value, you can edit the /etc/sysctl.conf file. This can be done with a text editor like nano or vi. For example, you can run:

sudo nano /etc/sysctl.conf

Then, add the following line to the file:

vm.swappiness = 10

After adding this line, save the file and exit the text editor. The changes will take effect after you reboot your system.


Reducing the swappiness value or emptying the swap should be done with caution. Make sure you have enough free RAM available before disabling the swap, as it may cause instability if the system is already low on memory. Additionally, remember that the kernel is optimized to manage swap space efficiently, so it’s generally recommended to let it handle the swapping process automatically.

For more information about swap and RAM, you can refer to the Ubuntu documentation.

What is the recommended swappiness value in Ubuntu?

The recommended swappiness value in Ubuntu is typically set to 60. However, it can be adjusted based on your specific needs and system configuration.

How can I check the current swappiness value in Ubuntu?

You can check the current swappiness value in Ubuntu by running the command cat /proc/sys/vm/swappiness in the terminal.

Can I completely disable swap in Ubuntu?

Yes, you can disable swap in Ubuntu by either setting the swappiness value to 0 or by turning off swap using the swapoff command. However, it is generally recommended to have some amount of swap space for system stability.

How can I permanently set the swappiness value in Ubuntu?

To permanently set the swappiness value in Ubuntu, you can edit the /etc/sysctl.conf file and add the line vm.swappiness = [value], where [value] is the desired swappiness value. Save the file and reboot your system for the changes to take effect.

Will emptying the swap improve my system’s performance?

Emptying the swap may improve your system’s performance if you have sufficient free RAM available. However, if your system is already low on memory, disabling swap can lead to instability. It is generally recommended to let the kernel manage swap space efficiently.

Leave a Comment

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