find the top 10 Memory Consuming Processes
ps auxf | sort -nr -k 4 | head -10
The free utility displays the total amount of free and used physical and swap memory in the system. By default free displays information in kilobytes.
[hyperion] (~) >>> free -m
total used free shared buffers cached
Mem: 5828 1618 4210 0 188 735
-/+ buffers/cache: 694 5134
Swap: 2047 0 2047
--- - 2.4M 138K 2.2M 6%
If you want to see a total memory ( including the swap), use the -t switch.
[hyperion] (~) >>> free -t
total used free shared buffers cached
Mem: 5968728 1654740 4313988 0 192216 753280
-/+ buffers/cache: 709244 5259484
Swap: 2096440 0 2096440
Total: 8065168 1654740 6410428
Display status in real time with -s
[gitlab] (~) >>> free -s 5
total used free shared buffers cached
Mem: 1018284 937020 81264 0 9252 146436
-/+ buffers/cache: 781332 236952
Swap: 524284 0 524284
total used free shared buffers cached
Mem: 1018284 937268 81016 0 9268 146424
-/+ buffers/cache: 781576 236708
Swap: 524284 0 524284
total used free shared buffers cached
Mem: 1018284 937268 81016 0 9276 146424
-/+ buffers/cache: 781568 236716
Swap: 524284 0 524284
^C
Using the -l
flag you can show the low and high memory statistics
[saturn] (~) >>> free -l
total used free shared buffers cached
Mem: 1020868 939896 80972 4156 14840 559332
Low: 890348 812720 77628
High: 130520 127176 3344
-/+ buffers/cache: 365724 655144
Swap: 0 0 0
vmstat is a tool that collects and reports data about your system's memory, swap, and processor resource utilization in real time. It is very handy for finding the cuplrit behind memory issues.
[gitlab] (~) >>> vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 75284 7204 156916 0 0 82 53 52 128 0 0 99 0
`
Without any flags the command provides an average view of virtual memory and system usage since the last reboot. A more typical usage is of the command is vmstat [interval] [count]
. In the following example we will run 20 times at an interval of 2 seconds.
[gitlab] (~) >>> vmstat 2 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
2 0 0 69724 19192 138180 0 0 82 49 52 127 0 0 99 0
0 1 0 73932 17752 137484 0 0 56 20502 190 389 0 4 22 74
0 1 0 76980 16908 136968 0 0 8 10282 177 364 0 2 0 98
0 1 0 78528 6712 146056 0 0 64 10260 177 354 0 3 0 97
0 1 0 78412 6712 146076 0 0 0 0 170 342 0 1 0 99
0 1 0 71776 6668 153536 0 0 100 20520 198 405 0 3 0 97
0 1 0 71664 6676 153552 0 0 0 4244 540 1065 6 2 0 93
0 1 0 74088 6680 151692 0 0 2 16316 681 1357 1 4 0 96
0 1 0 76116 6564 149536 0 0 8 10260 177 361 0 1 0 99
0 1 0 78844 6564 147680 0 0 100 10260 177 358 0 2 0 98
You can also run vmstat in real time by using just the interval option. In this case we will tell it to poll every 10 seconds, and when we have gathered enough info you can simply ctrl+c
to interupt the process.
[gitlab] (~) >>> vmstat 10
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
4 0 0 81892 8632 146260 0 0 82 53 53 128 0 0 99 0
0 0 0 81884 8656 146260 0 0 0 13 175 356 1 0 99 0
0 0 0 81884 8664 146260 0 0 0 1 168 340 0 0 100 0
0 0 0 81884 8680 146260 0 0 0 11 174 358 0 0 99 0
0 0 0 82752 8704 146260 0 0 0 11 174 364 1 0 99 0
0 0 0 82008 8708 146260 0 0 0 1 171 343 0 0 99 0
^C
By default vmstat displays memory statistics in kilobytes, to see the output in megabytes use the -S
flag.
[saturn] (~) >>> vmstat -S m 2 10
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 0 77 14 578 0 0 2 21 43 49 78 22 0 0 0
3 0 0 99 14 579 0 0 266 0 701 63044 75 25 0 0 0
3 0 0 92 14 579 0 0 256 0 716 58780 75 25 0 0 0
3 1 0 77 14 580 0 0 520 334 778 58170 74 26 0 0 0
2 0 0 74 14 581 0 0 504 0 766 57092 87 14 0 0 0
3 0 0 106 14 572 0 0 550 0 756 65898 74 26 0 0 0
3 0 0 100 14 572 0 0 180 12 693 62802 78 23 0 0 0
2 0 0 88 14 568 0 0 2 22 652 56354 77 23 0 0 0
3 0 0 85 14 569 0 0 168 26 728 52951 81 19 0 0 0
3 0 0 107 14 569 0 0 256 0 706 64544 74 27 0 0 0
10 Examples of Linux Free Command
Help with interpreting output
24 iostat, vmstat and mpstat example
Linux performance using_vmstat