• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Howto

5 ways to check swap on Linux

Published: June 8, 2017 | Modified: June 24, 2020



Learn 5 different ways to check swap space utilization on Linux server using free, swapon, /proc/swaps, top and vmstat/sar commands.

Check swap on linux

This is a short, handy post explaining how to check swap space on the Linux server with different commands. We already discussed about swap in few of old posts listed below :

  • Difference between tmpfs and swap
  • How to add or extend swap in Linux

In this post we will be seeing 5 ways to check swap space and utilization in the Linux server.

Using free command

Most of the users know this command. Using free you can check memory and swap utilization on the server in a few lines. By default, without any switch it shows numbers in kilobytes.

# free
             total       used       free     shared    buffers     cached
Mem:       1018308     191664     826644        144      13832      72652
-/+ buffers/cache:     105180     913128
Swap:         8188          0       8188

Using -h (human-readable) switch shows output values in the nearest possible (three-digit) representation.

# free -h
             total       used       free     shared    buffers     cached
Mem:          994M       191M       802M       144K        13M        74M
-/+ buffers/cache:       103M       890M
Swap:         8.0M         0B       8.0M

In the above output you can see the last row shows swap values, total, used, and free! Here swap value you see is a total of all swap devices on the system. You cant get device wise separated swap summery with this command. To view device wise summery you can use the next commands.

Using swapon command

Generally, swapon command is used to turn on swap on partition, logical volume or file. But using -s switch (summery) you can get current swap information.

# swapon -s
Filename                                Type            Size    Used    Priority
/myswapfile                             file            8188    0       -1

This command provides you output size in kilobytes. It also shows you device wise swap so that you can see device name (partition, logical volume or file), its type and how much swap it contributing to the system.

Using /proc/swaps file

Another way is to view the content of the process file /proc/swaps for the current swap config. This outputs the same content as we saw in previous command swapon -s. In fact swapon reads this file to print a summary.

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/myswapfile                             file            8188    0       -1

Output explanation is already covered above in swapon -s.

Using top command

Another popular well-known monitoring tool top can be used to view swap information. In the top output you can see the header section includes swap details.

# top
top - 02:41:33 up 13 min,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  88 total,   1 running,  87 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.6%us,  0.9%sy,  0.0%ni, 97.8%id,  0.2%wa,  0.0%hi,  0.0%si,  0.5%st
Mem:   1018308k total,   197260k used,   821048k free,    14548k buffers
Swap:     8188k total,        0k used,     8188k free,    76504k cached

Values in a row for the swap are in kilobytes. This information is also available in other advanced iterations or top alike tools like atop, htop or glance.

Using vmstat or sar command

In vmstat you can see the utilization of swap like swap in and swap out but not the devices or total values of swap like we saw in previous commands.

# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 821064  14564  76500    0    0    91    17   25   31  0  1 98  0  0

It’s more of swap monitoring. You can generate reports for certain iteration with particular time intervals like sar reporting.

# sar -S 2 3
Linux 2.6.39-200.24.1.el6uek.x86_64 (testsrv2)         12/21/2016      _x86_64_        (4 CPU)

01:01:45 AM kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
01:01:47 AM   8388604         0      0.00         0      0.00
01:01:49 AM   8388604         0      0.00         0      0.00
01:01:51 AM   8388604         0      0.00         0      0.00
Average:      8388604         0      0.00         0      0.00

These are 5 ways to get swap information out of your system. If you know any other methods do let us know in comments!

⇠ Previous article
Ultimate guide: swap addition in Linux (LVM, parted)
Next article ⇢
Basics of iptables – Linux firewall

Related stuff:

  • How to disable direct root login on Linux & HPUX
  • How to find the process using high memory in Linux
  • How to setup domain name in Linux server
  • Howto get Disk serial number in HPUX
  • How to run your script with system boot in HPUX
  • How to boot SPYRUS WorkSafe Pro Linux2Go drive
  • How to move /tmp on a separate disk as a separate mount point
  • How to remount filesystem in the read-write mode under Linux
  • How to save top command output in file
  • How to install sar in SUSE Linux
  • How to remove product channels in Suse Manager
  • How to install EC2 Linux server in AWS with screenshots

Filed Under: Howto Tagged With: check swap utilization, how to check swap, how to check total size of swap, how to view swap in linux, swap monitoring in linux, used swap in linux

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.