One of the critical components is the system is its memory (RAM). When server memory is fully utilized, it can slow down the server performance. To monitor memory utilization, Linux has another command called 'free'.
Free command is used in Linux to check the amount of free RAM memory in the system. The free command also shows swap space, buffer and cache space.
Most Linux distributions by default have free command inbuilt so no need to install any package.
Check memory usage using free command
To run free command just type free
on your terminal. Running it without an option will show you a default view with kilobyte units.
$ free
Command will shows below memory information.
Memory (in kilobytes units)
- Total : 1026740
- Used : 843396
- Free : 183344
- Shared : 0
- Buffers : 52704
- Cached : 376384
Swap (in kilobytes units)
- Total : 1045500
- Used : 3376
- Free : 1042124
Please note that the shared memory column should be ignored because it is obsolete.
Display memory information in unit
By default free
will show information in kilobytes unit. To check memory usage in other units use -b
(bytes), -k
(kilobytes), -m
(megabytes), -g
(gigabytes) and --tera
(terabytes).
The following example output is megabytes unit.
$ free -m
Some Linux distro support following free options as well -b
, -k
, -g
and --tera
.
Display memory in human readable
Free command also provide us with -h
option which means human readable. So what is the difference with previous option, such as -m (megabytes) option? The most visible difference is that -h
option will add human readable unit after the numbers.
Let’s take a look a example of it.
$ free -h
As we can see together, there is G
(gigabyte) letter behind 1,0 number. When the number is not reached gigabtye, free is smart enough to know it and put the appropriate unit behind each numbers. M
letter behind - let say - 929 number tell us its 969 Megabytes.
Display free with delay
As one of the statistic tool, the best way to capture memory utilization is using a delay. To do this, we can use -s
option followed by N
seconds that we want. We can always combine more than 1 options to make the output is fit with our needs.
Let say we want to capture memory utilization every 3 seconds and human readable.
$ free -hs 3
Display low and high memory utilization
If we want to show low and high memory statistics, we can use -l
option.
Sample output
$ free -l
Display Linux total memory
When we need the information of total for every column, we can add -t
option behind free command. This will add 1 more row at the bottom which display it.
$ free -t
Conclusion
Besides vmstat, free command is another simple statistic tool for capturing memory utilization. With this, you can grab quick information about what happened in your Linux memory.
Free is using '/proc/meminfo' as a base for showing memory utilization information. As usual, you can always type man free on your console to explore more detail about free.