Linux Fundamentals - Analyzing swap memory

The free command is used to view how much memory (RAM) is available. The free command without any options will display the available memory in bytes.

~]# free
             total      used    free   shared  buffers  cached
Mem:      20453604  19756444   697160      16   189332  3692964
-/+ buffers/cache:  15874148  4579456
Swap:      2097148    389432  1707716

 

Typically, the -h (human readable) option is used to view the available memory as M (megabytes) and G (gigabytes). When contemplating "do I have enough memory", if you are on version 6 of Red Had, look at the "free" column and add up mem and buffers/cache. I ususally do not include swap in this calculation, since software may not perform as well on swap memory.

~]# free -h
             total      used    free   shared  buffers  cached
Mem:           19G       19G    510M      16K     185M    3.6G
-/+ buffers/cache:       15G    4.3G
Swap:         2.0G      380M    1.6G

 

When contemplating "do I have enough memory", if you are on version 7 of Red Had, look at "available".

~]# free -h
             total      used    free   shared  buff/cache  available
Mem:           19G       19G    510M      16K        3.6G       8.0G
Swap:         2.0G      380M    1.6G

 

The following command can be used to display the top 10 processes using swap memory.

~]$ for file in /proc/*/status ; do egrep 'VmSwap|Name' $file | sed ':label; N; $! b label; s|\n| |g' | awk '{print $4 " " $5 " " $2}'; done | sort --numeric --reverse | head
296272 kB wdavdaemon
101292 kB wdavdaemon
82872 kB httpd
81860 kB httpd
81720 kB httpd
70932 kB wdavdaemon
64560 kB httpd
47700 kB httpd
46916 kB httpd
46160 kB httpd

 

Notice in the above example that numerous HTTPD processes are using swap. The following command can be used to display the amount of swap being used by the HTTPD processes.

~]$ for file in $( ls /proc/*/status ); do egrep '^(VmSwap|Name|Pid)' $file | sed ':label; N; $! b label; s|\n| |g' | awk '{print $6 " " $7 " " $2 " (PID " $4 ")"}'; done | sort --numeric --reverse | grep httpd
83968 kB httpd (PID 32287)
83080 kB httpd (PID 31545)
82476 kB httpd (PID 31621)
65488 kB httpd (PID 36144)
51836 kB httpd (PID 30379)
50920 kB httpd (PID 33691)
50460 kB httpd (PID 31813)
44676 kB httpd (PID 35054)
41372 kB httpd (PID 33760)
39396 kB httpd (PID 36338)
36280 kB httpd (PID 33107)

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 8516e in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |