How to review Swap space usage on a Linux server

Still need help?

The Atlassian Community is here for you.

Ask the community

Linux system administration is outside the scope of Atlassian support. This page is provided for your information only.

 

Purpose

As a system administrator, you may see the swap space fill up on the Bamboo server. The following will show some options for determining how much of the swap space each application is using.

Solution

TOP

Unix operating systems have the top command which will show memory usage. This is useful as a general overview, but SWAP is approximated as Virtual memory - Resident (physical) memory, so it less accurate than the other tools on this page.

However, once top is opened, you can sort by SWAP usage as follows:

  1. Type f to open the "Add column" menu
  2. Use the up/down arrow keys to navigate to SWAP
  3. Type d or <Space> to select SWAP for display
  4. Tap the right arrow to select the SWAP column to reorder
  5. Type s to select SWAP as your sort column
  6. Type q to return to the main screen

You can save the current top configuration by typing Shift + W.

Example output:

 

  PID USER      PR  NI    VIRT    RES   SWAP    SHR S %CPU %MEM     TIME+ COMMAND  
    1 root      20   0   33492   1628   1224   1476 S  0.0  0.1   0:00.75 init
  316 root      20   0   51508   1032    736    988 S  0.0  0.1   0:00.02 systemd-udevd                                                                                                                                                                               
  312 root      20   0   19472    468    252    468 S  0.0  0.0   0:00.06 upstart-udev-br
  493 root      20   0   23472    208    212    208 S  0.0  0.0   0:00.00 rpc.idmapd
  496 root      20   0   43444   1620    200   1460 S  0.0  0.1   0:00.00 systemd-logind
  443 message+  20   0   39212   1064    196    872 S  0.0  0.1   0:00.06 dbus-daemon
  648 root      20   0   15536    756    156    384 S  0.0  0.0   0:00.02 upstart-file-br
...

FREE

Another useful Linux command is free, which, when run with the -m flag, will return memory usage for your machine, including SWAP.

For example:

             total       used       free     shared    buffers     cached
Mem:         32109      30982       1126          0        301       2916
-/+ buffers/cache:      27764       4345
Swap:         8191       6107       2084

 

PROC STATUS

Finally, this command will list all applications with how much swap space each is using in kilobytes by looping through the status snapshots in the /proc/ directory:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

(Source)

Example:

root@bamboo:/home/vagrant# for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head
init 1008 kB
systemd-udevd 736 kB
upstart-udev-br 220 kB
dbus-daemon 192 kB
writeback 
watchdog/0 
vmstat 
VBoxService 0 kB
upstart-socket- 0 kB
upstart-file-br 0 kB



Last modified on Dec 14, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.