Methods to Check Swap Space in Linux

1. Using swapon Command

The swapon command is used to turn on and use an area of your hard drive as extra memory. This extra memory area is called swap space. It helps your computer keep running smoothly when the main memory (RAM) is full. To use swap space run the below command. This command tells your computer to treat the area /dev/sda2 on your hard drive as extra memory (swap space).

Command :

swapon /dev/sda2

After running swapon, you can check which swap space areas are being used by running the below command.

Command :

swapon -summary

Output :

2. Using /proc/swaps Command

The /proc/swaps file shows information about the swap spaces your computer is currently using as extra memory. It lists details like the name, type, size, and how much of each swap space is being used. To view the contents of the /proc/swaps file, you can use cat command.

Command :

cat /proc/swaps

Output :

3. Using free command

The free command shows how much memory (RAM) and swap space your computer is using. When you run free, it displays the total, used, and free amounts for both RAM and swap space use the below command to do that.

Command :

free

Output :

4. Using vmstat Command

The vmstat command shows information about your computer’s memory, CPU, and disk activity. It helps you understand how your system’s resources are being used.

Command :

vmstat

Output :

  1. options: Different options to customize vmstat output
  2. delay: How often (in seconds) to update the information
  3. count: How many updates to show before stopping

Example Command :

vmstat 2 5

This shows memory, CPU, and disk usage, updating every 2 seconds for 5 times.

5. Using top/atop/htop/glances Command

The commands top, atop, htop, and glances are system monitoring tools used in Linux. They show real-time information about how your computer’s resources like CPU, memory, and disk are being used.

Command :

top

Output :

atop command provides a comprehensive view of system activity over time, allowing you to analyze historical data. Navigate through different screens using arrow keys. Press ‘q’ to exit.

Command :

atop

Output :

htop command is similar to top but with a user-friendly interface and additional features. It displays a color-coded overview of processes, CPU, and memory usage.

Command :

htop

Output :

glances command presents a simplified overview of system resources like CPU, memory, network, and disk I/O on a single screen.

Command :

glances

Output :

6. Using Linux GUI Tool

The GNOME System Monitor is a graphical application that allows you to monitor various system resources in a user-friendly interface. It displays information about CPU usage, memory usage, swap space usage, disk activity, and network activity.

How to Check Swap Space in Linux

Swap space is like an extra space in your computer’s memory. When your computer’s main memory (RAM) gets full it uses this extra room (swap space) to store things that aren’t being used right now. This extra room is located on your computer’s hard drive. Keeping an eye on how much of this extra room is being used is important for your computer to work well. If too much of the extra room is being used, your computer might slow down.

How to Check Swap Space in Linux

  • What is Swap Space?
  • Methods to Check Swap Space in Linux
    • 1. Using swapon Command
    • 2. Using /proc/swaps Command
    • 3. Using free command
    • 4. Using vmstat Command
    • 5. Using top/atop/htop/glances Command
    • 6. Using Linux GUI Tool

Similar Reads

What is Swap Space?

Swap space is a separate memory on your computer’s hard drive. It acts like extra memory when your computer’s main memory (RAM) gets full. When you have too many programs or files open and your RAM is all used up, your computer moves some of the things it’s not using right now to the swap space on the hard drive. This frees up space in the RAM for the programs and files you’re actively using....

Methods to Check Swap Space in Linux

1. Using swapon Command...

Conclusion

Monitoring swap space usage is important to ensure your Linux system runs smoothly. Swap space acts as extra memory when your computer’s RAM gets full. Several command-line tools like swapon, free, vmstat, and GUI tools like GNOME System Monitor allow you to easily check how much swap space is being used....

How to Check Swap Space in Linux – FAQs

What is swap space and why is it important?...

Contact Us