Check swap space in Linux

When the physical memory or RAM on our system is full, we end to make use of the swap space on our systems. In this process, the inactive pages of our memory are moved to the swap space, creating more memory resources. This space is especially useful when a system is down on RAM; however, swap space is located on the hard drive and hence slower to access. Therefore, it should not be considered an appropriate alternative to RAM.

In this article, we will describe a few ways to check for available swap space on your Ubuntu system. The commands and procedures described in this article have been run on an Ubuntu 18.04 LTS system.

We are making use of the Ubuntu command line, the Terminal, in order to check swap space on our system. In order to open the Terminal, you can either use the Dash or the Ctrl+alt+T shortcut. Then you can choose the following ways to get swap space information:

The Linux free command


$ free

This command is used to check memory and swap utilization on your system in a few lines. Without the use of any switch, the displayed output is printed in kilobytes.

Check swap space with free command


$ free -h

With the -h switch, the free command displays the memory and swap utilization in nearest possible, 3 digit format.

free -h command

The swapon command


$ swapon -s

You can use the swapon command to check swap on a particular partition, logical volume or a file. Here, we will use it with the -s (summary) switch in order to get swap details (in kilobytes).

The swapon command

The top command


$ top

The header section of the top command output shows the swap space information, in kilobytes. Other commands that give this information include htop, glances, and itop, etc.

Check swap usage with top command

The vmstat command


$ vmstat

Through the vmstat command, you can view the swap in and swap out information. However, you can not see the total values of the swap as seen is the previously mentioned commands.

Use vmstat command to check swap space

The /proc/swaps file


$ cat /proc/swaps

You can also view the swap size information throough he swap configuration file /proc/swaps. It also displays device-wise swap information so that you can see device name (partition, logical volume or file), its type and how much swap it contributing to the system.

Check content of /proc/swaps

Though the very simple commands described in this article, you can view the swap space on your Ubuntu system and utilize it when your system is running low on RAM resources.

5 Commands to Check Swap space in Linux