
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 buff/cache available
Mem: 10054428 5930312 297116 217544 3827000 3592572
Swap: 8388604 45056 8343548
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 --human
total used free shared buff/cache available
Mem: 9.6G 5.7G 289M 212M 3.7G 3.4G
Swap: 8.0G 44M 8.0G
When contemplating "do I have enough memory", if you are on version 7 of Red Had, look at "available".
~]# free --human
total used free shared buff/cache available
Mem: 9.6G 5.7G 289M 212M 3.7G 3.4G
Swap: 8.0G 44M 8.0G
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
Likewise, you can replace VmSwap with VmData in the prior command to get "normal" memory, not the swap memory.
for file in /proc/*/status ; do egrep 'VmData|Name' $file | sed ':label; N; $! b label; s|\n| |g' | awk '{print $4 " " $5 " " $2}'; done | sort --numeric --reverse | head
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