You can get an idea of an application’s memory use via top
:
me@somewhere:~$ top
Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.0 us, 0.0 sy, 0.0 ni, 89.7 id, 8.3 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem: 3612.672 total, 3423.664 used, 189.008 free, 151.043 buffers
MiB Swap: 127.996 total, 17.074 used, 110.922 free. 1368.039 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16538 mysql 20 0 3389.5m 1.489g 10.4m S 0.7 42.2 10:16.33 mysqld
25567 www-data 20 0 352.9m 89.7m 45.1m S 0.0 2.5 0:03.98 apache2
25282 www-data 20 0 342.0m 82.1m 48.5m S 0.0 2.3 0:11.15 apache2
...
The RES column shows how much memory (RAM) is being used by each program. VIRT shows the virtual memory used by each i.e. the amount of memory that a program thinks it’s using.
However, Linux will consume RAM to cache disk blocks - unused RAM is wasted RAM - so the sums that top
shows in its header does not show you how much memory you still have available to programs.
To determine how much free memory you have, use free -m
:
me@somewhere:~$ free -m
total used free shared buffers cached
Mem: 3612 3422 190 196 151 1368
-/+ buffers/cache: 1903 1709
Swap: 127 17 110
Again, the ‘used’ column shows how much Linux is using, but not how much you have to play with.
The -/+ buffers/cache’ used shows how much memory is used by your programs. In this case we have 1903 megabytes used, with 1709 megabytes free i.e. available.
Some versions of free
will show this info differently e.g:
me@elsewhere ~ $ free -m
total used free shared buff/cache available
Mem: 3952 2529 142 151 1281 1184
Swap: 16383 4 16379
This shows that I have 1184 megabytes available (on a different computer).