How can I check if swap is active, and which swap devices are set up, on the command line?
4 Answers
in linux, you can use
cat /proc/meminfoto see total swap, and free swap (all linux)cat /proc/swapsto see which swap devices are being used (all linux)swapon --showto display a definable table of swap areas (swapon -sis deprecated)vmstatfor current virtual memory statistics
in Mac OS X, you can use
vm_statto 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 -lto see swap devices/files, and their sizesswap -sto see total swap size, used & freevmstatto 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.
- 25Also,
freeshould tell you how much swap is available to your system.user26112– user261122013-05-28 10:31:24 +00:00Commented May 28, 2013 at 10:31 - 3
cat /proc/meminfoshould becat /proc/meminfo | grep SwapBinar Web– Binar Web2019-06-11 04:09:46 +00:00Commented Jun 11, 2019 at 4:09 - 1use
free -hfor human readable sizes.red-o-alf– red-o-alf2023-04-23 17:56:54 +00:00Commented Apr 23, 2023 at 17:56 - 1The swapon -s (--summary) seems to be deprecated at least in util-linux 2.37.2. The swapon --show shows similar information.Niko Fohr– Niko Fohr2023-11-29 20:55:58 +00:00Commented Nov 29, 2023 at 20:55
- 2In order to save a few keystrokes,
cat /proc/meminfo | grep Swapcan be abbreviated withgrep Swap /proc/meminfo.René Nyffenegger– René Nyffenegger2025-01-03 14:12:35 +00:00Commented Jan 3 at 14:12
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.
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 top command again you should see it.
- On a kernel 6.8 LiveCD (even though swap isn't enabled),
kswapd0still appears when filtering or scrolling down intopDaniel T– Daniel T2024-11-15 20:03:04 +00:00Commented Nov 15, 2024 at 20:03