198

How can I check if swap is active, and which swap devices are set up, on the command line?

4 Answers 4

272

in linux, you can use

  • cat /proc/meminfo to see total swap, and free swap (all linux)
  • cat /proc/swaps to see which swap devices are being used (all linux)
  • swapon -s to see swap devices and sizes (where swapon is installed)
  • vmstat for current virtual memory statistics

in Mac OS X, you can use

  • vm_stat to see information about virtual memory (swap)
  • ls -lh /private/var/vm/swapfile* to see how many swap files are being used.

in Solaris, you can use

  • swap -l to see swap devices/files, and their sizes
  • swap -s to see total swap size, used & free
  • vmstat to see virtual memory statistics

On some systems, "virtual memory" refers only to disk-backed memory devices, and on other systems, like Solaris, Virtual Memory can refer to any user process address space, including tmpfs filesystems (like /tmp) and shared memory space.

4
  • 22
    Also, free should tell you how much swap is available to your system.
    – user26112
    Commented May 28, 2013 at 10:31
  • 2
    cat /proc/meminfo should be cat /proc/meminfo | grep Swap
    – Binar Web
    Commented Jun 11, 2019 at 4:09
  • use free -h for human readable sizes.
    – red-o-alf
    Commented Apr 23, 2023 at 17:56
  • 1
    The swapon -s (--summary) seems to be deprecated at least in util-linux 2.37.2. The swapon --show shows similar information.
    – Niko Fohr
    Commented Nov 29, 2023 at 20:55
40

swapon --show

This is a bit better than swapon -s as it provides human friendly size units. E.g. if swap is active you could see:

NAME      TYPE      SIZE   USED PRIO
/dev/dm-1 partition 7.5G 563.8M   -2

If swap is not active, it doesn't show anything.

man swap says:

-s, --summary

Display swap usage summary by device. Equivalent to "cat /proc/swaps". This output format is DEPRECATED in favour of --show that provides better control on output data.

--show[=column...]

Display a definable table of swap areas. See the --help > output for a list of available columns.

Tested in Ubuntu 18.04, util-linux 2.31.1.

34

Try swapon -s for a list of current swap devices and other relevant information.

3

With Linux you can use the top command to see if the swap is active or not, in which you can see something like kswapd0. The top command provides a dynamic real-time view of a running system, thus you should see the swap there.

If you don't see it there, it's more then likely it isn't working. to restart it or enable it, you can use this command: sudo swapon --all --verbose (source)

Then by running the topcommand again you should see it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .