How to monitor swap space usage in Linux

To monitor swap space usage in Linux

In this article we will explain how to monitor swap space usage in Linux. Swap space holds the virtual memory of the system, which is located on the hard drive of the system.

When the physical memory(RAM) available is fully utilized then the dedicated memory called Swap space from the hard drive is allocated to run the applications of the system.

In Linux machine Swap space can be a dedicated Swap partition, which is created during the installation of the Operating System. The Swap partition size allocation is depends on the available RAM memory size.

Eg: For 2GB RAM memory 4GB of Swap partition is recommended.

To check swap space by following Commands

1. Use Swapon command to monitor swap space status

To view summary of swap space usage " --summary" or " &ndash s" option is used to view summary of swap space usage, both the options performs the same process.

[root@linuxhelp~]# swapon &ndash summary

Output:

2. Using /proc/swaps command to monitor swap space status

Proc is referred to as process information pseudo file system

[root@linuxhelp~]# cat /proc/swaps

Output:

3. Using ‘ free’ Command to monitor swap space status

Using -h option in free command is used to display the amount of free and used system memory.

[root@linuxhelp~]# free -h

Output:

4. Using top Command to monitor swap space status

It shows the processor activity of Linux in real time.

[root@linuxhelp~]# top

Output:

5. Using atop Command to monitor swap space status

It is used to monitor reports activities of various processes and displays used and available memory space.

[root@linuxhelp~]# atop

Output:

6. Using htop Command to monitor swap space status

It is used to view the information about memory usage and the processes in interactive mode

[root@linuxhelp~]# htop

Output:

7. Using the Glances Command to monitor swap space status

Glances command displays the information about running processes like storage space, cpu load, memory usage etc.

[root@linuxhelp~]# glances

Output:

8. Using the vmstat Command to monitor swap space status

Vmstat command will displays the information about virtual memory statistics.

[root@linuxhelp~]# vmstat

Output:


so- memory swapped to disk
si - memory swapped from disk

Points to remember

Some Linux machine don’ t have htop, atop, glances and vmstat packages by default . You can install these packages by using yum install.

Example:

[root@linuxhelp~]#yum install htop
FAQ
Q
How to increase swap on linux
A
Please refer the link to increase your swap space https://www.linuxhelp.com/how-to-increase-swap-memory-in-centos-7/
Q
How to delete a swap partition in linux
A
Swap partition can be removed by simply using the following command. swapoff -a
Q
Do I really need a swap partition?
A
You will no longer require a swap partition until you are going to use the full memory of your physical RAM, if the RAM memory is almost filled it should go for swap space and take some memor
Q
How can I determine about what size should I give while creating the swap partition
A
Better try to give the Size, which double your physical RAM to get better performance
Q
For dual boot setup (Ubuntu & Centos) does I require to create 2 swap partition or one is enough?
A
There is One Swap partition is enough both linux distros, you don’t need to waste some GB for second swap partition